コード例 #1
0
ファイル: test_tree.py プロジェクト: giltayar/google-ex
    def test_random_mutable_adds_and_deletes(self):
        t = Tree(10)
        s = {10}
        for _ in range(100):
            r = random.randint(0, 100000000)
            t.add_mutable(r)
            s.add(r)

            self.assertEqual(t.as_list(), sorted(s))

        for i in range(99):
            r = random.choice(list(s))
            t.del_mutable(r)
            s.remove(r)

            self.assertEqual(t.as_list(), sorted(s), "problem in {}th delete".format(i))
コード例 #2
0
ファイル: test_tree.py プロジェクト: giltayar/google-ex
    def test_del_immutable(self):
        t = Tree(10).add_immutables(15, 5, 3, 7) 
        t = t.del_mutable(15)
        self.assertEqual(t.as_list(),
                         [3, 5, 7, 10])
        t = t.del_mutable(5)
        self.assertEqual(t.as_list(),
                         [3, 7, 10])
        t = t.del_mutable(10)
        self.assertEqual(t.as_list(),
                         [3, 7])

        t = Tree(10).add_mutable(15, 12, 11, 20, 25, 5, 3, 7, 
                1, 4, 6, 8)

        self.assertEqual(t.as_list(),
                [1, 3, 4, 5, 6, 7, 8, 10,
                    11, 12, 15, 20, 25])
        t = t.del_mutable(25)
        self.assertEqual(t.as_list(),
                [1, 3, 4, 5, 6, 7, 8, 10,
                    11, 12, 15, 20])
        t = t.del_mutable(11)
        self.assertEqual(t.as_list(),
                [1, 3, 4, 5, 6, 7, 8, 10,
                    12, 15, 20])
        t = t.del_mutable(8)
        self.assertEqual(t.as_list(),
                [1, 3, 4, 5, 6, 7, 10,
                    12, 15, 20])
        t = t.del_mutable(1)
        self.assertEqual(t.as_list(),
                [3, 4, 5, 6, 7, 10,
                    12, 15, 20])
        t = t.del_mutable(7)
        self.assertEqual(t.as_list(),
                [3, 4, 5, 6, 10,
                    12, 15, 20])
        t = t.del_mutable(3)
        self.assertEqual(t.as_list(),
                [4, 5, 6, 10,
                    12, 15, 20])
        t = t.del_mutable(10)
        self.assertEqual(t.as_list(),
                [4, 5, 6,
                    12, 15, 20])