func TestFizzBuzz_Contents(t *testing.T) { result := FizzBuzz() expectedStart := []string{"1", "2", "Fizz", "4", "Buzz", "Fizz", "7"} expectedMid := []string{"14", "FizzBuzz", "16"} assert.DeepEqual(t, expectedStart, result[:7]) assert.DeepEqual(t, expectedMid, result[13:16]) }
func TestQueryFromOpts(t *testing.T) { query, args := FormatOpts( "SELECT name FROM expenses", OrderBy("name ASC"), Where("ignore = '?' AND name = ? AND age > ? AND created_at < ?", "harald", 12, "2015"), Limit(12), ) assert.Equal(t, "SELECT name FROM expenses WHERE ignore = '?' AND name = $1 AND age > $2 AND created_at < $3 ORDER BY name ASC LIMIT 12", query) assert.DeepEqual(t, []interface{}{"harald", 12, "2015"}, args) }
func TestGetLOC(t *testing.T) { codeToTest := `/* this is the code to test the first lines are a documentation comment */ // after this comes a function func name(params) int { // indented comment return 42 }` loc := GetLOC(codeToTest) assert.DeepEqual(t, LOCData{ Total: 9, Code: 3, Comments: 5, Whitespace: 1, }, loc) }
// http://de.scribd.com/doc/141109135/Function-Kata-ToDictionary func TestToDictionary(t *testing.T) { dict, err := ToDictionary("a=1;b=2;c=3") assert.Nil(t, err) assert.DeepEqual(t, Dictionary{"a": "1", "b": "2", "c": "3"}, dict) dict, err = ToDictionary("a=1;a=2") assert.Nil(t, err) assert.DeepEqual(t, Dictionary{"a": "2"}, dict) dict, err = ToDictionary("a=") assert.Nil(t, err) assert.DeepEqual(t, Dictionary{"a": ""}, dict) dict, err = ToDictionary("") assert.Nil(t, err) assert.DeepEqual(t, Dictionary{}, dict) dict, err = ToDictionary("a==1") assert.Nil(t, err) assert.DeepEqual(t, Dictionary{"a": "=1"}, dict) dict, err = ToDictionary("=1") assert.DeepEqual(t, errors.New("Invalid Input"), err) }
func TestCalculateHappyNumbers(t *testing.T) { assert.DeepEqual(t, []int{7, 10, 13, 19}, CalculateHappyNumbers(5, 20)) assert.DeepEqual(t, []int{13, 19, 23, 28, 31, 32, 44}, CalculateHappyNumbers(13, 44)) }