MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / lpsTestTemplate

Function lpsTestTemplate

dynamic/longestpalindromicsubsequence_test.go:10–32  ·  view source on GitHub ↗
(t *testing.T, algorithm func(input string) int)

Source from the content-addressed store, hash-verified

8)
9
10func 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
34func TestLpsRec(t *testing.T) {
35 lpsTestTemplate(t, dynamic.LpsRec)

Callers 2

TestLpsRecFunction · 0.85
TestLpsDpFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected