-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
57 lines (44 loc) · 1.34 KB
/
main_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
package main
import (
"testing"
)
func TestParse(t *testing.T) {
input := []string{
"Hit Points: 1",
"Damage: 2",
"Armor: 3",
}
gotC := parse(input)
wantC := contender{hitPoints: 1, damage: 2, armor: 3}
if gotC != wantC {
t.Errorf("got %+v, want %+v", gotC, wantC)
}
}
func TestPlayerWins(t *testing.T) {
t.Run("Example from description", func(t *testing.T) {
player := contender{hitPoints: 8, damage: 5, armor: 5}
enemy := contender{hitPoints: 12, damage: 7, armor: 2}
if got, want := playerWins(&player, &enemy), true; got != want {
t.Errorf("got %t, want %t", got, want)
}
if got, want := player.hitPoints, 2; got != want {
t.Errorf("player has %d hit points, want %d", got, want)
}
if got, want := enemy.hitPoints, 0; got != want {
t.Errorf("enemy has %d hit points, want %d", got, want)
}
})
t.Run("Armor equal to damage", func(t *testing.T) {
player := contender{hitPoints: 8, damage: 5, armor: 7}
enemy := contender{hitPoints: 12, damage: 7, armor: 2}
if got, want := playerWins(&player, &enemy), true; got != want {
t.Errorf("got %t, want %t", got, want)
}
if got, want := player.hitPoints, 5; got != want {
t.Errorf("player has %d hit points, want %d", got, want)
}
if got, want := enemy.hitPoints, 0; got != want {
t.Errorf("enemy has %d hit points, want %d", got, want)
}
})
}