def test_contains(self):
     s = TreeSet()
     s.add('A')
     s.add('B')
     s.add('C')
     assert s.contains('A') is True
     assert s.contains('B') is True
     assert s.contains('D') is False
     s.remove('A')
     assert s.contains('A') is False
     assert s.size == 2
示例#2
0
 def test_add_ints(self):
     """Test add method with ints"""
     tree_set = TreeSet()
     tree_set.add(5)
     assert tree_set.contains(5)
     assert tree_set.tree.root.data == 5
     tree_set.add(3)
     assert tree_set.contains(3)
     assert tree_set.tree.root.left.data == 3
     tree_set.add(7)
     assert tree_set.contains(7)
     assert tree_set.tree.root.right.data == 7
     tree_set.add(6)
     assert tree_set.contains(6)
     assert tree_set.tree.root.right.left.data == 6
     tree_set.add(1)
     assert tree_set.contains(1)
     assert tree_set.tree.root.left.left.data == 1
示例#3
0
 def test_add_strings(self):
     """Test add method with strings"""
     tree_set = TreeSet()
     tree_set.add('C')
     assert tree_set.contains('C')
     assert tree_set.tree.root.data == 'C'
     tree_set.add('B')
     assert tree_set.contains('B')
     assert tree_set.tree.root.left.data == 'B'
     tree_set.add('E')
     assert tree_set.contains('E')
     assert tree_set.tree.root.right.data == 'E'
     tree_set.add('D')
     assert tree_set.contains('D')
     assert tree_set.tree.root.right.left.data == 'D'
     tree_set.add('A')
     assert tree_set.contains('A')
     assert tree_set.tree.root.left.left.data == 'A'
示例#4
0
 def test_add_tuples(self):
     """Test add method with tuples"""
     tree_set = TreeSet()
     tree_set.add(('E', 5))
     assert tree_set.contains(('E', 5))
     assert tree_set.tree.root.data == ('E', 5)
     tree_set.add(('C', 3))
     assert tree_set.contains(('C', 3))
     assert tree_set.tree.root.left.data == ('C', 3)
     tree_set.add(('G', 7))
     assert tree_set.contains(('G', 7))
     assert tree_set.tree.root.right.data == ('G', 7)
     tree_set.add(('F', 6))
     assert tree_set.contains(('F', 6))
     assert tree_set.tree.root.right.left.data == ('F', 6)
     tree_set.add(('A', 1))
     assert tree_set.contains(('A', 1))
     assert tree_set.tree.root.left.left.data == ('A', 1)
    def test_add(self):
        elements = ['L', 'M']
        set = TreeSet(elements)
        set.add('A')
        set.add('O')
        # Testing if it already exists within
        with self.assertRaises(KeyError):
            set.add('L')  # Already exists
        with self.assertRaises(KeyError):
            set.add('O')  # Already exists

        assert set.size is 4
        assert set.contains('L') is True

        assert set.contains('S') is False
 def test_duplicate(self):
     s = TreeSet([1, 2])
     with self.assertRaises(ValueError):
         s.add(1)