PageRenderTime 40ms CodeModel.GetById 30ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/examples/libtest/SetTest.py

http://pyjamas.googlecode.com/
Python | 75 lines | 56 code | 19 blank | 0 comment | 19 complexity | 83d40731f3d129cfebbc8ca0f0a61757 MD5 | raw file
 1from UnitTest import UnitTest
 2from sets import Set
 3
 4class SetTest(UnitTest):
 5	def __init__(self):
 6		UnitTest.__init__(self)
 7
 8	def getName(self):
 9		return "Set"
10
11	def testInit(self):
12		value = Set(['a', 'b', 'c'])
13		
14		self.assertTrue('b' in value)
15		self.assertTrue('d' not in value)
16
17	def testAdd(self):
18		value = Set()
19		value.add("a")
20		value.add("b")
21		value.add("a")		
22		
23		self.assertTrue('a' in value)
24		self.assertTrue('c' not in value)
25		self.assertTrue(len(value)==2)
26
27	def testRemove(self):
28		value = Set(['a', 'b', 'c'])
29		value.remove('a')
30		
31		self.assertTrue('a' not in value)
32		self.assertTrue('b' in value)
33
34	def testIter(self):
35		items = ['a', 'b', 'c']
36		value = Set(items)
37		
38		for i in value:
39			items.remove(i)			
40
41		self.assertTrue(len(items)==0)
42
43	def testAddObject(self):
44		v1 = DummyClass('a')
45		v2 = DummyClass('b')
46		v3 = DummyClass('b')
47		v4 = DummyClass('c')
48		items = [v1, v2, v3]
49
50		value = Set()
51		value.add(v1)
52		value.add(v2)
53		value.add(v1)
54		value.add(v3)
55		
56		self.assertTrue(v1 in value)
57		self.assertTrue(v2 in value)
58		self.assertTrue(v3 in value)
59		self.assertTrue(v4 not in value)
60		self.assertTrue(len(value)==3)
61		
62		i = 0
63		for v in value:
64			if v.getValue() != items[i].value:
65				self.assertTrue(False)
66			i += 1
67
68
69class DummyClass:
70	def __init__(self, value):
71		self.value = value
72	
73	def getValue(self):
74		return self.value
75