Created
March 15, 2016 11:30
-
-
Save zaky/8304b5abbdc03600c29e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Fibonacci | |
import "testing" | |
func TestFibonacci(t *testing.T) { | |
parameters := []struct { | |
input, expected int | |
}{ | |
{0, 0}, {1, 1}, {2, 1}, {3, 2}, {4, 3}, {5, 5}, {6, 8}, | |
} | |
for i := range parameters { | |
actual := compute(parameters[i].input) | |
if actual != parameters[i].expected { | |
t.Logf("expected%d: , actual:%d", parameters[i].expected, actual) | |
t.Fail() | |
} | |
} | |
} | |
func compute(n int) int { | |
result := 0 | |
if n <= 1 { | |
result = n | |
} else { | |
result = compute(n-1) + compute(n-2) | |
} | |
return result | |
} | |
//In oppose to https://github.com/junit-team/junit/wiki/Parameterized-tests |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also add
t.Run
so that when one (or some) of the parameters fail, you get better error messages in go test