-
Notifications
You must be signed in to change notification settings - Fork 1
/
dnd-character.spec.js
117 lines (93 loc) · 3.51 KB
/
dnd-character.spec.js
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
116
117
import { Character, abilityModifier } from './dnd-character';
describe('D&D Character', () => {
describe('Ability modifier', () => {
test('ability modifier for score 3 is -4', () => {
expect(abilityModifier(3)).toEqual(-4);
});
test('ability modifier for score 4 is -3', () => {
expect(abilityModifier(4)).toEqual(-3);
});
test('ability modifier for score 5 is -3', () => {
expect(abilityModifier(5)).toEqual(-3);
});
test('ability modifier for score 6 is -2', () => {
expect(abilityModifier(6)).toEqual(-2);
});
test('ability modifier for score 7 is -2', () => {
expect(abilityModifier(7)).toEqual(-2);
});
test('ability modifier for score 8 is -1', () => {
expect(abilityModifier(8)).toEqual(-1);
});
test('ability modifier for score 9 is -1', () => {
expect(abilityModifier(9)).toEqual(-1);
});
test('ability modifier for score 10 is 0', () => {
expect(abilityModifier(10)).toEqual(0);
});
test('ability modifier for score 11 is 0', () => {
expect(abilityModifier(11)).toEqual(0);
});
test('ability modifier for score 12 is 1', () => {
expect(abilityModifier(12)).toEqual(1);
});
test('ability modifier for score 13 is 1', () => {
expect(abilityModifier(13)).toEqual(1);
});
test('ability modifier for score 14 is 2', () => {
expect(abilityModifier(14)).toEqual(2);
});
test('ability modifier for score 15 is 2', () => {
expect(abilityModifier(15)).toEqual(2);
});
test('ability modifier for score 16 is 3', () => {
expect(abilityModifier(16)).toEqual(3);
});
test('ability modifier for score 17 is 3', () => {
expect(abilityModifier(17)).toEqual(3);
});
test('ability modifier for score 18 is 4', () => {
expect(abilityModifier(18)).toEqual(4);
});
test('ability score less than 3 throws error', () => {
expect(() => abilityModifier(2)).toThrow(
new Error('Ability scores must be at least 3')
);
});
test('ability score greater than 18 throws error', () => {
expect(() => abilityModifier(19)).toThrow(
new Error('Ability scores can be at most 18')
);
});
});
describe('Ability scores calculated properly', () => {
test('ability within range', () => {
expect(Character.rollAbility()).toBeLessThanOrEqual(18);
expect(Character.rollAbility()).toBeGreaterThanOrEqual(3);
});
test('ability scores only calculated once', () => {
const Drizzt = new Character();
expect(Drizzt.strength).toEqual(Drizzt.strength);
});
});
describe('Random character is valid', () => {
test('character is valid', () => {
const Drizzt = new Character();
expect(Drizzt.strength).toBeLessThanOrEqual(18);
expect(Drizzt.strength).toBeGreaterThanOrEqual(3);
expect(Drizzt.dexterity).toBeLessThanOrEqual(18);
expect(Drizzt.dexterity).toBeGreaterThanOrEqual(3);
expect(Drizzt.constitution).toBeLessThanOrEqual(18);
expect(Drizzt.constitution).toBeGreaterThanOrEqual(3);
expect(Drizzt.intelligence).toBeLessThanOrEqual(18);
expect(Drizzt.intelligence).toBeGreaterThanOrEqual(3);
expect(Drizzt.wisdom).toBeLessThanOrEqual(18);
expect(Drizzt.wisdom).toBeGreaterThanOrEqual(3);
expect(Drizzt.charisma).toBeLessThanOrEqual(18);
expect(Drizzt.charisma).toBeGreaterThanOrEqual(3);
expect(Drizzt.hitpoints).toEqual(
10 + abilityModifier(Drizzt.constitution)
);
});
});
});