pokedex_cli/repl_test.go

60 lines
989 B
Go
Raw Normal View History

2025-09-28 20:15:55 +00:00
package main
import (
"fmt"
"testing"
2025-09-28 20:15:55 +00:00
)
func TestCleanInput(t *testing.T) {
2025-09-28 20:15:55 +00:00
cases := []struct {
input string
expected []string
2025-09-28 20:15:55 +00:00
}{
{
input: " hello world ",
expected: []string{"hello", "world"},
2025-09-28 20:15:55 +00:00
},
{
input: "Charmander Bulbasaur PIKACHU",
expected: []string{"charmander", "bulbasaur", "pikachu"},
2025-09-28 20:15:55 +00:00
},
{
input: "",
expected: []string{},
2025-09-28 20:15:55 +00:00
},
}
successCount := 0
failCount := 0
passed := true
for _, c := range cases {
output := cleanInput(c.input)
for i := range output {
word := output[i]
expectedWord := c.expected[i]
if word != expectedWord {
passed = false
break
}
}
if !passed {
t.Errorf(`
===================
Input: %v
Expected: %v
Output: %v
`, c.input, c.expected, output)
failCount++
} else {
fmt.Printf(`
===================
Input: %v
Expected: %v
Output: %v
`, c.input, c.expected, output)
2025-09-28 20:15:55 +00:00
successCount++
}
}
fmt.Printf("%d passed, %d failed", successCount, failCount)
}