(t *testing.T, algorithm func(input string) int)
| 8 | ) |
| 9 | |
| 10 | func lpsTestTemplate(t *testing.T, algorithm func(input string) int) { |
| 11 | testCases := []struct { |
| 12 | input string |
| 13 | expected int |
| 14 | }{ |
| 15 | {"BBABCBCAB", 7}, |
| 16 | {"BBBAB", 4}, |
| 17 | {"ABBD", 2}, |
| 18 | {"GEEKSFORGEEKS", 5}, |
| 19 | {"abcdefgh", 1}, |
| 20 | {"bbbab", 4}, |
| 21 | {"cbbd", 2}, |
| 22 | {"racexyzcxar", 7}, |
| 23 | } |
| 24 | for _, tc := range testCases { |
| 25 | t.Run(fmt.Sprint("test with ", tc.input), func(t *testing.T) { |
| 26 | result := algorithm(tc.input) |
| 27 | if tc.expected != result { |
| 28 | t.Fatalf("expected %d, got %d", tc.expected, result) |
| 29 | } |
| 30 | }) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func TestLpsRec(t *testing.T) { |
| 35 | lpsTestTemplate(t, dynamic.LpsRec) |
no outgoing calls
no test coverage detected