swarm-game / swarm

Resource gathering + programming game
Other
835 stars 52 forks source link

Add flag to test for invariants #217

Open polux opened 2 years ago

polux commented 2 years ago

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.

byorgey commented 2 years ago

Let's collect the relevant invariants in a nice list here.

This 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.

byorgey commented 2 years ago

Concretely, I propose:

xsebek commented 1 year ago

Related Issue:

xsebek commented 1 month ago

Add a new command-line flag --check-invariants, and store a boolean in the UIState

@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

byorgey commented 1 month ago

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.

xsebek commented 1 month ago

I meant the integration/unit tests. Of course we test the game manually as well.

byorgey commented 1 month ago

Oh, I see. Right, I don't think we currently have any integration/unit tests for the UI state.