-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_practice.py
More file actions
67 lines (57 loc) · 1.96 KB
/
test_practice.py
File metadata and controls
67 lines (57 loc) · 1.96 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
import pytest
import random
from practice import *
def test_is_multiple():
assert is_multiple(20,10) == True
assert is_multiple(20.5, 10.5) == False
assert is_multiple(200, 0) == "error caught"
def test_is_even():
assert is_even(100) == True
assert is_even(15) == False
assert is_even(99.9) == "error caught"
def test_minmax():
list_with_floats = [1,5,6.5,-2]
assert minmax(list_with_floats) == (-2, 6.5)
list_with_None = [1,None,6]
assert minmax(list_with_None) == (1, 6)
list_with_String = [-22,"jeff",None,-22]
assert minmax(list_with_String) == (-22, -22)
with pytest.raises(TypeError):
minmax(False)
def test_sqr_sum():
assert sqr_sum(4) == 14
assert sqr_sum_oneline(4) == 14
assert sqr_sum(-1) == 0
assert sqr_sum(4.0) == 0
assert sqr_sum("hi") == 0
assert sqr_sum(None) == 0
def test_sqr_odd_sum():
assert sqr_odd_sum(6) == 35
assert sqr_odd_sum(-1) == 0
assert sqr_odd_sum("hello") == 0
assert sqr_odd_sum(None) == 0
def test_ran_choice():
int_list = [k for k in range(1,6)]
func_res = ran_choice(int_list)
random.seed(103)
test_res = int_list[random.randrange(0,5)]
assert func_res == test_res
def test_distince_pair_odd_product():
assert distinc_pair_odd_product([1,3,4]) == True
assert distinc_pair_odd_product([1,2,4]) == False
assert distinc_pair_odd_product([3,3,4]) == False
assert distinc_pair_odd_product([3,3,5]) == True
def test_all_distinct():
assert all_distinct([1,3,5,6,7]) == True
assert all_distinct([1,1,2]) == False
assert all_distinct([1]) == True
assert all_distinct([]) == True
assert all_distinct([1,None,3]) == "error caught"
with pytest.raises(TypeError):
all_distinct(1)
def test_dot_product():
assert dot_product([1,2,3],[3,2,1]) == [3,4,3]
assert dot_product([1,2,3], [1]) == 0
def test_count_vowel():
assert count_vowels('a5.3long\\n') == 2
assert count_vowels('h I _\t') == 1