Open polux opened 2 years ago
Let's collect the relevant invariants in a nice list here.
activeRobots
setThis is the only real invariant that I found from reading through #200. I am not sure what invariants you are referring to from 2b14658.
To check that the above invariant holds we just need to traverse the entire robotMap
, check the machine state of each robot, and see whether they are in activeRobots
as appropriate. I don't think we want to assert this in gameTick
--- part of the point of having an active robots set is so that we don't have to iterate over the entire robotMap
every tick. Though I suppose we could add a flag to enable this assertion to be checked, and turn it on in our test suites.
Concretely, I propose:
--check-invariants
, and store a boolean in the UIState
uiPlaying = False
and uiMenu = NoMenu
at the same time), and call them conditionally on the --check-invariants
flag being set. The checking functions should crash the app loudly if an invariant is violated.Related Issue:
Add a new command-line flag
--check-invariants
, and store a boolean in theUIState
@byorgey do we test UI state at all? I thought we only create the game state.
I think it would be better to have a boolean in game state that causes a verification of the invariants on each tick and if that fails a Critical
message is written to the global log, which we check in integration tests:
https://github.com/swarm-game/swarm/blob/3cf62ab2947be91dad033760438252fc9bcaf169/test/integration/Main.hs#L130-L131
do we test UI state at all? I thought we only create the game state.
I'm not sure I understand what you mean. There are definitely UI-level invariants as well.
I meant the integration/unit tests. Of course we test the game manually as well.
Oh, I see. Right, I don't think we currently have any integration/unit tests for the UI state.
With all the subtle invariants introduced by #200 and 2b146586d2c756e9c1e86d0975957d1ad96f5097 we really want to write a function that checks that they hold, and either add a test that they aren't violated over the run of a game or add an assert in gameTick, or both.