pokedex_cli/repl_test.go
2025-09-28 21:15:55 +01:00

60 lines
985 B
Go

package main
import (
"testing"
"fmt"
)
func TestCleanInput(t * testing.T) {
cases := []struct {
input string
expected []string
}{
{
input: " hello world ",
expected: []string{"hello", "world"},
},
{
input: "Charmander Bulbasaur PIKACHU",
expected: []string{"charmander", "bulbasaur", "pikachu"},
},
{
input: "",
expected: []string{},
},
}
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)
successCount++
}
}
fmt.Printf("%d passed, %d failed", successCount, failCount)
}