Yatzy.spec.ts 4.69 KB
Newer Older
1
import assert from 'assert';
2
import Yatzy from './yatzy';
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


describe('Chance', () => {
  it('scores sum of all dice', () => {
    assert.strictEqual(15, new Yatzy(2, 3, 4, 5, 1).chance());
    assert.strictEqual(16, new Yatzy(3, 3, 4, 5, 1).chance());
  });
});

describe('Yatzy', () => {
  it('scores 50', () => {
    assert.strictEqual(0, new Yatzy(6, 6, 6, 6, 3).yatzy());
    assert.strictEqual(50, new Yatzy(4, 4, 4, 4, 4).yatzy());
    assert.strictEqual(50, new Yatzy(6, 6, 6, 6, 6).yatzy());
  });
});

describe('Ones', () => {
  it('score the sum of 1s', () => {
    assert.strictEqual(0, new Yatzy(6, 2, 2, 4, 5).ones());
    assert.strictEqual(1, new Yatzy(1, 2, 3, 4, 5).ones());
    assert.strictEqual(2, new Yatzy(1, 2, 1, 4, 5).ones());
    assert.strictEqual(4, new Yatzy(1, 2, 1, 1, 1).ones());
  });
});

describe('Twos', () => {
  it('score the sum of 2s', () => {
    assert.strictEqual(0, new Yatzy(1, 4, 3, 5, 6).twos());
    assert.strictEqual(4, new Yatzy(1, 2, 3, 2, 6).twos());
    assert.strictEqual(10, new Yatzy(2, 2, 2, 2, 2).twos());
  });
});

describe('Threes', () => {
  it('score the sum of 3s', () => {
39
    assert.strictEqual(0, new Yatzy(1, 2, 4, 2, 4).threes());
40
41
42
43
44
45
46
    assert.strictEqual(6, new Yatzy(1, 2, 3, 2, 3).threes());
    assert.strictEqual(12, new Yatzy(2, 3, 3, 3, 3).threes());
  });
});

describe('Fours', () => {
  it('score the sum of 4s', () => {
47
    assert.strictEqual(0, new Yatzy(1, 2, 3, 5, 5).fours());
48
49
50
51
52
53
54
55
    assert.strictEqual(12, new Yatzy(4, 4, 4, 5, 5).fours());
    assert.strictEqual(8, new Yatzy(4, 4, 5, 5, 5).fours());
    assert.strictEqual(4, new Yatzy(4, 5, 5, 5, 5).fours());
  });
});

describe('Fives', () => {
  it('score the sum of fives', () => {
56
    assert.strictEqual(0, new Yatzy(1, 2, 4, 6, 3).fives());
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
116
117
118
119
120
121
122
123
124
125
126
127
128
    assert.strictEqual(10, new Yatzy(4, 4, 4, 5, 5).fives());
    assert.strictEqual(15, new Yatzy(4, 4, 5, 5, 5).fives());
    assert.strictEqual(20, new Yatzy(4, 5, 5, 5, 5).fives());
  });
});

describe('Sixes', () => {
  it('score the sum of sixes', () => {
    assert.strictEqual(0, new Yatzy(4, 4, 4, 5, 5).sixes());
    assert.strictEqual(6, new Yatzy(4, 4, 6, 5, 5).sixes());
    assert.strictEqual(18, new Yatzy(6, 5, 6, 6, 5).sixes());
  });
});

describe('One pair', () => {
  it('scores the sum of the highest pair', () => {
    assert.strictEqual(0, new Yatzy(3, 4, 1, 5, 6).onePair());
    assert.strictEqual(6, new Yatzy(3, 4, 3, 5, 6).onePair());
    assert.strictEqual(10, new Yatzy(5, 3, 3, 3, 5).onePair());
    assert.strictEqual(12, new Yatzy(5, 3, 6, 6, 5).onePair());
  });
});

describe('Two pair', () => {
  it('scores the sum of the two pairs', () => {
    assert.strictEqual(0, new Yatzy(3, 3, 2, 4, 5).twoPair());
    assert.strictEqual(16, new Yatzy(3, 3, 5, 4, 5).twoPair());
    assert.strictEqual(16, new Yatzy(3, 3, 5, 5, 5).twoPair());
  });
});

describe('Three of a kind', () => {
  it('scores the sum of the three of the kind', () => {
    assert.strictEqual(0, new Yatzy(3, 3, 4, 4, 5).threeOfAKind());
    assert.strictEqual(9, new Yatzy(3, 3, 3, 4, 5).threeOfAKind());
    assert.strictEqual(15, new Yatzy(5, 3, 5, 4, 5).threeOfAKind());
    assert.strictEqual(9, new Yatzy(3, 3, 3, 3, 5).threeOfAKind());
  });
});

describe('Four of a kind', () => {
  it('scores the sum of the four of the kind', () => {
    assert.strictEqual(0, new Yatzy(3, 3, 3, 5, 5).fourOfAKind());
    assert.strictEqual(12, new Yatzy(3, 3, 3, 3, 5).fourOfAKind());
    assert.strictEqual(20, new Yatzy(5, 5, 5, 4, 5).fourOfAKind());
    assert.strictEqual(12, new Yatzy(3, 3, 3, 3, 3).fourOfAKind());
  });
});

describe('Small straight', () => {
  it('scores 15', () => {
    assert.strictEqual(0, new Yatzy(1, 2, 4, 5, 6).smallStraight());
    assert.strictEqual(0, new Yatzy(1, 2, 2, 4, 5).smallStraight());
    assert.strictEqual(0, new Yatzy(2, 3, 4, 5, 6).smallStraight());
    assert.strictEqual(15, new Yatzy(1, 2, 3, 4, 5).smallStraight());
    assert.strictEqual(15, new Yatzy(2, 3, 4, 5, 1).smallStraight());
  });
});

describe('Large straight', () => {
  it('scores 20', () => {
    assert.strictEqual(0, new Yatzy(1, 2, 2, 4, 5).largeStraight());
    assert.strictEqual(0, new Yatzy(1, 2, 3, 4, 5).largeStraight());
    assert.strictEqual(0, new Yatzy(1, 2, 4, 5, 6).largeStraight());
    assert.strictEqual(20, new Yatzy(6, 2, 3, 4, 5).largeStraight());
    assert.strictEqual(20, new Yatzy(2, 3, 4, 5, 6).largeStraight());
  });
});

describe('Full house', () => {
  it('scores the sum of the full house', () => {
    assert.strictEqual(0, new Yatzy(2, 3, 4, 5, 6).fullHouse());
129
    assert.strictEqual(0, new Yatzy(4, 4, 4, 4, 1).fullHouse());
130
131
132
133
    assert.strictEqual(22, new Yatzy(2, 2, 6, 6, 6).fullHouse());
    assert.strictEqual(18, new Yatzy(6, 2, 2, 2, 6).fullHouse());
  });
});