aboutsummaryrefslogtreecommitdiff
path: root/logic/dice_test.go
blob: f458708d1ddc709fc75b9de48f2af5e2ebe1bca2 (plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright (c) 2016 Florian Fischer. All rights reserved.
// Use of this source code is governed by a MIT license found in the LICENSE file.

package logic

import "testing"

func TestSum(t *testing.T) {
	d := Dice{1, 1, 1, 2, 6}
	if d.Sum(1) != 3 {
		t.Errorf("Sum(1) of %v should be 3", d)
	}
	d = Dice{1, 1, 1, 2, 6}
	if d.Sum(2) != 2 {
		t.Errorf("Sum(2) of %v should be 2", d)
	}
	d = Dice{1, 1, 1, 2, 6}
	if d.Sum(0) != 11 {
		t.Errorf("Sum(0) of %v should be 11", d)
	}
	d = Dice{1, 1, 1, 2, 6}
	if d.Sum(3) != 0 {
		t.Errorf("Sum(3) of %v should be 0", d)
	}
}

func TestIsThreeOfAKind(t *testing.T) {
	dice := []Dice{{1, 2, 3, 3, 3}, {1, 4, 4, 4, 5}, {2, 2, 2, 3, 6}, {1, 1, 1, 1, 1}}
	for _, d := range dice {
		if !d.IsThreeOfAKind() {
			t.Errorf("%v is three of a kind", d)
		}
	}
	dice = []Dice{{1, 2, 3, 3, 4}, {1, 4, 4, 5, 5}, {1, 2, 2, 3, 6}, {1, 1, 2, 5, 6}}
	for _, d := range dice {
		if d.IsThreeOfAKind() {
			t.Errorf("%v is not three of a kind", d)
		}
	}
}

func TestIsFourOfAKind(t *testing.T) {
	dice := []Dice{{1, 3, 3, 3, 3}, {1, 4, 4, 4, 4}, {2, 2, 2, 2, 6}, {1, 1, 1, 1, 1}}
	for _, d := range dice {
		if !d.IsFourOfAKind() {
			t.Errorf("%v is four of a kind", d)
		}
	}
	dice = []Dice{{1, 2, 3, 3, 4}, {1, 4, 4, 5, 5}, {1, 2, 2, 3, 6}, {1, 1, 2, 5, 6}}
	for _, d := range dice {
		if d.IsFourOfAKind() {
			t.Errorf("%v is not four of a kind", d)
		}
	}
}

func TestIsFullHouse(t *testing.T) {
	dice := []Dice{{1, 1, 3, 3, 3}, {1, 1, 4, 4, 4}, {2, 2, 2, 6, 6}}
	for _, d := range dice {
		if !d.IsFullHouse() {
			t.Errorf("%v is a full house", d)
		}
	}
	dice = []Dice{{1, 2, 3, 3, 4}, {1, 4, 4, 5, 5}, {1, 2, 2, 3, 6}, {1, 1, 2, 5, 6}}
	for _, d := range dice {
		if d.IsFullHouse() {
			t.Errorf("%v is not a full house", d)
		}
	}
}

func TestIsSmallStraight(t *testing.T) {
	dice := []Dice{{1, 2, 3, 4, 6}, {1, 1, 2, 3, 4}, {2, 3, 4, 5, 6}, {1, 2, 3, 3, 4}}
	for _, d := range dice {
		if !d.IsSmallStraight() {
			t.Errorf("%v is a small straight", d)
		}
	}
	dice = []Dice{{1, 2, 3, 3, 5}, {1, 4, 4, 5, 5}, {1, 2, 2, 3, 6}, {1, 1, 2, 5, 6}}
	for _, d := range dice {
		if d.IsSmallStraight() {
			t.Errorf("%v is not a small straight", d)
		}
	}
}

func TestIsLargeStraight(t *testing.T) {
	dice := []Dice{{1, 2, 3, 4, 5}, {2, 3, 4, 5, 6}}
	for _, d := range dice {
		if !d.IsLargeStraight() {
			t.Errorf("%v is a large straight", d)
		}
	}
	dice = []Dice{{1, 2, 3, 3, 4}, {1, 4, 4, 5, 5}, {1, 2, 2, 3, 6}, {1, 1, 2, 5, 6}}
	for _, d := range dice {
		if d.IsLargeStraight() {
			t.Errorf("%v is not a large straight", d)
		}
	}
}

func TestIsYahtzee(t *testing.T) {
	dice := []Dice{{3, 3, 3, 3, 3}, {1, 1, 1, 1, 1}}
	for _, d := range dice {
		if !d.IsYahtzee() {
			t.Errorf("%v is a yahtzee", d)
		}
	}
	dice = []Dice{{1, 2, 3, 3, 4}, {1, 4, 4, 5, 5}, {1, 2, 2, 3, 6}, {1, 1, 2, 5, 6}}
	for _, d := range dice {
		if d.IsYahtzee() {
			t.Errorf("%v is not a yahtzee", d)
		}
	}
}