-
-
Notifications
You must be signed in to change notification settings - Fork 546
/
canonical-data.json
661 lines (661 loc) · 18.2 KB
/
canonical-data.json
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
{
"exercise": "react",
"comments": [
"Note that, due to the nature of this exercise,",
"the tests are specified using their cells and a series of operations to perform on the cells.",
"",
"Each object in the `cells` array has a `name` and `type` (`input` or `output`).",
"input cells have an `initial_value`, and compute cells have `inputs` and `compute_function`",
"",
"Each object in the `operations` array has a `type`.",
"Depending on the type, it also has additional fields.",
"The possible types and semantics of their fields are as follows:",
"",
"* expect_cell_value (`cell`, `value`): Expect that cell `cell` has value `value`.",
"* set_value (`cell`, `value`, optionally `expect_callbacks`, `expect_callbacks_not_to_be_called`): Sets input cell `cell` to value `value`.",
" Expect that, as a result, all callbacks in `expect_callbacks` (if present) were called exactly once with the designated value",
" Expect that no callbacks in `expect_callbacks_not_to_be_called` (if present) were called as a result.",
"* add_callback (`cell`, `name`): Adds a callback to cell `cell`. Store the callback ID in a variable named `name`.",
" all callbacks are assumed to simply store the values they're called with in some array.",
"* remove_callback (`cell`, `name`): Removes the callback `name` from cell `cell`.",
"",
"Additional notes:",
"",
"These tests only describe compute cells with up to two inputs.",
"Some languages may choose to have two functions: create_compute1 and create_compute2.",
"The compiler can then ensure that you never pass a two-input function to a one-input compute cell.",
"(This benefit only exists for statically typed languages).",
"If your track does this, you should test that all combinations of",
"(compute1, compute2) can depend on (input, compute1, compute2) are tested.",
"Other languages simply have a single create_compute function, taking a list of input cells.",
"Of the languages in this category, there are two subcategories:",
"- In some languages, the compute function might take as many inputs as there are input cells.",
" (it might be very difficult to write the type signature for create_compute in statically typed languages!)",
"- In other languages, the compute function might always take a single input (the list of values)",
" (again this gives up the ability to check that the arities match)",
"Both subcategories using create_compute have the benefit of more flexibility in arity,",
"fewer repetitive tests (only need to test that compute cells can depend on compute cells and input cells),",
"and likely less repetitive code.",
"",
"Finally, note that all values are integers.",
"If your language supports generics, you may consider allowing reactors to act on other types.",
"Tests for that are not included here.",
""
],
"cases": [
{
"uuid": "c51ee736-d001-4f30-88d1-0c8e8b43cd07",
"description": "input cells have a value",
"property": "react",
"input": {
"cells": [
{
"name": "input",
"type": "input",
"initial_value": 10
}
],
"operations": [
{
"type": "expect_cell_value",
"cell": "input",
"value": 10
}
]
},
"expected": {}
},
{
"uuid": "dedf0fe0-da0c-4d5d-a582-ffaf5f4d0851",
"description": "an input cell's value can be set",
"property": "react",
"input": {
"cells": [
{
"name": "input",
"type": "input",
"initial_value": 4
}
],
"operations": [
{
"type": "set_value",
"cell": "input",
"value": 20
},
{
"type": "expect_cell_value",
"cell": "input",
"value": 20
}
]
},
"expected": {}
},
{
"uuid": "5854b975-f545-4f93-8968-cc324cde746e",
"description": "compute cells calculate initial value",
"property": "react",
"input": {
"cells": [
{
"name": "input",
"type": "input",
"initial_value": 1
},
{
"name": "output",
"type": "compute",
"inputs": ["input"],
"compute_function": "inputs[0] + 1"
}
],
"operations": [
{
"type": "expect_cell_value",
"cell": "output",
"value": 2
}
]
},
"expected": {}
},
{
"uuid": "25795a3d-b86c-4e91-abe7-1c340e71560c",
"description": "compute cells take inputs in the right order",
"property": "react",
"input": {
"cells": [
{
"name": "one",
"type": "input",
"initial_value": 1
},
{
"name": "two",
"type": "input",
"initial_value": 2
},
{
"name": "output",
"type": "compute",
"inputs": ["one", "two"],
"compute_function": "inputs[0] + inputs[1] * 10"
}
],
"operations": [
{
"type": "expect_cell_value",
"cell": "output",
"value": 21
}
]
},
"expected": {}
},
{
"uuid": "c62689bf-7be5-41bb-b9f8-65178ef3e8ba",
"description": "compute cells update value when dependencies are changed",
"property": "react",
"input": {
"cells": [
{
"name": "input",
"type": "input",
"initial_value": 1
},
{
"name": "output",
"type": "compute",
"inputs": ["input"],
"compute_function": "inputs[0] + 1"
}
],
"operations": [
{
"type": "set_value",
"cell": "input",
"value": 3
},
{
"type": "expect_cell_value",
"cell": "output",
"value": 4
}
]
},
"expected": {}
},
{
"uuid": "5ff36b09-0a88-48d4-b7f8-69dcf3feea40",
"description": "compute cells can depend on other compute cells",
"property": "react",
"input": {
"cells": [
{
"name": "input",
"type": "input",
"initial_value": 1
},
{
"name": "times_two",
"type": "compute",
"inputs": ["input"],
"compute_function": "inputs[0] * 2"
},
{
"name": "times_thirty",
"type": "compute",
"inputs": ["input"],
"compute_function": "inputs[0] * 30"
},
{
"name": "output",
"type": "compute",
"inputs": ["times_two", "times_thirty"],
"compute_function": "inputs[0] + inputs[1]"
}
],
"operations": [
{
"type": "expect_cell_value",
"cell": "output",
"value": 32
},
{
"type": "set_value",
"cell": "input",
"value": 3
},
{
"type": "expect_cell_value",
"cell": "output",
"value": 96
}
]
},
"expected": {}
},
{
"uuid": "abe33eaf-68ad-42a5-b728-05519ca88d2d",
"description": "compute cells fire callbacks",
"property": "react",
"input": {
"cells": [
{
"name": "input",
"type": "input",
"initial_value": 1
},
{
"name": "output",
"type": "compute",
"inputs": ["input"],
"compute_function": "inputs[0] + 1"
}
],
"operations": [
{
"type": "add_callback",
"cell": "output",
"name": "callback1"
},
{
"type": "set_value",
"cell": "input",
"value": 3,
"expect_callbacks": {
"callback1": 4
}
}
]
},
"expected": {}
},
{
"uuid": "9e5cb3a4-78e5-4290-80f8-a78612c52db2",
"description": "callback cells only fire on change",
"property": "react",
"input": {
"cells": [
{
"name": "input",
"type": "input",
"initial_value": 1
},
{
"name": "output",
"type": "compute",
"inputs": ["input"],
"compute_function": "if inputs[0] < 3 then 111 else 222"
}
],
"operations": [
{
"type": "add_callback",
"cell": "output",
"name": "callback1"
},
{
"type": "set_value",
"cell": "input",
"value": 2,
"expect_callbacks_not_to_be_called": ["callback1"]
},
{
"type": "set_value",
"cell": "input",
"value": 4,
"expect_callbacks": {
"callback1": 222
}
}
]
},
"expected": {}
},
{
"uuid": "ada17cb6-7332-448a-b934-e3d7495c13d3",
"description": "callbacks do not report already reported values",
"property": "react",
"input": {
"cells": [
{
"name": "input",
"type": "input",
"initial_value": 1
},
{
"name": "output",
"type": "compute",
"inputs": ["input"],
"compute_function": "inputs[0] + 1"
}
],
"operations": [
{
"type": "add_callback",
"cell": "output",
"name": "callback1"
},
{
"type": "set_value",
"cell": "input",
"value": 2,
"expect_callbacks": {
"callback1": 3
}
},
{
"type": "set_value",
"cell": "input",
"value": 3,
"expect_callbacks": {
"callback1": 4
}
}
]
},
"expected": {}
},
{
"uuid": "ac271900-ea5c-461c-9add-eeebcb8c03e5",
"description": "callbacks can fire from multiple cells",
"property": "react",
"input": {
"cells": [
{
"name": "input",
"type": "input",
"initial_value": 1
},
{
"name": "plus_one",
"type": "compute",
"inputs": ["input"],
"compute_function": "inputs[0] + 1"
},
{
"name": "minus_one",
"type": "compute",
"inputs": ["input"],
"compute_function": "inputs[0] - 1"
}
],
"operations": [
{
"type": "add_callback",
"cell": "plus_one",
"name": "callback1"
},
{
"type": "add_callback",
"cell": "minus_one",
"name": "callback2"
},
{
"type": "set_value",
"cell": "input",
"value": 10,
"expect_callbacks": {
"callback1": 11,
"callback2": 9
}
}
]
},
"expected": {}
},
{
"uuid": "95a82dcc-8280-4de3-a4cd-4f19a84e3d6f",
"description": "callbacks can be added and removed",
"property": "react",
"input": {
"cells": [
{
"name": "input",
"type": "input",
"initial_value": 11
},
{
"name": "output",
"type": "compute",
"inputs": ["input"],
"compute_function": "inputs[0] + 1"
}
],
"operations": [
{
"type": "add_callback",
"cell": "output",
"name": "callback1"
},
{
"type": "add_callback",
"cell": "output",
"name": "callback2"
},
{
"type": "set_value",
"cell": "input",
"value": 31,
"expect_callbacks": {
"callback1": 32,
"callback2": 32
}
},
{
"type": "remove_callback",
"cell": "output",
"name": "callback1"
},
{
"type": "add_callback",
"cell": "output",
"name": "callback3"
},
{
"type": "set_value",
"cell": "input",
"value": 41,
"expect_callbacks": {
"callback2": 42,
"callback3": 42
},
"expect_callbacks_not_to_be_called": ["callback1"]
}
]
},
"expected": {}
},
{
"uuid": "f2a7b445-f783-4e0e-8393-469ab4915f2a",
"description": "removing a callback multiple times doesn't interfere with other callbacks",
"comments": [
"Some incorrect implementations store their callbacks in an array",
"and removing a callback repeatedly either removes an unrelated callback",
"or causes an out of bounds access."
],
"property": "react",
"input": {
"cells": [
{
"name": "input",
"type": "input",
"initial_value": 1
},
{
"name": "output",
"type": "compute",
"inputs": ["input"],
"compute_function": "inputs[0] + 1"
}
],
"operations": [
{
"type": "add_callback",
"cell": "output",
"name": "callback1"
},
{
"type": "add_callback",
"cell": "output",
"name": "callback2"
},
{
"type": "remove_callback",
"cell": "output",
"name": "callback1"
},
{
"type": "remove_callback",
"cell": "output",
"name": "callback1"
},
{
"type": "remove_callback",
"cell": "output",
"name": "callback1"
},
{
"type": "set_value",
"cell": "input",
"value": 2,
"expect_callbacks": {
"callback2": 3
},
"expect_callbacks_not_to_be_called": ["callback1"]
}
]
},
"expected": {}
},
{
"uuid": "daf6feca-09e0-4ce5-801d-770ddfe1c268",
"description": "callbacks should only be called once even if multiple dependencies change",
"comments": [
"Some incorrect implementations call a callback function too early,",
"when not all of the inputs of a compute cell have propagated new values."
],
"property": "react",
"input": {
"cells": [
{
"name": "input",
"type": "input",
"initial_value": 1
},
{
"name": "plus_one",
"type": "compute",
"inputs": ["input"],
"compute_function": "inputs[0] + 1"
},
{
"name": "minus_one1",
"type": "compute",
"inputs": ["input"],
"compute_function": "inputs[0] - 1"
},
{
"name": "minus_one2",
"type": "compute",
"inputs": ["minus_one1"],
"compute_function": "inputs[0] - 1"
},
{
"name": "output",
"type": "compute",
"inputs": ["plus_one", "minus_one2"],
"compute_function": "inputs[0] * inputs[1]"
}
],
"operations": [
{
"type": "add_callback",
"cell": "output",
"name": "callback1"
},
{
"type": "set_value",
"cell": "input",
"value": 4,
"expect_callbacks": {
"callback1": 10
}
}
]
},
"expected": {}
},
{
"uuid": "9a5b159f-b7aa-4729-807e-f1c38a46d377",
"description": "callbacks should not be called if dependencies change but output value doesn't change",
"comments": [
"Some incorrect implementations simply mark a compute cell as dirty when a dependency changes,",
"then call callbacks on all dirty cells.",
"This is incorrect since the specification indicates only to call callbacks on change."
],
"property": "react",
"input": {
"cells": [
{
"name": "input",
"type": "input",
"initial_value": 1
},
{
"name": "plus_one",
"type": "compute",
"inputs": ["input"],
"compute_function": "inputs[0] + 1"
},
{
"name": "minus_one",
"type": "compute",
"inputs": ["input"],
"compute_function": "inputs[0] - 1"
},
{
"name": "always_two",
"type": "compute",
"inputs": ["plus_one", "minus_one"],
"compute_function": "inputs[0] - inputs[1]"
}
],
"operations": [
{
"type": "add_callback",
"cell": "always_two",
"name": "callback1"
},
{
"type": "set_value",
"cell": "input",
"value": 2,
"expect_callbacks_not_to_be_called": ["callback1"]
},
{
"type": "set_value",
"cell": "input",
"value": 3,
"expect_callbacks_not_to_be_called": ["callback1"]
},
{
"type": "set_value",
"cell": "input",
"value": 4,
"expect_callbacks_not_to_be_called": ["callback1"]
},
{
"type": "set_value",
"cell": "input",
"value": 5,
"expect_callbacks_not_to_be_called": ["callback1"]
}
]
},
"expected": {}
}
]
}