Skip to content

Instantly share code, notes, and snippets.

@Voles
Created October 28, 2019 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Voles/d0a81fce7fdafeead4f661706185a125 to your computer and use it in GitHub Desktop.
Save Voles/d0a81fce7fdafeead4f661706185a125 to your computer and use it in GitHub Desktop.
BizzBuzz attempt
package code_kata
import "testing"
import "strconv"
//func TestLineCount(t *testing.T) {
// buffer := fizbuzz()
//
// if len(buffer) != 100 {
// t.Fail("expected 100 lines")
// }
//}
func TestNumber15(t *testing.T) {
// Given the number 15 we expect the return value fizzbuzz
result := fizzbuzzing(15)
if result != "fizzbuzz" {
t.Errorf("Expected fizzbuzz, got %s", result)
}
}
func TestNumber1(t *testing.T) {
// Given the number 1 we expect the return value 1
result := fizzbuzzing( 1)
if result != "1" {
t.Errorf("Expected 1, got %s", result)
}
}
func TestNumber5(t *testing.T) {
// Given the number 5 we expect the return value buzz
result := fizzbuzzing(5)
if result != "buzz" {
t.Errorf("Expected buzz, got %s", result)
}
}
func TestNumber3(t *testing.T) {
// Given the number 3 we expect the return value fizz
result := fizzbuzzing(3)
if result != "fizz" {
t.Errorf("Expected fizz, got %s", result)
}
}
func TestAll(t *testing.T) {
testSet := []struct{
input int
result string
}{
{1, "1"},
{6, "fizz"},
}
for _, test := range testSet {
// Given the number 3 we expect the return value fizz
result := fizzbuzzing(test.input)
if result != test.result {
t.Errorf("Expected %s, got %s", test.result, result)
}
}
}
func fizzbuzzing(number int) string {
if number == 15{
return "fizzbuzz"
}
if number / 3 == 0 {
return "fizz"
}
if number == 5 {
return "buzz"
}
return strconv.Itoa(number)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment