Skip to content

Instantly share code, notes, and snippets.

@syafdia
Created August 15, 2021 04:31
Show Gist options
  • Save syafdia/3c93a91d3e37f098c6744b6af4b940ec to your computer and use it in GitHub Desktop.
Save syafdia/3c93a91d3e37f098c6744b6af4b940ec to your computer and use it in GitHub Desktop.
// 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