-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_L101.py
119 lines (89 loc) · 2.81 KB
/
test_L101.py
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
__author__ = 'Hernan Y.Ke'
import unittest
from collections.abc import (Container, Sized, Iterable, Sequence) #Parentheses)
from L101 import SortedSet
class TestConst(unittest.TestCase):
def test_empty(self):
s = SortedSet([])
def test_from_seq(self):
s = SortedSet([5,7])
def test_dup(self):
s = SortedSet([7,7])
def test_from_iter(self):
def gen67():
yield 6
yield 7
g =gen67()
s=sorted(g)
def test_deff(self):
s = SortedSet()
class TestContainer(unittest.TestCase):
def setUp(self):
self.s = SortedSet([4,3,5,9,7,6])
def test_posi_conta(self):
self.assertTrue(6 in self.s)
def test_neg_conta(self):
self.assertTrue(2 not in self.s)
class TestSize(unittest.TestCase):
def test_empty(self):
s=SortedSet
self.assertEqual(len(s),0)
def test_empty(self):
s=SortedSet([3,3,3])
self.assertEqual(len(s),1)
class TestIter(unittest.TestCase):
def setUp(self):
self.s=SortedSet([1,2])
def test_iter(self):
i = iter(self.s)
self.assertEqual(next(i),1)
self.assertEqual(next(i),2)
self.assertRaises(StopIteration, lambda :next(i)) #Syntax
def test_indx(self):
index = 0
expected =[1,2,5]
for item in self.s:
self.assertEqual(item,expected[index])
index+=1
class TestSeq(unittest.TestCase):
def setUp(self):
self.s=SortedSet([1,2])
def test_index(self):
self.assertEqual(self.s[0],1)
def test_arise(self):
with self.assertRaises(IndexError):
self.s[3] # Because only 2 elems exist, hence it raises error. Syntax!
def test_slice(self):
self.assertEqual(self.s[:1],SortedSet([1]))
def test_index_positive(self):
s = SortedSet([1,3,8,9])
self.assertEqual(s.index(1),0)
def test_index_positive_err(self):
s = SortedSet([1,3,8,9])
with self.assertRaises(ValueError):
s.index(2)
def test_reversed(self):
s =SortedSet([1,3])
r=reversed(s)
self.assertEqual(next(r),3)
self.assertEqual(next(r),1)
with self.assertRaises(StopIteration):
next(r)
def test_count_one(self):
s = SortedSet([1,3])
self.assertEqual(s.count(1),1)
class TestRepr(unittest.TestCase):
def test_repr_empy(self):
s = SortedSet()
self.assertEqual(repr(s),"SortedSet()")
class TestEq(unittest.TestCase):
def test_eq(self):
self.assertTrue(SortedSet([1,2])==SortedSet([1,2]))
def test_idential(self):
s=SortedSet([1,2])
self.assertTrue(s==s)
def test_not_idential(self):
s=SortedSet([1,2])
self.assertFalse(s!=s)
if __name__ == '__main__':
unittest.main()