예제 #1
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_insert_one(self):
     t = TST()
     t.insert("one", 97)
     self.assertFalse(t.is_empty())
     self.assertEqual(t.count(), 1)
     self.assertEqual(t.search("one"), 97)
     self.assertTrue(t.contains("one"))
예제 #2
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_keys_with_prefix_two_found(self):
     t = TST()
     t.insert("one", 1)
     t.insert("two", 2)
     t.delete("one")
     t.insert("three", 3)
     self.assertEqual(sorted(t.keys_with_prefix("t")), ["three", "two"])
예제 #3
0
파일: test_TST.py 프로젝트: michiboo1/ands
    def test_delete_inexistent_key(self):
        t = TST()
        t.insert("first", "1st")

        self.assertIsNone(t.delete("second"))
        self.assertFalse(t.is_empty())
        self.assertEqual(t.count(), 1)
        self.assertTrue(t.contains("first"))
        self.assertEqual(t.search("first"), "1st")
예제 #4
0
파일: test_TST.py 프로젝트: michiboo1/ands
    def test_delete_the_only_key(self):
        t = TST()
        t.insert("seven", 7)

        self.assertEqual(t.delete("seven"), 7)
        self.assertTrue(t.is_empty())
        self.assertEqual(t.count(), 0)
        self.assertFalse(t.contains("seven"))
        self.assertIsNone(t.search("seven"))
예제 #5
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_insert_two(self):
     t = TST()
     t.insert("he", 0)
     t.insert("she", 1)
     self.assertFalse(t.is_empty())
     self.assertEqual(t.count(), 2)
     self.assertEqual(t.search("he"), 0)
     self.assertEqual(t.search("she"), 1)
     self.assertTrue(t.contains("he"))
     self.assertTrue(t.contains("she"))
예제 #6
0
파일: test_TST.py 프로젝트: michiboo1/ands
    def test_all_pairs_random_size_and_strings(self):
        t = TST()

        n = random.randint(3, 1000)
        random_pairs = {}

        for _ in range(n):
            key = TestTST.gen_rand_str(random.randint(1, 17))
            random_pairs[key] = key
            t.insert(key, key)

        self.assertEqual(t.all_pairs(), random_pairs)
예제 #7
0
파일: test_TST.py 프로젝트: michiboo1/ands
    def test_delete_same_key_twice(self):
        t = TST()
        t.insert("one", 1)
        t.insert("two", 2)
        t.insert("three", 3)

        self.assertEqual(t.delete("three"), 3)
        self.assertIsNone(t.delete("three"))
        self.assertFalse(t.is_empty())
        self.assertEqual(t.count(), 2)
        self.assertTrue(t.contains("one"))
        self.assertTrue(t.contains("two"))
        self.assertEqual(t.search("one"), 1)
        self.assertEqual(t.search("two"), 2)
예제 #8
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_keys_that_match_pattern_using_dots_to_retrieve_all_keys_of_certain_length(
         self):
     t = TST()
     t.insert("zero", 0)
     t.insert("one", 1)
     t.insert("two", 2)
     t.insert("three", 3)
     t.insert("four", 4)
     t.insert("five", 5)
     t.insert("six", 6)
     self.assertEqual(sorted(t.keys_that_match("...")),
                      ["one", "six", "two"])
     self.assertEqual(sorted(t.keys_that_match("....")),
                      ["five", "four", "zero"])
     self.assertEqual(sorted(t.keys_that_match(".....")), ["three"])
예제 #9
0
파일: test_TST.py 프로젝트: michiboo1/ands
    def test_keys_with_prefix_empty_prefix(self):
        t = TST()

        n = random.randint(1, 50)
        keys = set()

        for _ in range(n):
            key = TestTST.gen_rand_str(random.randint(1, 11))
            keys.add(key)
            t.insert(key, key)

        kwp = t.keys_with_prefix("")
        kwp_set = set(kwp)
        self.assertEqual(len(kwp), len(
            kwp_set))  # I should not need to check this here!!!
        self.assertEqual(kwp_set, keys)
예제 #10
0
파일: test_TST.py 프로젝트: michiboo1/ands
    def test_insert_random_keys(self):
        t = TST()

        n = random.randint(4, 100)
        random_pairs = {}

        for _ in range(n):
            key = TestTST.gen_rand_str(random.randint(1, 11))
            random_pairs[key] = key
            t.insert(key, key)

            self.assertFalse(t.is_empty())
            self.assertEqual(t.count(), len(random_pairs))

        for k, v in random_pairs.items():
            self.assertEqual(t.search(k), v)
            self.assertTrue(t.contains(k))
예제 #11
0
파일: test_TST.py 프로젝트: michiboo1/ands
    def test_delete_the_two_keys(self):
        t = TST()
        t.insert("one", 1)
        t.insert("two", 2)

        self.assertEqual(t.delete("one"), 1)
        self.assertFalse(t.is_empty())
        self.assertEqual(t.count(), 1)
        self.assertFalse(t.contains("one"))
        self.assertTrue(t.contains("two"))
        self.assertIsNone(t.search("one"))
        self.assertEqual(t.search("two"), 2)

        self.assertEqual(t.delete("two"), 2)
        self.assertTrue(t.is_empty())
        self.assertEqual(t.count(), 0)
        self.assertFalse(t.contains("one"))
        self.assertFalse(t.contains("two"))
        self.assertIsNone(t.search("one"))
        self.assertIsNone(t.search("two"))
예제 #12
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_insert_same_twice_to_update(self):
     t = TST()
     t.insert("seven", 7)
     t.insert("fly away", 11)
     t.insert("fly away", 101)
     t.insert("bandit queen", "Looptroop")
     self.assertFalse(t.is_empty())
     self.assertEqual(t.count(), 3)
     self.assertEqual(t.search("seven"), 7)
     self.assertEqual(t.search("fly away"), 101)
     self.assertEqual(t.search("bandit queen"), "Looptroop")
     self.assertTrue(t.contains("seven"))
     self.assertTrue(t.contains("fly away"))
     self.assertTrue(t.contains("bandit queen"))
예제 #13
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_keys_that_match_pattern_using_dots(self):
     t = TST()
     t.insert("nop", 0)
     t.insert("one", 1)
     t.insert("on", "fire")
     t.insert("fno", "ok")
     self.assertEqual(sorted(t.keys_that_match(".n.")), ["fno", "one"])
예제 #14
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_keys_with_prefix_all_found(self):
     t = TST()
     t.insert("occasion", 2)
     t.insert("occasionally", 2)
     t.insert("occam", 2)
     self.assertEqual(sorted(t.keys_with_prefix("occa")),
                      ["occam", "occasion", "occasionally"])
예제 #15
0
파일: test_TST.py 프로젝트: michiboo1/ands
    def test_delete_after_inserting_again(self):
        t = TST()

        t.insert("boo", 0.5)
        t.insert("neg", 1)
        self.assertEqual(t.delete("neg"), 1)

        t.insert("neg", 1)
        self.assertEqual(t.delete("neg"), 1)

        self.assertFalse(t.is_empty())
        self.assertEqual(t.count(), 1)
예제 #16
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_traverse_tst(self):
     t = TST()
     t.insert("one", 1)
     t.insert("two", 2)
     t.insert("three", 3)
     self.assertIsNone(t.traverse())
예제 #17
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_keys_with_prefix_prefix_size_equal_to_key_size(self):
     t = TST()
     t.insert("valete", "dama")
     self.assertEqual(t.keys_with_prefix("valete"), ["valete"])
예제 #18
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_keys_that_match_example_docs(self):
     t = TST()
     t.insert("food", 3)
     t.insert("good", 3)
     t.insert("foodie", 3)
     self.assertEqual(sorted(t.keys_that_match(".ood")), ["food", "good"])
예제 #19
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_keys_that_match_pattern_no_dots(self):
     t = TST()
     t.insert("one", 1)
     t.insert("on", "fire")
     self.assertEqual(t.keys_that_match("on"), ["on"])
예제 #20
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_longest_prefix_of_longest_prefix_size_of_query(self):
     t = TST()
     t.insert("allen", "first")
     t.insert("allen halloween", "underrated!")
     self.assertEqual(t.longest_prefix_of("allen halloween"),
                      "allen halloween")
예제 #21
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_longest_prefix_of_longest_prefix_size_two(self):
     t = TST()
     t.insert("p", 7)
     t.insert("oa", 23)
     self.assertEqual(t.longest_prefix_of("oak"), "oa")
예제 #22
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_longest_prefix_of_longest_prefix_size_one(self):
     t = TST()
     t.insert("o", 7)
     t.insert("obnoxious", 23)
     self.assertEqual(t.longest_prefix_of("overall"), "o")
예제 #23
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_longest_prefix_of_longest_prefix_size_zero(self):
     t = TST()
     t.insert("obnoxious", 7)
     # obnoxious is NOT even a prefix of over
     self.assertEqual(t.longest_prefix_of("over"), "")
예제 #24
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_keys_with_prefix_one_found(self):
     t = TST()
     t.insert("one", 1)
     t.insert("two", 2)
     t.insert("three", 3)
     self.assertEqual(t.keys_with_prefix("on"), ["one"])
예제 #25
0
파일: test_TST.py 프로젝트: michiboo1/ands
 def test_all_pairs_tst_size_1(self):
     t = TST()
     t.insert("the most sadistic", "necro")
     self.assertEqual(t.all_pairs(), {"the most sadistic": "necro"})