feat: add unit test
This commit is contained in:
@@ -17,7 +17,7 @@ const (
|
|||||||
const (
|
const (
|
||||||
TotalGestationPeriod = 15
|
TotalGestationPeriod = 15
|
||||||
MinChild = 5
|
MinChild = 5
|
||||||
MaxCild = 9
|
MaxChild = 9
|
||||||
GestationCooldown = (3 * 7) + 2
|
GestationCooldown = (3 * 7) + 2
|
||||||
GestationMinAge = 10 * 6
|
GestationMinAge = 10 * 6
|
||||||
MaxAge = 365 * 2
|
MaxAge = 365 * 2
|
||||||
@@ -114,7 +114,7 @@ func Born(father *Hamster, mother *Hamster) ([]*Hamster, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func randNumberChild() int {
|
func randNumberChild() int {
|
||||||
return randNumber(MinChild, MaxCild)
|
return randNumber(MinChild, MaxChild)
|
||||||
}
|
}
|
||||||
|
|
||||||
func randSexe() string {
|
func randSexe() string {
|
||||||
@@ -128,5 +128,5 @@ func randSexe() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func randNumber(min int, max int) int {
|
func randNumber(min int, max int) int {
|
||||||
return min + randomizer.Rand(max-min)
|
return min + randomizer.Rand(max)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDie(t *testing.T) {
|
func TestHamster_Die(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
caseName string
|
caseName string
|
||||||
hamster *Hamster
|
hamster *Hamster
|
||||||
@@ -39,7 +39,7 @@ func TestDie(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFuck(t *testing.T) {
|
func TestHamster_Fuck(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
caseName string
|
caseName string
|
||||||
hamster1 *Hamster
|
hamster1 *Hamster
|
||||||
@@ -180,43 +180,6 @@ func TestFuck(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHamster_Die(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
h *Hamster
|
|
||||||
}{
|
|
||||||
// TODO: Add test cases.
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
tt.h.Die()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHamster_Fuck(t *testing.T) {
|
|
||||||
type args struct {
|
|
||||||
another *Hamster
|
|
||||||
}
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
h *Hamster
|
|
||||||
args args
|
|
||||||
want bool
|
|
||||||
wantErr bool
|
|
||||||
}{
|
|
||||||
// TODO: Add test cases.
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
got, err := tt.h.Fuck(tt.args.another)
|
|
||||||
if (err != nil) != tt.wantErr {
|
|
||||||
t.Errorf("%q. Hamster.Fuck() error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if got != tt.want {
|
|
||||||
t.Errorf("%q. Hamster.Fuck() = %v, want %v", tt.name, got, tt.want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBorn(t *testing.T) {
|
func TestBorn(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
father *Hamster
|
father *Hamster
|
||||||
@@ -242,28 +205,26 @@ func TestBorn(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_randNumberChild(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
want int
|
|
||||||
}{
|
|
||||||
// TODO: Add test cases.
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
if got := randNumberChild(); got != tt.want {
|
|
||||||
t.Errorf("%q. randNumberChild() = %v, want %v", tt.name, got, tt.want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_randSexe(t *testing.T) {
|
func Test_randSexe(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
want string
|
want string
|
||||||
|
fakeGen int
|
||||||
}{
|
}{
|
||||||
// TODO: Add test cases.
|
{
|
||||||
|
name: "Should be a male",
|
||||||
|
fakeGen: 1,
|
||||||
|
want: MALE,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Should be a female",
|
||||||
|
fakeGen: 0,
|
||||||
|
want: FEMALE,
|
||||||
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
randomizer.FakeRandomizer(tt.fakeGen)
|
||||||
if got := randSexe(); got != tt.want {
|
if got := randSexe(); got != tt.want {
|
||||||
t.Errorf("%q. randSexe() = %v, want %v", tt.name, got, tt.want)
|
t.Errorf("%q. randSexe() = %v, want %v", tt.name, got, tt.want)
|
||||||
}
|
}
|
||||||
@@ -278,11 +239,21 @@ func Test_randNumber(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
|
fakeGen int
|
||||||
want int
|
want int
|
||||||
}{
|
}{
|
||||||
// TODO: Add test cases.
|
{
|
||||||
|
name: "Should add min to result",
|
||||||
|
args: args{
|
||||||
|
min: 1,
|
||||||
|
max: 2,
|
||||||
|
},
|
||||||
|
fakeGen: 0,
|
||||||
|
want: 1,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
randomizer.FakeRandomizer(tt.fakeGen)
|
||||||
if got := randNumber(tt.args.min, tt.args.max); got != tt.want {
|
if got := randNumber(tt.args.min, tt.args.max); got != tt.want {
|
||||||
t.Errorf("%q. randNumber() = %v, want %v", tt.name, got, tt.want)
|
t.Errorf("%q. randNumber() = %v, want %v", tt.name, got, tt.want)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package randomizer
|
package randomizer
|
||||||
|
|
||||||
import "math/rand"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
)
|
||||||
|
|
||||||
type Random interface {
|
type Random interface {
|
||||||
Int() int
|
Int() int
|
||||||
@@ -25,8 +28,13 @@ func Rand(rand int) int {
|
|||||||
return randGen(rand)
|
return randGen(rand)
|
||||||
}
|
}
|
||||||
func realRand(n int) int { return int(rand.Intn(n)) }
|
func realRand(n int) int { return int(rand.Intn(n)) }
|
||||||
func fakeRand(n int) func(_ int) int {
|
func fakeRand(n int) func(numb int) int {
|
||||||
return func(_ int)int { return n}
|
return func(numb int)int {
|
||||||
|
if n >= numb {
|
||||||
|
panic(fmt.Sprintf("%d Should not be superior of %d",n,numb))
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var randGen = NewRandomizer(realRand).Int
|
var randGen = NewRandomizer(realRand).Int
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user