#include #include #include #include #include #include using BoolTrie = Void::Trie::Trie; using IntTrie = Void::Trie::Trie; // ── insert / contains ───────────────────────────────────────────────────────── Void::Testing::Test trie_insert_and_contains() { BoolTrie t; t.insert("hello"); Void::Testing::expect(t.contains("hello")); } Void::Testing::Test trie_does_not_contain_prefix_only() { BoolTrie t; t.insert("hello"); Void::Testing::expect(!t.contains("hell")); } Void::Testing::Test trie_does_not_contain_extension() { BoolTrie t; t.insert("hell"); Void::Testing::expect(!t.contains("hello")); } Void::Testing::Test trie_insert_empty_key() { BoolTrie t; t.insert(""); Void::Testing::expect(t.contains("")); } Void::Testing::Test trie_multiple_words() { BoolTrie t; t.insert("car"); t.insert("card"); t.insert("care"); Void::Testing::expect(t.contains("car")); Void::Testing::expect(t.contains("card")); Void::Testing::expect(t.contains("care")); Void::Testing::expect(!t.contains("ca")); } // ── get ─────────────────────────────────────────────────────────────────────── Void::Testing::Test trie_get_value() { IntTrie t; t.insert("key", 42); const auto v = t.get("key"); Void::Testing::expect(v.has_value()); Void::Testing::expect_eq(*v, 42); } Void::Testing::Test trie_get_missing_returns_nullopt() { IntTrie t; Void::Testing::expect(!t.get("nope").has_value()); } // ── starts_with ─────────────────────────────────────────────────────────────── Void::Testing::Test trie_starts_with_true() { BoolTrie t; t.insert("hello"); Void::Testing::expect(t.starts_with("hel")); } Void::Testing::Test trie_starts_with_false() { BoolTrie t; t.insert("hello"); Void::Testing::expect(!t.starts_with("world")); } // ── erase ──────────────────────────────────────────────────────────────────── Void::Testing::Test trie_erase_removes_word() { BoolTrie t; t.insert("hello"); Void::Testing::expect(t.erase("hello")); Void::Testing::expect(!t.contains("hello")); } Void::Testing::Test trie_erase_prefix_word_keeps_extension() { BoolTrie t; t.insert("car"); t.insert("card"); t.erase("car"); Void::Testing::expect(!t.contains("car")); Void::Testing::expect(t.contains("card")); } Void::Testing::Test trie_erase_missing_returns_false() { BoolTrie t; Void::Testing::expect(!t.erase("nope")); } // ── keys_with_prefix ────────────────────────────────────────────────────────── Void::Testing::Test trie_keys_with_prefix() { BoolTrie t; t.insert("car"); t.insert("card"); t.insert("care"); t.insert("dog"); auto keys = t.keys_with_prefix("car"); std::sort(keys.begin(), keys.end()); Void::Testing::expect_eq(keys.size(), std::size_t{3}); Void::Testing::expect_eq(keys[0], std::string{"car"}); Void::Testing::expect_eq(keys[1], std::string{"card"}); Void::Testing::expect_eq(keys[2], std::string{"care"}); } Void::Testing::Test trie_keys_with_prefix_no_match() { BoolTrie t; t.insert("hello"); Void::Testing::expect(t.keys_with_prefix("xyz").empty()); } // ── size ───────────────────────────────────────────────────────────────────── Void::Testing::Test trie_size_tracks_inserts() { BoolTrie t; Void::Testing::expect_eq(t.size(), std::size_t{0}); t.insert("a"); t.insert("b"); Void::Testing::expect_eq(t.size(), std::size_t{2}); }