Created
August 15, 2021 04:31
-
-
Save syafdia/3c93a91d3e37f098c6744b6af4b940ec 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
// calc_test.go | |
package calc | |
import "testing" | |
func TestFactorial(t *testing.T) { | |
type args struct { | |
n uint | |
} | |
tests := []struct { | |
name string | |
args args | |
want uint | |
}{ | |
{ | |
name: "N is 0", | |
args: args{n: 0}, | |
want: 1, | |
}, | |
{ | |
name: "N is 1", | |
args: args{n: 3}, | |
want: 1, | |
}, | |
{ | |
name: "N is 3", | |
args: args{n: 3}, | |
want: 6, | |
}, | |
{ | |
name: "N is 10", | |
args: args{n: 10}, | |
want: 3628800, | |
}, | |
} | |
for _, tt := range tests { | |
t.Run(tt.name, func(t *testing.T) { | |
if got := Factorial(tt.args.n); got != tt.want { | |
t.Errorf("Factorial() = %v, want %v", got, tt.want) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment