|
| 1 | +package camelcase_matching |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +type caseType struct { |
| 9 | + queries []string |
| 10 | + pattern string |
| 11 | + expected []bool |
| 12 | +} |
| 13 | + |
| 14 | +func TestCamelMatch(t *testing.T) { |
| 15 | + tests := [...]caseType{ |
| 16 | + { |
| 17 | + queries: []string{"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"}, |
| 18 | + pattern: "FB", |
| 19 | + expected: []bool{true, false, true, true, false}, |
| 20 | + }, |
| 21 | + { |
| 22 | + queries: []string{"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"}, |
| 23 | + pattern: "FoBa", |
| 24 | + expected: []bool{true, false, true, false, false}, |
| 25 | + }, |
| 26 | + { |
| 27 | + queries: []string{"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"}, |
| 28 | + pattern: "FoBaT", |
| 29 | + expected: []bool{false, true, false, false, false}, |
| 30 | + }, |
| 31 | + { |
| 32 | + queries: []string{"CompetitiveProgramming", "CounterPick", "ControlPanel"}, |
| 33 | + pattern: "CooP", |
| 34 | + expected: []bool{false, false, true}, |
| 35 | + }, |
| 36 | + { |
| 37 | + queries: []string{"aksvbjLiknuTzqon", "ksvjLimflkpnTzqn", "mmkasvjLiknTxzqn", "ksvjLiurknTzzqbn", "ksvsjLctikgnTzqn", "knzsvzjLiknTszqn"}, |
| 38 | + pattern: "ksvjLiknTzqn", |
| 39 | + expected: []bool{true, true, true, true, true, true}, |
| 40 | + }, |
| 41 | + } |
| 42 | + for _, tc := range tests { |
| 43 | + output := camelMatch(tc.queries, tc.pattern) |
| 44 | + if !reflect.DeepEqual(output, tc.expected) { |
| 45 | + t.Fatalf("input: %v, output: %v, expected: %v", tc.pattern, output, tc.expected) |
| 46 | + } |
| 47 | + } |
| 48 | +} |
0 commit comments