rassulya commited on
Commit
d9f69bd
·
1 Parent(s): 43c55fa

Add unit tests for calculator functions

Browse files
Files changed (1) hide show
  1. tests/test_calc.py +34 -0
tests/test_calc.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ import sys
3
+ import os
4
+
5
+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
6
+
7
+ from calculator import add, subtract, multiply, divide, is_even
8
+
9
+ def test_add():
10
+ assert add(2, 3) == 5
11
+ assert add(-1, 1) == 0
12
+ assert add(0, 0) == 0
13
+
14
+ def test_subtract():
15
+ assert subtract(5, 3) == 2
16
+ assert subtract(0, 5) == -5
17
+ assert subtract(-2, -3) == 1
18
+
19
+ def test_multiply():
20
+ assert multiply(3, 4) == 12
21
+ assert multiply(-2, 3) == -6
22
+ assert multiply(0, 5) == 0
23
+
24
+ def test_divide():
25
+ assert divide(10, 2) == 5
26
+ assert divide(7, 2) == 3.5
27
+
28
+ with pytest.raises(ValueError):
29
+ divide(5, 0)
30
+
31
+ def test_is_even():
32
+ assert is_even(4) == True
33
+ assert is_even(3) == False
34
+ assert is_even(0) == True