Ejemplo n.º 1
0
    def test_setItem_withEqualKeys_shouldReplaceOldValueByNewValue(self):
        bst = SplayTree()
        for i in range(1, 20):
            bst[i] = str(i)

        for i in range(1, 20):
            self.assertEqual(str(i), bst.get(i))

            bst[i] = str(i + 1)

            self.assertEqual(19, len(bst))
            self.assertIn(i, bst)
            self.assertEqual(str(i + 1), bst[i])
            self.assertEqual(str(i + 1), bst.get(i))
Ejemplo n.º 2
0
    def test_setItem_withNotEqualKeys_shouldInsertNewPairKeyValueIntoTree(
            self):
        bst = SplayTree()
        for i in range(1, 20):
            bst[i] = str(i)
            self.assertEqual(i, len(bst))

            self.assertIn(i, bst)
            self.assertEqual(str(i), bst[i])
            self.assertEqual(str(i), bst.get(i))

        for i in range(1, 20):
            self.assertIn(i, bst)
            self.assertEqual(str(i), bst[i])
            self.assertEqual(str(i), bst.get(i))
Ejemplo n.º 3
0
    def test_get_withKeyInBST_shouldReturnAssociatedValue(self):
        bst = SplayTree()
        for i in range(1, 20):
            bst.put(i, str(i))

        for i in range(1, 20):
            self.assertEqual(str(i), bst.get(i))
Ejemplo n.º 4
0
    def test_get_withKeyNotInBST_shouldReturnNone(self):
        bst = SplayTree()
        for i in range(1, 20):
            bst.put(i, str(i))

        for i in range(20, 30):
            self.assertIsNone(bst.get(i))