class TestCase(unittest.TestCase): def setUp(self): self.keys = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] self.t = SplayTree() for key in self.keys: self.t.insert(key) def testInsert(self): for key in self.keys: self.assertEquals(key, self.t.find(key)) def testRemove(self): for key in self.keys: self.t.remove(key) self.assertEquals(self.t.find(key), None) self.t.remove(-9999) def testLargeInserts(self): t = SplayTree() nums = 40000 gap = 307 i = gap while i != 0: t.insert(i) i = (i + gap) % nums def testIsEmpty(self): self.assertFalse(self.t.isEmpty()) t = SplayTree() self.assertTrue(t.isEmpty()) def testMinMax(self): self.assertEquals(self.t.findMin(), 0) self.assertEquals(self.t.findMax(), 9)
def test0(): s = SplayTree() s.insert(3) s.insert(2) s.insert(1) s.find(3) s.find(2) s.find(1)
def test(): n1 = Node(1) n2 = Node(2) assert not n1.equals(n2) s = SplayTree() assert s.findMin() == None assert s.findMax() == None assert s.find(1) == None assert s.isEmpty() s.insert(80) s.insert(81) s.insert(82) s.insert(1) s.find(-999) s.insert(1) s.insert(3) s.insert(2) for i in range(20): s.insert(i) for i in range(40, 20, -1): s.insert(i) assert s.findMin() != None assert s.findMax() != None assert s.find(1) != None assert not s.isEmpty() s.insert(80) s.insert(81) s.insert(82) s.insert(82) s.remove(1) s.remove(2) s.remove(3) for i in range(20): s.remove(i)
class TestCase(unittest.TestCase): def setUp(self): self.keys = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] self.t = SplayTree() for key in self.keys: self.t.insert(key) def testInsert(self): for key in self.keys: self.assertEquals(key, self.t.find(key)) # Forgot in first phase, insert an elem in tree already there self.t.insert(self.keys[0]) def testRemove(self): for key in self.keys: self.t.remove(key) self.assertEquals(self.t.find(key), None) # Forgot to remove elem not in tree self.t.remove(-13) def testLargeInserts(self): t = SplayTree() nums = 40000 gap = 307 i = gap while i != 0: t.insert(i) i = (i + gap) % nums def testIsEmpty(self): self.assertFalse(self.t.isEmpty()) t = SplayTree() self.assertTrue(t.isEmpty()) def testMinMax(self): self.assertEquals(self.t.findMin(), 0) self.assertEquals(self.t.findMax(), 9) # Forgot in first phase, check when there no element in tree t = SplayTree() self.assertEquals(t.findMin(), None) self.assertEquals(t.findMax(), None) def TearDown(self): del self.t