-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyTest.py
More file actions
75 lines (66 loc) · 1.85 KB
/
Copy pathPyTest.py
File metadata and controls
75 lines (66 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
import pytest
class TestFloatClass:
# Is integer (parametrized)
@pytest.mark.parametrize("num", [-76.0, -54.32, -1, -0.5, 0, 0.5, 1, 23.45, 67.0])
def test_flt_one(self, num):
try:
assert num.is_integer()
except AttributeError:
pass
except AssertionError:
pass
# Is almost equal (positive)
def test_flt_two(self):
num1 = 123.45678
num2 = 123.45679
delta = 0.0001
try:
assert abs(num1 - num2) < delta
except AssertionError:
pass
# Are integer and fractional parts equal (negative)
def test_flt_three(self):
num = 123.456
integ, fract = str(num).split(".")
integ, fract = int(integ), int(fract)
delta = 0.0001
try:
assert abs(integ - fract) < delta
except AssertionError:
pass
class TestDictClass:
# Has all numeric values
@pytest.mark.parametrize(
"dic",
[
{"a": 12, "b": 45},
{"a": 12, "b": "12"},
{"a": "12", "b": "ab"},
],
)
def test_dic_one(self, dic):
result = True
for val in dic.values():
if type(val) is not int:
result = False
break
try:
assert result
except AssertionError:
pass
# Has more than 2 keys (positive)
def test_dic_two(self):
dic = {"a": 123, "b": "123", "c": "abc"}
try:
assert len(dic.keys()) > 2
except AssertionError:
pass
# Has equal values (negative)
def test_dic_three(self):
dic = {"a": 123, "b": "123", "c": "abc"}
val_set = set(dic.values())
try:
assert len(val_set) < len(dic.values())
except AssertionError:
pass