MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / TestTrie

Function TestTrie

implement_trie_208/solution_test.go:8–69  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestTrie(t *testing.T) {
9 type operation struct {
10 method string
11 value string
12 want bool
13 }
14
15 testCases := []struct {
16 name string
17 ops []operation
18 }{
19 {
20 name: "trie test",
21 ops: []operation{
22 {
23 method: "Insert",
24 value: "apple",
25 },
26 {
27 method: "Search",
28 value: "apple",
29 want: true,
30 },
31 {
32 method: "Search",
33 value: "app",
34 want: false,
35 },
36 {
37 method: "StartsWith",
38 value: "app",
39 want: true,
40 },
41 {
42 method: "Insert",
43 value: "app",
44 },
45 {
46 method: "Search",
47 value: "app",
48 want: true,
49 },
50 },
51 },
52 }
53
54 for _, tt := range testCases {
55 t.Run(tt.name, func(t *testing.T) {
56 trie := Constructor()
57 for _, op := range tt.ops {
58 switch op.method {
59 case "Insert":
60 trie.Insert(op.value)
61 case "Search":
62 assert.Equal(t, op.want, trie.Search(op.value))
63 case "StartsWith":
64 assert.Equal(t, op.want, trie.StartsWith(op.value))
65 }

Callers

nothing calls this directly

Calls 4

InsertMethod · 0.80
SearchMethod · 0.80
StartsWithMethod · 0.80
ConstructorFunction · 0.70

Tested by

no test coverage detected