-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathtest_structures.py
More file actions
137 lines (109 loc) · 3.27 KB
/
test_structures.py
File metadata and controls
137 lines (109 loc) · 3.27 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'''
test_toys.py
Unit tests for structures functions.
'''
import unittest
import unittest.mock
import io
import structures as st
class TestSum(unittest.TestCase):
def set_up(self):
pass
def test_first_and_last(self):
'''
Test first_and_last function
'''
result = st.first_and_last([0,1,2,3])
self.assertEqual(result, [0,3])
def test_part_reverse(self):
'''
Test
'''
result = st.part_reverse([0,1,2,3,4,5], 1, 4)
self.assertEqual(result, [3,2,1])
def test_repeat_at_index(self):
'''
Test
'''
result = st.repeat_at_index([0,1,2,3,4,5,6], 3)
self.assertEqual(result, [0,1,2,3,3,3,4,5,6])
def test_palindrome_word1(self):
'''
Test palindrome word
'''
result = st.palindrome_word("madam")
self.assertIs(result, True)
def test_palindrome_word2(self):
'''
Test palindrome word
'''
result = st.palindrome_word("Madam")
self.assertIs(result, True)
def test_palindrome_word3(self):
'''
Test palindrome word
'''
result = st.palindrome_word("palindrome")
self.assertIs(result, False)
def test_palindrome_sentence1(self):
'''
Test palindrome sentence
'''
result = st.palindrome_word("Was it a car or a cat I saw")
self.assertIs(result, True)
def test_palindrome_sentence2(self):
'''
Test palindrome sentence
'''
result = st.palindrome_word("Random sentence")
self.assertIs(result, False)
def test_palindrome_sentence3(self):
'''
Test palindrome sentence
'''
result = st.palindrome_word(" Do geese see God ")
self.assertIs(result, True)
def test_concatenate_sentences1(self):
'''
Test sentence concatenation
'''
result = st.concatenate_sentences("First sentence.", "Second sentence.")
self.assertEqual(result, "First sentence. Second sentence.")
#def test_concatenate_sentences2(self):
# '''
# Test sentence concatenation
# '''
# result = st.concatenate_sentences("first sentence.", "Second sentence.")
# self.assertRaises(ValueError,
def test_index_exists1(self):
'''
Test
'''
result = st.index_exists({"ind1": "val1", "ind2": "val2"} , "ind1")
self.assertIs(result, True)
def test_index_exists2(self):
'''
Test
'''
result = st.index_exists({"ind1": "val1", "ind2": "val2"} , "ind3")
self.assertIs(result, False)
def test_value_exists1(self):
'''
Test
'''
result = st.value_exists({"ind1": "val1", "ind2": "val2"} , "val1")
self.assertIs(result, True)
def test_index_exists2(self):
'''
Test
'''
result = st.value_exists({"ind1": "val1", "ind2": "val2"} , "val3")
self.assertIs(result, False)
def test_merge_dictionaries(self):
'''
Test
'''
result = st.merge_dictionaries({"a": 1, "c": 3}, {"b": 2, "d": 4})
self.assertEqual(result, {"a": 1, "c": 3, "b": 2, "d": 4})
if __name__ == '__main__':
unittest.main()