-
Notifications
You must be signed in to change notification settings - Fork 0
/
cards_test.go
88 lines (85 loc) · 1.74 KB
/
cards_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"reflect"
"testing"
)
func TestCard_Check(t *testing.T) {
type args struct {
next Card
}
tests := []struct {
name string
c Card
args args
want bool
}{
{
"same color",
Card{Color: "red", Value: "10"},
args{next: Card{Color: "red", Value: "1"}},
true,
},
{
"same value",
Card{Color: "red", Value: "10"},
args{next: Card{Color: "green", Value: "10"}},
true,
},
{
"not allowed",
Card{Color: "red", Value: "10"},
args{next: Card{Color: "green", Value: "5"}},
false,
},
{
"wish card",
Card{Color: "red", Value: "10"},
args{next: Card{Color: "", WishColor: true}},
true,
},
{
"nach wish card",
Card{Color: "", Value: "", WishColor: true},
args{next: Card{Color: "green", Value: "5", WishColor: false}},
true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.c.Check(tt.args.next); got != tt.want {
t.Errorf("Card.Check() = %v, want %v", got, tt.want)
}
})
}
}
func TestCardStackMethods(t *testing.T) {
cards := []Card{
Card{ID: "1"},
Card{ID: "2"},
Card{ID: "3"},
Card{ID: "4"},
}
// Add all the cards to the stack
cs := CardStack{}
for _, c := range cards {
cs.push(c)
}
// check the cards inside the stack
if !reflect.DeepEqual(cards, cs.Cards) {
t.Errorf("Slices should be equal:\ngot:\n%v\nwant:\n%v", cs.Cards, cards)
}
// take the last card of the stack
got := cs.pop()
if got != cards[3] {
t.Errorf("pop(): got:%v\nwant:%v", got, cards[3])
}
// check the size of the stack
if cs.len() != 3 {
t.Errorf("Size of the stack is %d\nwant: 3", cs.len())
}
// check the last card with peek
got = cs.peek()
if got != cards[2] {
t.Errorf("peek(): got:%v\nwant:%v", got, cards[3])
}
}