Create High Level Test Framework for StandardRuleset.ResolveMoves(...) #26
Replies: 9 comments 3 replies
-
I'd love to collaborate on this. Ideally the test data/fixtures could be made public so that the same tests can run for our snakes as the tests for the official rules. What's the next step and how can I help? |
Beta Was this translation helpful? Give feedback.
-
Yes - exactly! Next step I think would be a single test case, maybe in standard_test.go, that loads a board state from a json file and checks the results against a second json file. Once we have one test working, we can worry about adding others. |
Beta Was this translation helpful? Give feedback.
-
Interesting, so in theory when it's time to build the whole canonical dataset we would run the rulesets for lots of scenarios, save the results as JSON, and then store it for history? So after that exists, it's literally just a content comparison to test it. That means testing it wouldn't even have to load up the full example JSON, it could go by a hash or file checksum |
Beta Was this translation helpful? Give feedback.
-
Yeah, regression testing becomes super easy. New rulesets can be implemented using test cases first. In theory yeah you could use a checksum but ordering in JSON isn't deterministic so that would need additional manipulation. Easier to just do JSON object dumps of the structs, load and run compares (which go handles well). |
Beta Was this translation helpful? Give feedback.
-
(closed by accident ;)) |
Beta Was this translation helpful? Give feedback.
-
Haven't really started yet, but saving this here for reference: https://www.npmjs.com/package/json-diff (might be useful) |
Beta Was this translation helpful? Give feedback.
-
I opend a PR for this on the repo! BattlesnakeOfficial/rules#43 |
Beta Was this translation helpful? Give feedback.
-
Moved this to an issue, since this is work we'd like to get done. #73 for tracking. |
Beta Was this translation helpful? Give feedback.
-
One important part of this to consider is how the ruleset interface handles random chance. For tests you want it to be deterministic, which it is, but it's only deterministic if you pass a seed, and this is not ideal for testing because you end up hard coding examples to verify for example that a food was placed in X,Y location, which is linked to the seed and not the intent that it was randomly placed there by chance. My suggestion is to change the ruleset interface just slightly, so that there is a separate function/method for generating events by chance than applying them, both for the initial state and for move applications. This would make it so that you could test the fully deterministic functions purely, because they would be separate steps. Let me know if this makes sense. (This also relates to #76) |
Beta Was this translation helpful? Give feedback.
-
We're hoping to build a very thorough and thoughtful test suite for high level move resolution (using the Standard Ruleset for now).
Ideally this consumes input board state, input moves, and expected output board state from test files (probably json?).
Example:
tests/standard/1.in.json
---> contains a JSON representation of BoardState to start with + SnakeMoves to execute
tests/standard/1.out.json
---> contains a JSON representation of the resulting BoardState after StandardRuleset is applied
Beta Was this translation helpful? Give feedback.
All reactions