ci: add acceptance test
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package hamster_tycoon
|
||||
|
||||
|
||||
type Cage struct {
|
||||
Hamsters []*Hamster
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package hamster_tycoon
|
||||
|
||||
|
||||
type Game struct {
|
||||
Cages []*Cage
|
||||
Cages []*Cage
|
||||
SelledHamster []*Hamster
|
||||
|
||||
}
|
||||
@@ -15,44 +15,43 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
TotalGestationPeriod = 15
|
||||
MinChild = 5
|
||||
MaxCild = 9
|
||||
GestationCooldown = (3*7) + 2
|
||||
GestationMinAge = 10*6
|
||||
MaxAge = 365*2
|
||||
GestationLuck = 70
|
||||
FEMALE = "F"
|
||||
MALE = "M"
|
||||
|
||||
TotalGestationPeriod = 15
|
||||
MinChild = 5
|
||||
MaxCild = 9
|
||||
GestationCooldown = (3 * 7) + 2
|
||||
GestationMinAge = 10 * 6
|
||||
MaxAge = 365 * 2
|
||||
GestationLuck = 70
|
||||
FEMALE = "F"
|
||||
MALE = "M"
|
||||
)
|
||||
|
||||
var GlobalHamsterNumber = 1
|
||||
|
||||
type Hamster struct {
|
||||
Name string
|
||||
Number int
|
||||
Sexe string
|
||||
Age int
|
||||
Father *Hamster
|
||||
Mother *Hamster
|
||||
HungerLevel int8
|
||||
ThirstLevel int8
|
||||
Weight float64
|
||||
Height float64
|
||||
Alive bool
|
||||
Selled bool
|
||||
Gestation bool
|
||||
GestationPeriod int8
|
||||
Name string
|
||||
Number int
|
||||
Sexe string
|
||||
Age int
|
||||
Father *Hamster
|
||||
Mother *Hamster
|
||||
HungerLevel int8
|
||||
ThirstLevel int8
|
||||
Weight float64
|
||||
Height float64
|
||||
Alive bool
|
||||
Selled bool
|
||||
Gestation bool
|
||||
GestationPeriod int8
|
||||
GestationCooldown int8
|
||||
Child []*Hamster
|
||||
Child []*Hamster
|
||||
}
|
||||
|
||||
func(h *Hamster) Die(){
|
||||
func (h *Hamster) Die() {
|
||||
h.Alive = false
|
||||
}
|
||||
|
||||
func (h *Hamster) Fuck(another *Hamster) (bool,error){
|
||||
func (h *Hamster) Fuck(another *Hamster) (bool, error) {
|
||||
if h.Sexe == another.Sexe {
|
||||
return false, errors.New("can't fuck together")
|
||||
}
|
||||
@@ -61,10 +60,16 @@ func (h *Hamster) Fuck(another *Hamster) (bool,error){
|
||||
return false, errors.New("one of the hamster is too young")
|
||||
}
|
||||
|
||||
rand := randNumber(1,100)
|
||||
rand := randNumber(1, 100)
|
||||
|
||||
if rand <= GestationLuck {
|
||||
female := func() *Hamster{if h.Sexe == FEMALE {return h } else {return another}}()
|
||||
female := func() *Hamster {
|
||||
if h.Sexe == FEMALE {
|
||||
return h
|
||||
} else {
|
||||
return another
|
||||
}
|
||||
}()
|
||||
female.Gestation = true
|
||||
female.GestationPeriod = 0
|
||||
female.GestationCooldown = TotalGestationPeriod + GestationCooldown
|
||||
@@ -72,7 +77,7 @@ func (h *Hamster) Fuck(another *Hamster) (bool,error){
|
||||
return rand <= GestationLuck, nil
|
||||
}
|
||||
|
||||
func Born(father *Hamster, mother *Hamster)([]*Hamster,error){
|
||||
func Born(father *Hamster, mother *Hamster) ([]*Hamster, error) {
|
||||
if !mother.Alive || mother.Selled {
|
||||
return nil, errors.New("the mother is not here")
|
||||
}
|
||||
@@ -85,43 +90,43 @@ func Born(father *Hamster, mother *Hamster)([]*Hamster,error){
|
||||
mother.GestationPeriod = 0
|
||||
|
||||
numberOfChild := randNumberChild()
|
||||
child := make([]*Hamster,numberOfChild)
|
||||
for i := 1; i <= numberOfChild; i++{
|
||||
child := make([]*Hamster, numberOfChild)
|
||||
for i := 1; i <= numberOfChild; i++ {
|
||||
child[i] = &Hamster{
|
||||
Name: fmt.Sprintf("Hamster %d",GlobalHamsterNumber),
|
||||
Number: GlobalHamsterNumber,
|
||||
Age : 1,
|
||||
Sexe: randSexe(),
|
||||
Father: father,
|
||||
Mother: mother,
|
||||
HungerLevel: Full,
|
||||
ThirstLevel: Full,
|
||||
Alive: true,
|
||||
Selled: false,
|
||||
Gestation: false,
|
||||
GestationPeriod: 0,
|
||||
Name: fmt.Sprintf("Hamster %d", GlobalHamsterNumber),
|
||||
Number: GlobalHamsterNumber,
|
||||
Age: 1,
|
||||
Sexe: randSexe(),
|
||||
Father: father,
|
||||
Mother: mother,
|
||||
HungerLevel: Full,
|
||||
ThirstLevel: Full,
|
||||
Alive: true,
|
||||
Selled: false,
|
||||
Gestation: false,
|
||||
GestationPeriod: 0,
|
||||
GestationCooldown: 30,
|
||||
}
|
||||
}
|
||||
mother.Child = append(mother.Child, child...)
|
||||
father.Child = append(father.Child, child...)
|
||||
return child,nil
|
||||
return child, nil
|
||||
}
|
||||
|
||||
func randNumberChild() int {
|
||||
return randNumber(MinChild,MaxCild)
|
||||
return randNumber(MinChild, MaxCild)
|
||||
}
|
||||
|
||||
func randSexe() string {
|
||||
return func () string{
|
||||
if randNumber(1,2) == 2 {
|
||||
return func() string {
|
||||
if randNumber(1, 2) == 2 {
|
||||
return MALE
|
||||
} else {
|
||||
return FEMALE
|
||||
return FEMALE
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func randNumber(min int ,max int) int {
|
||||
func randNumber(min int, max int) int {
|
||||
return min + rand.Intn(max-min)
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
|
||||
func TestDie(t *testing.T) {
|
||||
testCases := []struct {
|
||||
caseName string
|
||||
hamster *Hamster
|
||||
caseName string
|
||||
hamster *Hamster
|
||||
expectedAlive bool
|
||||
}{
|
||||
{
|
||||
@@ -39,41 +39,41 @@ func TestDie(t *testing.T) {
|
||||
|
||||
func TestFuck(t *testing.T) {
|
||||
testCases := []struct {
|
||||
caseName string
|
||||
hamster1 *Hamster
|
||||
hamster2 *Hamster
|
||||
caseName string
|
||||
hamster1 *Hamster
|
||||
hamster2 *Hamster
|
||||
expectedResult bool
|
||||
expectedError error
|
||||
expectedError error
|
||||
}{
|
||||
{
|
||||
caseName: "Hamster 1 too young",
|
||||
hamster1: &Hamster{
|
||||
Alive: true,
|
||||
Sexe: MALE,
|
||||
Age: GestationMinAge - 1,
|
||||
Sexe: MALE,
|
||||
Age: GestationMinAge - 1,
|
||||
},
|
||||
hamster2: &Hamster{
|
||||
Alive: true,
|
||||
Sexe: FEMALE,
|
||||
Age: GestationMinAge + 1,
|
||||
Sexe: FEMALE,
|
||||
Age: GestationMinAge + 1,
|
||||
},
|
||||
expectedResult: false,
|
||||
expectedError: errors.New("one of the hamster is too young"),
|
||||
expectedError: errors.New("one of the hamster is too young"),
|
||||
},
|
||||
{
|
||||
caseName: "Hamster 2 too young",
|
||||
hamster1: &Hamster{
|
||||
Alive: false,
|
||||
Sexe: MALE,
|
||||
Age: GestationMinAge + 1,
|
||||
Sexe: MALE,
|
||||
Age: GestationMinAge + 1,
|
||||
},
|
||||
hamster2: &Hamster{
|
||||
Alive: true,
|
||||
Sexe: FEMALE,
|
||||
Age: GestationMinAge - 1,
|
||||
Sexe: FEMALE,
|
||||
Age: GestationMinAge - 1,
|
||||
},
|
||||
expectedResult: false,
|
||||
expectedError: errors.New("one of the hamster is too young"),
|
||||
expectedError: errors.New("one of the hamster is too young"),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user