Instructions say “the last added score” but no test actually enforce an important edge case. Do I need to store the value that they tried to add?
test {
var scores: HighScores = .init(&.{ 80, 70, 90, 10, 20, 30 });
try std.testing.expectEqual(30, scores.latest());
}
Do I need to ignore the value that failed to register in Top Three?
test {
var scores: HighScores = .init(&.{ 80, 70, 90, 10, 20, 30 });
try std.testing.expectEqual(90, scores.latest());
}
You may argue that I need to go back in time, play Frogger again and see what it did. But my Time Machine is currently out of service.
IsaacG
June 11, 2026, 6:41pm
2
Could you share which line of the test file you are looking at? Are you using an old test?
Exactly! There is no line.
The example tests in my post are my guesses for what test you could add to fix the ambiguity.
IsaacG
June 11, 2026, 7:02pm
4
I believe the expectation is that all added scores are stored, not just the top three. The top three function gets the top three. The last added gets the last added – regardless of whether or not it’s in the top three.
You can not do this. The function does not accept the allocator.
See, you can only store in the fields of the struct. And you can not dynamically change the length of the array.
I would be happy to know that this suboptimal API is going to change.
IsaacG
June 11, 2026, 8:26pm
7
Apologies. There’s no expectations about what is and isn’t stored. The expectation is that the latest returns the last score, regardless of whether or not it is in the top three.
1 Like
We can add a test case on the Zig track: PR
2 Likes