Skip to content

Commit

Permalink
test: add tests to gametake
Browse files Browse the repository at this point in the history
  • Loading branch information
PapePathe committed Oct 10, 2023
1 parent 39595f6 commit f8c80ef
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gametake/carreau.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (t Carreau) Name() string {
}

func (t Carreau) GetValue() int {
return 1
return 2
}

func (t Carreau) EvaluateHand(cards [5]cards.Card) (entry GameTakeEntry) {
Expand Down
2 changes: 1 addition & 1 deletion gametake/carreau_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestGetValue(t *testing.T) {
assert.Equal(t, 1, CARREAU.GetValue())
assert.Equal(t, 2, CARREAU.GetValue())
}

func TestGetName(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions gametake/pique.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (

var PIQUE GameTake = Pique{}

type Pique struct {
value int32 `default:"2"`
}
type Pique struct{}

func (t Pique) Name() string {
return "Pique"
Expand Down
95 changes: 95 additions & 0 deletions gametake/pique_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package gametake

import (
"testing"

"github.com/stretchr/testify/assert"
"pathe.co/zinx/pkg/cards"
)

type evaluateCardTestCasesPIQUE struct {
card cards.Card
name string
value int
}

func TestEvaluateCardPIQUE(t *testing.T) {
tc := []evaluateCardTestCasesPIQUE{
evaluateCardTestCasesPIQUE{cards.ValetCarreau, "Valet carreau should be 2", 2},
evaluateCardTestCasesPIQUE{cards.NeufCarreau, "Neuf carreau should be 0", 0},
evaluateCardTestCasesPIQUE{cards.AsCarreau, "As carreau should be 11", 11},
evaluateCardTestCasesPIQUE{cards.DixCarreau, "Dix carreau should be 10", 10},
evaluateCardTestCasesPIQUE{cards.RoiCarreau, "Roi carreau should be 4", 4},
evaluateCardTestCasesPIQUE{cards.DameCarreau, "Dame carreau should be 3", 3},
evaluateCardTestCasesPIQUE{cards.HuitCarreau, "Huit carreau should be 0", 0},
evaluateCardTestCasesPIQUE{cards.SeptCarreau, "Sept carreau should be 0", 0},

evaluateCardTestCasesPIQUE{cards.ValetCoeur, "Valet coeur should be 2", 2},
evaluateCardTestCasesPIQUE{cards.NeufCoeur, "Neuf coeur should be 0", 0},
evaluateCardTestCasesPIQUE{cards.AsCoeur, "As coeur should be 11", 11},
evaluateCardTestCasesPIQUE{cards.DixCoeur, "Dix coeur should be 10", 10},
evaluateCardTestCasesPIQUE{cards.RoiCoeur, "Roi coeur should be 4", 4},
evaluateCardTestCasesPIQUE{cards.DameCoeur, "Dame coeur should be 3", 3},
evaluateCardTestCasesPIQUE{cards.HuitCoeur, "Huit coeur should be 0", 0},
evaluateCardTestCasesPIQUE{cards.SeptCoeur, "Sept coeur should be 0", 0},

evaluateCardTestCasesPIQUE{cards.ValetTrefle, "Valet trefle should be 2", 2},
evaluateCardTestCasesPIQUE{cards.NeufTrefle, "Neuf trefle should be 0", 0},
evaluateCardTestCasesPIQUE{cards.AsTrefle, "As trefle should be 11", 11},
evaluateCardTestCasesPIQUE{cards.DixTrefle, "Dix trefle should be 10", 10},
evaluateCardTestCasesPIQUE{cards.RoiTrefle, "Roi trefle should be 4", 4},
evaluateCardTestCasesPIQUE{cards.DameTrefle, "Dame trefle should be 3", 3},
evaluateCardTestCasesPIQUE{cards.HuitTrefle, "Huit trefle should be 0", 0},
evaluateCardTestCasesPIQUE{cards.SeptTrefle, "Sept trefle should be 0", 0},

evaluateCardTestCasesPIQUE{cards.ValetPique, "Valet pique should be 2", 20},
evaluateCardTestCasesPIQUE{cards.NeufPique, "Neuf pique should be 14", 14},
evaluateCardTestCasesPIQUE{cards.AsPique, "As pique should be 11", 11},
evaluateCardTestCasesPIQUE{cards.DixPique, "Dix pique should be 10", 10},
evaluateCardTestCasesPIQUE{cards.RoiPique, "Roi pique should be 4", 4},
evaluateCardTestCasesPIQUE{cards.DamePique, "Dame pique should be 3", 3},
evaluateCardTestCasesPIQUE{cards.HuitPique, "Huit pique should be 0", 0},
evaluateCardTestCasesPIQUE{cards.SeptPique, "Sept pique should be 0", 0},
}

for _, test := range tc {
t.Run(test.name, func(t *testing.T) {
pique := Pique{}
result := pique.EvaluateCard(test.card)
assert.Equal(t, result, test.value)
})
}
}

type testGreaterThanCasesPIQUE struct {
name string
take GameTake
expected bool
}

func TestGreaterThanPIQUE(t *testing.T) {
tc := []testGreaterThanCasesPIQUE{
testGreaterThanCasesPIQUE{"Coeur is greater than tout", TOUT, false},
testGreaterThanCasesPIQUE{"Coeur is greater than cent", CENT, false},
testGreaterThanCasesPIQUE{"Coeur is greater than pique", COEUR, true},
testGreaterThanCasesPIQUE{"Coeur is greater than carreau", CARREAU, true},
testGreaterThanCasesPIQUE{"Coeur is greater than trefle", TREFLE, true},
testGreaterThanCasesPIQUE{"Coeur is greater than passe", PASSE, true},
}
for _, test := range tc {
t.Run(test.name, func(t *testing.T) {
result := PIQUE.GreaterThan(test.take)
assert.Equal(t, result, test.expected)
})
}
}

func TestGetValuePIQUE(t *testing.T) {
result := PIQUE.GetValue()
assert.Equal(t, result, 4)
}

func TestNamePIQUE(t *testing.T) {
result := PIQUE.Name()
assert.Equal(t, result, "Pique")
}
2 changes: 1 addition & 1 deletion gametake/trefle.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (t Trefle) GreaterThan(other GameTake) bool {
}

func (t Trefle) GetValue() int {
return 0
return 1
}

func (t Trefle) EvaluateHand(cards [5]cards.Card) (entry GameTakeEntry) {
Expand Down
95 changes: 95 additions & 0 deletions gametake/trefle_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package gametake

import (
"testing"

"github.com/stretchr/testify/assert"
"pathe.co/zinx/pkg/cards"
)

type evaluateCardTestCasesTREFLE struct {
card cards.Card
name string
value int
}

func TestEvaluateCardTREFLE(t *testing.T) {
tc := []evaluateCardTestCasesTREFLE{
evaluateCardTestCasesTREFLE{cards.ValetCarreau, "Valet carreau should be 2", 2},
evaluateCardTestCasesTREFLE{cards.NeufCarreau, "Neuf carreau should be 0", 0},
evaluateCardTestCasesTREFLE{cards.AsCarreau, "As carreau should be 11", 11},
evaluateCardTestCasesTREFLE{cards.DixCarreau, "Dix carreau should be 10", 10},
evaluateCardTestCasesTREFLE{cards.RoiCarreau, "Roi carreau should be 4", 4},
evaluateCardTestCasesTREFLE{cards.DameCarreau, "Dame carreau should be 3", 3},
evaluateCardTestCasesTREFLE{cards.HuitCarreau, "Huit carreau should be 0", 0},
evaluateCardTestCasesTREFLE{cards.SeptCarreau, "Sept carreau should be 0", 0},

evaluateCardTestCasesTREFLE{cards.ValetCoeur, "Valet coeur should be 2", 2},
evaluateCardTestCasesTREFLE{cards.NeufCoeur, "Neuf coeur should be 0", 0},
evaluateCardTestCasesTREFLE{cards.AsCoeur, "As coeur should be 11", 11},
evaluateCardTestCasesTREFLE{cards.DixCoeur, "Dix coeur should be 10", 10},
evaluateCardTestCasesTREFLE{cards.RoiCoeur, "Roi coeur should be 4", 4},
evaluateCardTestCasesTREFLE{cards.DameCoeur, "Dame coeur should be 3", 3},
evaluateCardTestCasesTREFLE{cards.HuitCoeur, "Huit coeur should be 0", 0},
evaluateCardTestCasesTREFLE{cards.SeptCoeur, "Sept coeur should be 0", 0},

evaluateCardTestCasesTREFLE{cards.ValetTrefle, "Valet trefle should be 20", 20},
evaluateCardTestCasesTREFLE{cards.NeufTrefle, "Neuf trefle should be 14", 14},
evaluateCardTestCasesTREFLE{cards.AsTrefle, "As trefle should be 11", 11},
evaluateCardTestCasesTREFLE{cards.DixTrefle, "Dix trefle should be 10", 10},
evaluateCardTestCasesTREFLE{cards.RoiTrefle, "Roi trefle should be 4", 4},
evaluateCardTestCasesTREFLE{cards.DameTrefle, "Dame trefle should be 3", 3},
evaluateCardTestCasesTREFLE{cards.HuitTrefle, "Huit trefle should be 0", 0},
evaluateCardTestCasesTREFLE{cards.SeptTrefle, "Sept trefle should be 0", 0},

evaluateCardTestCasesTREFLE{cards.ValetPique, "Valet pique should be 2", 2},
evaluateCardTestCasesTREFLE{cards.NeufPique, "Neuf pique should be 0", 0},
evaluateCardTestCasesTREFLE{cards.AsPique, "As pique should be 11", 11},
evaluateCardTestCasesTREFLE{cards.DixPique, "Dix pique should be 10", 10},
evaluateCardTestCasesTREFLE{cards.RoiPique, "Roi pique should be 4", 4},
evaluateCardTestCasesTREFLE{cards.DamePique, "Dame pique should be 3", 3},
evaluateCardTestCasesTREFLE{cards.HuitPique, "Huit pique should be 0", 0},
evaluateCardTestCasesTREFLE{cards.SeptPique, "Sept pique should be 0", 0},
}

for _, test := range tc {
t.Run(test.name, func(t *testing.T) {
trefle := Trefle{}
result := trefle.EvaluateCard(test.card)
assert.Equal(t, result, test.value)
})
}
}

type testGreaterThanCasesTREFLE struct {
name string
take GameTake
expected bool
}

func TestGreaterThanTREFLE(t *testing.T) {
tc := []testGreaterThanCasesTREFLE{
testGreaterThanCasesTREFLE{"Trefle is greater than tout", TOUT, false},
testGreaterThanCasesTREFLE{"Trefle is greater than cent", CENT, false},
testGreaterThanCasesTREFLE{"Trefle is greater than pique", PIQUE, false},
testGreaterThanCasesTREFLE{"Trefle is greater than pique", COEUR, false},
testGreaterThanCasesTREFLE{"Trefle is greater than carreau", CARREAU, false},
testGreaterThanCasesTREFLE{"Trefle is greater than passe", PASSE, true},
}
for _, test := range tc {
t.Run(test.name, func(t *testing.T) {
result := TREFLE.GreaterThan(test.take)
assert.Equal(t, result, test.expected)
})
}
}

func TestGetValueTREFLE(t *testing.T) {
result := TREFLE.GetValue()
assert.Equal(t, result, 1)
}

func TestNameTREFLE(t *testing.T) {
result := TREFLE.Name()
assert.Equal(t, result, "Trefle")
}

0 comments on commit f8c80ef

Please sign in to comment.