Commit e8ab978
committed
robot-name: Redesign for testability
The previous exercise design had two fundamental flaws wrt. testability:
- The source of randomness was not injected by the tests. It was
expected that users would initialize an RNG on their own. This lead to
users simply not using any randomness at all.
- The fact that names were required to be _globally_ unique meant that
there was no way to test for deterministic behavior, given a PRNG with
a stable seed.
These two problems are solved by injecting an RNG from the tests and by
narrowing the requirement of unique names to a single "robot factory".
Motivated by this discussion on the forum:
https://forum.exercism.org/t/rust-track-check-predictability-of-names-in-robot-name-exercise/20077
The function `RobotFactory::new_robot` takes a `&mut self`, even
though it could take a `&self` as well. `&self` would work, because
the robot factory needs shared ownership & interior mutability anyway
to track robot names generated with `Robot::reset`. However, that
would slightly interfere with the TTD flow of this exercise. If
`RobotFactory::new_robot` takes a `&self`, users will be forced to use
interior mutability right away, even though it's unclear why that is
even necessary until they get around to implementing `Robot::reset`.1 parent e16a91c commit e8ab978
File tree
8 files changed
+131
-74
lines changed- exercises/practice/robot-name
- .docs
- .meta
- src
- tests
- rust-tooling/ci-tests/tests
8 files changed
+131
-74
lines changedLines changed: 0 additions & 9 deletions
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 8 | + | |
15 | 9 | | |
16 | 10 | | |
17 | | - | |
18 | | - | |
19 | 11 | | |
20 | | - | |
| 12 | + | |
21 | 13 | | |
22 | 14 | | |
23 | | - | |
| 15 | + | |
24 | 16 | | |
25 | | - | |
26 | | - | |
| 17 | + | |
27 | 18 | | |
28 | 19 | | |
29 | 20 | | |
30 | 21 | | |
31 | 22 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
39 | | - | |
40 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
41 | 48 | | |
| 49 | + | |
42 | 50 | | |
43 | | - | |
44 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
45 | 54 | | |
46 | | - | |
47 | 55 | | |
48 | | - | |
49 | | - | |
50 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
51 | 61 | | |
52 | 62 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
1 | 8 | | |
2 | 9 | | |
3 | | - | |
| 10 | + | |
4 | 11 | | |
5 | | - | |
| 12 | + | |
6 | 13 | | |
7 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
8 | 21 | | |
9 | | - | |
| 22 | + | |
10 | 23 | | |
11 | 24 | | |
12 | | - | |
13 | | - | |
| 25 | + | |
| 26 | + | |
14 | 27 | | |
15 | 28 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
2 | 10 | | |
3 | 11 | | |
4 | 12 | | |
| |||
14 | 22 | | |
15 | 23 | | |
16 | 24 | | |
17 | | - | |
18 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
19 | 29 | | |
20 | 30 | | |
21 | 31 | | |
22 | 32 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
27 | 38 | | |
28 | 39 | | |
29 | 40 | | |
30 | 41 | | |
31 | | - | |
32 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
33 | 48 | | |
34 | | - | |
35 | | - | |
36 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
37 | 56 | | |
38 | | - | |
39 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
40 | 66 | | |
41 | 67 | | |
42 | 68 | | |
43 | 69 | | |
44 | 70 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
49 | 77 | | |
50 | 78 | | |
51 | 79 | | |
52 | 80 | | |
53 | 81 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 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 | + | |
59 | 107 | | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| |||
0 commit comments