Simple implementation of LBC's fizzbuzz API server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

package fizzbuzz
import (
"reflect"
"testing"
)
func TestGenerateFizzbuzz(t *testing.T) {
tcases := []struct {
in *inputs
expect []string
}{
// Invlid cases
{in: nil, expect: []string{}},
{in: &inputs{string1: "aa", string2: "bb", int1: 3, int2: 5, limit: 0}, expect: []string{}},
{
in: &inputs{string1: "aa", string2: "bb", int1: 0, int2: 0, limit: 5},
expect: []string{"1", "2", "3", "4", "5"},
},
{
in: &inputs{string1: "", string2: "bb", int1: 2, int2: 0, limit: 5},
expect: []string{"1", "", "3", "", "5"},
},
{
in: &inputs{string1: "", string2: "", int1: 1, int2: 2, limit: 5},
expect: []string{"", "", "", "", ""},
},
// Valid cases
{
in: &inputs{string1: "aa", string2: "bb", int1: 3, int2: 2, limit: 12},
expect: []string{"1", "bb", "aa", "bb", "5", "aabb", "7", "bb", "aa", "bb", "11", "aabb"},
},
{
in: &inputs{string1: "cc", string2: "dd", int1: 10, int2: 5, limit: 11},
expect: []string{"1", "2", "3", "4", "dd", "6", "7", "8", "9", "ccdd", "11"},
},
}
for i, tcase := range tcases {
if got, want := tcase.in.generateFizzbuzz(), tcase.expect; !reflect.DeepEqual(got, want) {
t.Fatalf("%d: got %#v, want %#v", i+1, got, want)
}
}
}