@pie-lib/categorize 2.0.3-next.1 → 2.0.3-next.2

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.
@@ -1,281 +0,0 @@
1
- import { score } from '../scoring';
2
-
3
- describe('scoring', () => {
4
- describe('score', () => {
5
- const _assert = (only) => (label, categories, scoring, expected) => {
6
- const fn = only ? it.only : it;
7
- fn(label, async () => {
8
- const result = await score(categories, scoring);
9
-
10
- expect(result).toMatchObject(expected);
11
- });
12
- };
13
-
14
- const assert = _assert(false);
15
- assert.only = _assert(true);
16
-
17
- describe('w/ partial rules', () => {
18
- assert(
19
- '1 category w/ 1 correct, partial rule for it @ 20%',
20
- [
21
- {
22
- id: '1',
23
- correct: false,
24
- choices: [{ correct: true }],
25
- },
26
- ],
27
- {
28
- partial: {
29
- enabled: true,
30
- rules: [
31
- {
32
- category: '1',
33
- rules: [{ count: 1, percent: 20 }],
34
- },
35
- ],
36
- },
37
- },
38
- {
39
- score: 0.2,
40
- },
41
- );
42
-
43
- assert(
44
- '2 categories equal weights, 1 correct@20%, 2 correct@85% ',
45
- [
46
- {
47
- id: '1',
48
- correct: false,
49
- choices: [{ correct: true }],
50
- },
51
- {
52
- id: '2',
53
- correct: false,
54
- choices: [{ correct: true }, { correct: true }],
55
- },
56
- ],
57
- {
58
- partial: {
59
- enabled: true,
60
- rules: [
61
- {
62
- category: '1',
63
- rules: [{ count: 1, percent: 20 }],
64
- },
65
- {
66
- category: '2',
67
- rules: [{ count: 2, percent: 85 }],
68
- },
69
- ],
70
- },
71
- },
72
- {
73
- score: 0.53,
74
- },
75
- );
76
-
77
- assert(
78
- '2 categories, weights 1 + 3, 1 correct@20% 2 correct@85%',
79
- [
80
- {
81
- id: '1',
82
- correct: false,
83
- choices: [{ correct: true }],
84
- },
85
- {
86
- id: '2',
87
- correct: false,
88
- choices: [{ correct: true }, { correct: true }],
89
- },
90
- ],
91
- {
92
- weighting: {
93
- enabled: true,
94
- rules: [{ category: '2', points: 3 }],
95
- },
96
- partial: {
97
- enabled: true,
98
- rules: [
99
- {
100
- category: '1',
101
- rules: [{ count: 1, percent: 20 }],
102
- },
103
- {
104
- category: '2',
105
- rules: [{ count: 2, percent: 85 }],
106
- },
107
- ],
108
- },
109
- },
110
- {
111
- score: 0.69,
112
- },
113
- );
114
-
115
- assert(
116
- '2 categories, weights 1 + 3, 1 correct@20% only',
117
- [
118
- {
119
- id: '1',
120
- correct: false,
121
- choices: [{ correct: true }],
122
- },
123
- {
124
- id: '2',
125
- correct: false,
126
- choices: [{ correct: true }, { correct: true }],
127
- },
128
- ],
129
- {
130
- weighting: {
131
- enabled: true,
132
- rules: [{ category: '2', points: 3 }],
133
- },
134
- partial: {
135
- enabled: true,
136
- rules: [
137
- {
138
- category: '1',
139
- rules: [{ count: 1, percent: 20 }],
140
- },
141
- ],
142
- },
143
- },
144
- {
145
- score: 0.05,
146
- },
147
- );
148
- });
149
-
150
- describe('2 equal weights', () => {
151
- const a = (categories, expected) =>
152
- assert(
153
- '2 equal weights',
154
- categories,
155
- {
156
- weighting: {
157
- rules: [
158
- { category: '1', points: 1 },
159
- { category: '2', points: 1 },
160
- ],
161
- },
162
- },
163
- expected,
164
- );
165
-
166
- a(
167
- [
168
- { id: '1', correct: true },
169
- { id: '2', correct: true },
170
- ],
171
- {
172
- score: 1.0,
173
- },
174
- );
175
- a(
176
- [
177
- { id: '1', correct: false },
178
- { id: '2', correct: true },
179
- ],
180
- {
181
- score: 0.5,
182
- },
183
- );
184
- a(
185
- [
186
- { id: '1', correct: false },
187
- { id: '2', correct: false },
188
- ],
189
- {
190
- score: 0.0,
191
- },
192
- );
193
- });
194
-
195
- describe('2 unequal weights', () => {
196
- const a = (categories, expected) =>
197
- assert(
198
- '2 unequal weights',
199
- categories,
200
- {
201
- weighting: {
202
- enabled: true,
203
- rules: [
204
- { category: '1', points: 3 },
205
- { category: '2', points: 1 },
206
- ],
207
- },
208
- },
209
- expected,
210
- );
211
-
212
- a(
213
- [
214
- { id: '1', correct: true },
215
- { id: '2', correct: true },
216
- ],
217
- {
218
- score: 1.0,
219
- },
220
- );
221
- a(
222
- [
223
- { id: '1', correct: false },
224
- { id: '2', correct: true },
225
- ],
226
- {
227
- score: 0.25,
228
- },
229
- );
230
-
231
- a(
232
- [
233
- { id: '1', correct: true },
234
- { id: '2', correct: false },
235
- ],
236
- {
237
- score: 0.75,
238
- },
239
- );
240
-
241
- a(
242
- [
243
- { id: '1', correct: false },
244
- { id: '2', correct: false },
245
- ],
246
- {
247
- score: 0.0,
248
- },
249
- );
250
- });
251
-
252
- describe('2 unequal weights with recurring number', () => {
253
- const a = (categories, expected) =>
254
- assert(
255
- '2 unequal weights with recurring number',
256
- categories,
257
- // [{ id: '1', correct: true }, { id: '2', correct: true }],
258
- {
259
- weighting: {
260
- enabled: true,
261
- rules: [
262
- { category: '1', points: 2 },
263
- { category: '2', points: 1 },
264
- ],
265
- },
266
- },
267
- expected,
268
- );
269
-
270
- a(
271
- [
272
- { id: '1', correct: false },
273
- { id: '2', correct: true },
274
- ],
275
- {
276
- score: 0.33,
277
- },
278
- );
279
- });
280
- });
281
- });
@@ -1,19 +0,0 @@
1
- export const cat = (id) => ({ id });
2
-
3
- export const cats = (choices) => ({
4
- choices: choices.map(cat),
5
- });
6
-
7
- export const choice = (id, categoryCount, correct) => {
8
- const out = { id, categoryCount };
9
-
10
- if (correct === false || correct === true) {
11
- out.correct = correct;
12
- }
13
- return out;
14
- };
15
-
16
- export const answer = (category, choices, alternateResponses) => {
17
- const c = choices ? (Array.isArray(choices) ? choices : [choices]) : [];
18
- return { alternateResponses, category, choices: c };
19
- };