@dicelette/core 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/index.ts
ADDED
package/package.json
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dicelette/core",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.3",
|
4
4
|
"description": "Core library for the Dicelette Discord bot",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
7
7
|
"url": "https://github.com/Dicelette/core.git"
|
8
8
|
},
|
9
|
-
"types": "
|
9
|
+
"types": "@types",
|
10
|
+
"main": "index.ts",
|
10
11
|
"keywords": [
|
11
12
|
"discord",
|
12
13
|
"roll",
|
@@ -27,7 +28,9 @@
|
|
27
28
|
"remove-accents": "^0.5.0",
|
28
29
|
"ts-dedent": "^2.2.0"
|
29
30
|
},
|
30
|
-
"devDependencies": {
|
31
|
+
"devDependencies": {
|
32
|
+
"tslib": "^2.6.2"
|
33
|
+
},
|
31
34
|
"scripts": {
|
32
35
|
"test": "jest"
|
33
36
|
}
|
@@ -1,21 +1,20 @@
|
|
1
1
|
// FILEPATH: /c:/Users/simonettili/Documents/Github/discord-dicelette/src/utils/verify_template.test.ts
|
2
|
-
import
|
3
|
-
|
4
|
-
import { diceRandomParse,evalCombinaison, generateRandomStat,testCombinaison, testDamageRoll, verifyTemplateValue } from "../core/verify_template";
|
2
|
+
import * as core from "../core";
|
3
|
+
|
5
4
|
|
6
5
|
describe("verify_template", () => {
|
7
6
|
describe("evalCombinaison", () => {
|
8
7
|
it("should evaluate the combination correctly", () => {
|
9
8
|
const combinaison = { stat1: "stat2 + 3" };
|
10
9
|
const stats = { stat2: 2 };
|
11
|
-
const result = evalCombinaison(combinaison, stats);
|
10
|
+
const result = core.evalCombinaison(combinaison, stats);
|
12
11
|
expect(result).toEqual({ stat1: 5 });
|
13
12
|
});
|
14
13
|
|
15
14
|
it("should throw an error for invalid formula", () => {
|
16
15
|
const combinaison = { stat1: "stat2 + " };
|
17
16
|
const stats = { stat2: 2 };
|
18
|
-
expect(() => evalCombinaison(combinaison, stats)).toThrow();
|
17
|
+
expect(() => core.evalCombinaison(combinaison, stats)).toThrow();
|
19
18
|
});
|
20
19
|
});
|
21
20
|
|
@@ -25,7 +24,7 @@ describe("verify_template", () => {
|
|
25
24
|
const total = 100;
|
26
25
|
const max = 50;
|
27
26
|
const min = 10;
|
28
|
-
const result = generateRandomStat(total, max, min);
|
27
|
+
const result = core.generateRandomStat(total, max, min);
|
29
28
|
expect(result).toBeGreaterThanOrEqual(min);
|
30
29
|
expect(result).toBeLessThanOrEqual(max);
|
31
30
|
expect(result).toBeLessThanOrEqual(total);
|
@@ -34,7 +33,7 @@ describe("verify_template", () => {
|
|
34
33
|
it ("should verify with no max", () => {
|
35
34
|
const total = 100;
|
36
35
|
const min = 1;
|
37
|
-
const result = generateRandomStat(total, undefined, min);
|
36
|
+
const result = core.generateRandomStat(total, undefined, min);
|
38
37
|
expect(result).toBeGreaterThanOrEqual(min);
|
39
38
|
expect(result).toBeLessThanOrEqual(total);
|
40
39
|
});
|
@@ -42,14 +41,14 @@ describe("verify_template", () => {
|
|
42
41
|
it ("should verify with no min", () => {
|
43
42
|
const total = 100;
|
44
43
|
const max = 99;
|
45
|
-
const result = generateRandomStat(total, max, undefined);
|
44
|
+
const result = core.generateRandomStat(total, max, undefined);
|
46
45
|
expect(result).toBeGreaterThanOrEqual(0);
|
47
46
|
expect(result).toBeLessThanOrEqual(max);
|
48
47
|
});
|
49
48
|
|
50
49
|
it ("should verify with no min and max", () => {
|
51
50
|
const total = 100;
|
52
|
-
const result = generateRandomStat(total, undefined, undefined);
|
51
|
+
const result = core.generateRandomStat(total, undefined, undefined);
|
53
52
|
expect(result).toBeGreaterThanOrEqual(0);
|
54
53
|
expect(result).toBeLessThanOrEqual(total);
|
55
54
|
});
|
@@ -57,13 +56,13 @@ describe("verify_template", () => {
|
|
57
56
|
it ("should verify with no total", () => {
|
58
57
|
const max = 99;
|
59
58
|
const min = 1;
|
60
|
-
const result = generateRandomStat(undefined, max, min);
|
59
|
+
const result = core.generateRandomStat(undefined, max, min);
|
61
60
|
expect(result).toBeGreaterThanOrEqual(min);
|
62
61
|
expect(result).toBeLessThanOrEqual(max);
|
63
62
|
});
|
64
63
|
|
65
64
|
it ("should verify with no total, min and max", () => {
|
66
|
-
const result = generateRandomStat(undefined, undefined, undefined);
|
65
|
+
const result = core.generateRandomStat(undefined, undefined, undefined);
|
67
66
|
expect(result).toBeGreaterThanOrEqual(0);
|
68
67
|
expect(result).toBeLessThanOrEqual(100);
|
69
68
|
});
|
@@ -79,7 +78,7 @@ describe("verify_template", () => {
|
|
79
78
|
"piercing": "1d6+2",
|
80
79
|
}
|
81
80
|
};
|
82
|
-
const result = verifyTemplateValue(template);
|
81
|
+
const result = core.verifyTemplateValue(template);
|
83
82
|
expect(result).toEqual(template);
|
84
83
|
});
|
85
84
|
|
@@ -90,7 +89,7 @@ describe("verify_template", () => {
|
|
90
89
|
"piercing": "1d6+2>20",
|
91
90
|
}
|
92
91
|
};
|
93
|
-
const result = verifyTemplateValue(template);
|
92
|
+
const result = core.verifyTemplateValue(template);
|
94
93
|
expect(result).toEqual(template);
|
95
94
|
});
|
96
95
|
|
@@ -99,74 +98,74 @@ describe("verify_template", () => {
|
|
99
98
|
statistics: { stat1: { max: 10, min: 1, combinaison: "stat2 + 3" } },
|
100
99
|
diceType: "invalid",
|
101
100
|
};
|
102
|
-
expect(() => verifyTemplateValue(template)).toThrow();
|
101
|
+
expect(() => core.verifyTemplateValue(template)).toThrow();
|
103
102
|
});
|
104
103
|
});
|
105
104
|
|
106
105
|
describe("combinaison", () => {
|
107
106
|
// Add more tests for different scenarios
|
108
107
|
it("should throw an error because they are no stat2", () => {
|
109
|
-
const template: StatisticalTemplate = {
|
108
|
+
const template: core.StatisticalTemplate = {
|
110
109
|
statistics: { stat1: { max: 10, min: 1, combinaison: "stat2 + 3" } },
|
111
110
|
diceType: "d6",
|
112
111
|
};
|
113
|
-
expect(() => testCombinaison(template)).toThrow();
|
112
|
+
expect(() => core.testCombinaison(template)).toThrow();
|
114
113
|
});
|
115
114
|
it("validate formula for dice", () => {
|
116
|
-
const template: StatisticalTemplate = {
|
115
|
+
const template: core.StatisticalTemplate = {
|
117
116
|
statistics: { stat1: { max: 10, min: 1, combinaison: "stat2 + 3" } },
|
118
117
|
diceType: "d6+{{$}}>20",
|
119
118
|
};
|
120
|
-
expect(() => testCombinaison(template)).toThrow();
|
119
|
+
expect(() => core.testCombinaison(template)).toThrow();
|
121
120
|
});
|
122
121
|
it("validate formula for dice", () => {
|
123
|
-
const template: StatisticalTemplate = {
|
122
|
+
const template: core.StatisticalTemplate = {
|
124
123
|
statistics: { stat1: { max: 10, min: 1, combinaison: "stat2 + 3" } },
|
125
124
|
diceType: "d6+5>{{$}}",
|
126
125
|
};
|
127
|
-
expect(() => testCombinaison(template)).toThrow();
|
126
|
+
expect(() => core.testCombinaison(template)).toThrow();
|
128
127
|
});
|
129
128
|
|
130
129
|
|
131
130
|
|
132
131
|
|
133
132
|
it("create combinaison dice formula for skill dice with statistic", () => {
|
134
|
-
const testTemplate: StatisticalTemplate = {
|
133
|
+
const testTemplate: core.StatisticalTemplate = {
|
135
134
|
statistics: { stat1: { max: 10, min: 1 } },
|
136
135
|
diceType: "1d20",
|
137
136
|
damage: {
|
138
137
|
"piercing": "1d6 + stat1>stat1",
|
139
138
|
}
|
140
139
|
};
|
141
|
-
const expectedFormula = diceRandomParse("1d20 + {{ceil((stat1-10)/2)}}>stat1", testTemplate);
|
140
|
+
const expectedFormula = core.diceRandomParse("1d20 + {{ceil((stat1-10)/2)}}>stat1", testTemplate);
|
142
141
|
expect(expectedFormula).toEqual(expectedFormula);
|
143
142
|
});
|
144
143
|
it("Test a roll with a combinaison on the dice", () => {
|
145
|
-
const template: StatisticalTemplate = {
|
144
|
+
const template: core.StatisticalTemplate = {
|
146
145
|
statistics: { stat1: { max: 10, min: 1, combinaison: "stat2 + 3" } },
|
147
146
|
diceType: "1d20",
|
148
147
|
damage: {
|
149
148
|
"piercing": "1d20stat1*2>stat1",
|
150
149
|
}
|
151
150
|
};
|
152
|
-
expect(() => testDamageRoll(template)).not.toThrow();
|
151
|
+
expect(() => core.testDamageRoll(template)).not.toThrow();
|
153
152
|
});
|
154
153
|
it("Test a roll with a combinaison on the dice and accents", () => {
|
155
|
-
const template: StatisticalTemplate = {
|
154
|
+
const template: core.StatisticalTemplate = {
|
156
155
|
statistics: { éducation: { max: 10, min: 1 } },
|
157
156
|
diceType: "1d20",
|
158
157
|
damage: {
|
159
158
|
"piercing": "1déducation>20",
|
160
159
|
}
|
161
160
|
};
|
162
|
-
expect(() => testDamageRoll(template)).not.toThrow();
|
161
|
+
expect(() => core.testDamageRoll(template)).not.toThrow();
|
163
162
|
});
|
164
163
|
});
|
165
164
|
describe("roll_string_creation", () => {
|
166
165
|
it("creating roll dice with formula", () => {
|
167
166
|
const dice = "1d20+$>20";
|
168
167
|
const userStat = 10;
|
169
|
-
const calculation = replaceFormulaInDice(dice.replaceAll("$", userStat.toString()));
|
168
|
+
const calculation = core.replaceFormulaInDice(dice.replaceAll("$", userStat.toString()));
|
170
169
|
const formula = `${calculation} coucou`;
|
171
170
|
const expectedFormula = "1d20+10>20 coucou";
|
172
171
|
expect(formula).toEqual(expectedFormula);
|
@@ -174,7 +173,7 @@ describe("verify_template", () => {
|
|
174
173
|
it("creating roll dice with success formula", () => {
|
175
174
|
const dice = "1d20+5>{{$*2}}";
|
176
175
|
const userStat = 10;
|
177
|
-
const calculation = replaceFormulaInDice(dice.replaceAll("$", userStat.toString()));
|
176
|
+
const calculation = core.replaceFormulaInDice(dice.replaceAll("$", userStat.toString()));
|
178
177
|
const formula = `${calculation} coucou`;
|
179
178
|
const expectedFormula = "1d20+5>20 coucou";
|
180
179
|
expect(formula).toEqual(expectedFormula);
|
@@ -182,7 +181,7 @@ describe("verify_template", () => {
|
|
182
181
|
it("creating roll dice with complicated formula", () => {
|
183
182
|
const dice = "1d20+{{ceil((10-$)/2)}}>20";
|
184
183
|
const userStat = 5;
|
185
|
-
const calculation = replaceFormulaInDice(dice.replaceAll("$", userStat.toString()));
|
184
|
+
const calculation = core.replaceFormulaInDice(dice.replaceAll("$", userStat.toString()));
|
186
185
|
const formula = `${calculation} coucou`;
|
187
186
|
const expectedFormula = "1d20+3>20 coucou";
|
188
187
|
expect(formula).toEqual(expectedFormula);
|
@@ -190,7 +189,7 @@ describe("verify_template", () => {
|
|
190
189
|
it("creating roll dice with negative formula", () => {
|
191
190
|
const dice = "1d20+{{ceil(($-10)/2)}}>20";
|
192
191
|
const userStat = 5;
|
193
|
-
const calculation = replaceFormulaInDice(dice.replaceAll("$", userStat.toString()));
|
192
|
+
const calculation = core.replaceFormulaInDice(dice.replaceAll("$", userStat.toString()));
|
194
193
|
const expectedFormula = "1d20-2>20";
|
195
194
|
expect(calculation).toEqual(expectedFormula);
|
196
195
|
});
|
@@ -202,7 +201,7 @@ describe("verify_template", () => {
|
|
202
201
|
stat1: 5,
|
203
202
|
stat2: 10
|
204
203
|
};
|
205
|
-
dice = generateStatsDice(dice, userStat);
|
204
|
+
dice = core.generateStatsDice(dice, userStat);
|
206
205
|
const formula = `${dice} cc`;
|
207
206
|
const expectedFormula = "1d5>20 cc";
|
208
207
|
expect(formula).toEqual(expectedFormula);
|
@@ -213,7 +212,7 @@ describe("verify_template", () => {
|
|
213
212
|
stat1: 10,
|
214
213
|
stat2: 10
|
215
214
|
};
|
216
|
-
dice = generateStatsDice(dice, userStat);
|
215
|
+
dice = core.generateStatsDice(dice, userStat);
|
217
216
|
const formula = `${dice} cc`;
|
218
217
|
const expectedFormula = "1d20+0>20 cc";
|
219
218
|
expect(formula).toEqual(expectedFormula);
|
@@ -224,7 +223,7 @@ describe("verify_template", () => {
|
|
224
223
|
stat1: 5,
|
225
224
|
stat2: 10
|
226
225
|
};
|
227
|
-
dice = generateStatsDice(dice, userStat);
|
226
|
+
dice = core.generateStatsDice(dice, userStat);
|
228
227
|
const formula = `${dice} cc`;
|
229
228
|
const expectedFormula = "1d20+5>5 cc";
|
230
229
|
expect(formula).toEqual(expectedFormula);
|
@@ -235,7 +234,7 @@ describe("verify_template", () => {
|
|
235
234
|
stat1: 5,
|
236
235
|
stat2: 10
|
237
236
|
};
|
238
|
-
dice = generateStatsDice(dice, userStat);
|
237
|
+
dice = core.generateStatsDice(dice, userStat);
|
239
238
|
const formula = `${dice} cc`;
|
240
239
|
const expectedFormula = "1d20+5>3 cc";
|
241
240
|
expect(formula).toEqual(expectedFormula);
|
package/tsconfig.json
CHANGED
File without changes
|