-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
212 lines (186 loc) · 5.48 KB
/
test.ts
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import {
assert,
assertArrayIncludes,
assertEquals,
assertExists,
assertThrows,
} from "jsr:@std/[email protected]";
import { GachaMachine, LimitedGachaMachine, roll, rollDie } from "./mod.ts";
import { unbiasedCoin } from "./src/coin.ts";
const testData = [
{ result: "SSR cool character", chance: 1 },
{ result: "Kinda rare character", chance: 3 },
{ result: "Mob character", chance: 5 },
{ result: "Mob character", chance: 5 },
{ result: "Mob character", chance: 5 },
];
Deno.test({
name: "V4: Is GachaMachine defined?",
fn() {
const machine = new GachaMachine(testData);
assertExists(machine);
},
});
Deno.test({
name: "V3: Is GachaMachine defined?",
fn() {
const machine = new LimitedGachaMachine(testData);
assertExists(machine);
},
});
Deno.test({
name: `V3: Roll 3 unique items from a collection of 5 items`,
fn() {
const machine = new LimitedGachaMachine(testData);
const res = machine.get(3);
assertExists(res);
},
});
Deno.test({
name: `V3: Roll 5 unique items from a collection of 5 items`,
fn() {
const machine = new LimitedGachaMachine(testData);
const res = machine.get(5);
assertArrayIncludes(res, [
"SSR cool character",
"Kinda rare character",
"Mob character",
"Mob character",
"Mob character",
]);
},
});
Deno.test({
name: `V3: Roll 7 unique items from a collection of 5 items (throw error)`,
fn() {
const machine = new LimitedGachaMachine(testData);
assertThrows(() => machine.get(7));
},
});
Deno.test({
name: `V4: Roll 7 non-unique items from a collection of 5 items`,
fn() {
const machine = new GachaMachine(testData);
const res = machine.get(7);
assertEquals(res.length, 7);
},
});
Deno.test({
name:
`V4: Machine can be updated by just setting machine.items after initialization.`,
fn() {
const machine = new GachaMachine(testData);
const machine2 = new GachaMachine(testData.slice(0, 3));
machine.items = testData.slice(0, 3);
assertEquals(machine.items, machine2.items, "Items are not equal.");
// assertEquals(machine.tiers, machine2.tiers, "Tiers are not equal.");
// assertEquals(machine.totalChance, machine2.totalChance, "totalChance are not equal.");
// assertEquals(machine.maxTier, machine2.maxTier, "maxTier are not equal.");
// assertEquals(machine.pool, machine2.pool, "pool are not equal.");
},
});
Deno.test({
name:
`V3: Machine can be updated by just setting machine.items after initialization.`,
fn() {
const machine = new LimitedGachaMachine(testData);
const machine2 = new LimitedGachaMachine(testData.slice(0, 3));
machine.items = testData.slice(0, 3);
assertEquals(machine.items, machine2.items, "Items are not equal.");
// assertEquals(machine.tiers, machine2.tiers, "Tiers are not equal.");
// assertEquals(machine.totalChance, machine2.totalChance, "totalChance are not equal.");
// assertEquals(machine.maxTier, machine2.maxTier, "maxTier are not equal.");
// assertEquals(machine.pool, machine2.pool, "pool are not equal.");
},
});
Deno.test({
name:
`Single Roll: Roll 1 items from a collection of 5 items using the roll() method`,
fn() {
const res = roll(testData);
console.log(`Rolled: `, res);
assertExists(res);
},
});
Deno.test({
name:
`Single Roll: Roll 1 items from a collection of 5 items using the roll() method (overload)`,
fn() {
const res = roll(
testData.map((x) => x.result),
testData.map((x) => x.chance),
);
console.log(`Rolled: `, res);
assertExists(res);
},
});
Deno.test({
name: `Roll a simple die once`,
fn() {
const res = rollDie();
console.log(`Die Rolled: `, res);
assert(typeof res === "number" && res >= 1 && res <= 6);
},
});
Deno.test({
name: `Roll 3 simple dice`,
fn() {
const res = rollDie({ times: 3, face: 6, separate: true });
console.log(`Die Rolled: `, res);
assert(Array.isArray(res) && res.every((x) => x >= 1 && x <= 6));
},
});
Deno.test({
name: `Roll 3 simple dice and sum all rolls`,
fn() {
const res = rollDie({ times: 3, face: 6 });
console.log(`Die Rolled: `, res);
assert(typeof res === "number" && res >= 3 && res <= 18);
},
});
Deno.test({
name: `Roll 6d9 and sum all rolls`,
fn() {
const res = rollDie("6d9");
console.log(`Die Rolled: `, res);
assert(typeof res === "number" && res >= 6 && res <= 54);
},
});
Deno.test({
name: `Roll 6d9 with a +12 modifier`,
fn() {
const res = rollDie("6d9+12");
console.log(`Die Rolled: `, res);
assert(typeof res === "number" && res >= 18 && res <= 66);
},
});
Deno.test({
name: `Attempt to roll 6dd (should throw)`,
fn() {
assertThrows(() => rollDie("6dd"));
},
});
Deno.test({
name: `Toss an unbiased coin (should return ["0"] or ["1"])`,
fn() {
const res = unbiasedCoin();
assert(res.length === 1 && res[0] === "0" || res[0] === "1");
},
});
Deno.test({
name: `Toss N unbiased coins (should return an array of "H" or "T")`,
fn() {
const res = unbiasedCoin();
assert(res.length === 1 && res.every((x) => x === "0" || x === "1"));
},
});
/*
Deno.test({
name: `${sortedTestData[0].chance} in ${testData.reduce((acc, val) => acc + val.chance, 0)} rolls return a ${sortedTestData[0].result}?`,
fn() {
const machine = new GachaMachine(testData);
const res = machine.get(testData.reduce((acc, val) => acc + val.chance, 0));
assertArrayIncludes(res, sortedTestData[0].result)
},
});
*/