Open leftiness opened 8 years ago
When I get around to this, make sure to go back to flood, line, etc tests which use HashMap<Point, Prism>
and use these changes to make the tests easier to read... Also, use travel() in the tests instead of entering arbitrary coordinates. Makes it easier to understand.
Mm... Or should I use travel()? Makes things interdependent. If travel() broke, then tests for other things would break, and it wouldn't be obvious what's wrong. It's like... the difference between an example and a test? Should I have tests which hard-code point values and examples that use other functions to make things clearer? "Integration" vs "unit" tests I think...
Started poking at #66 today.
The thing is that I'm constructing these Prisms: Prism(point, 1, 0, 0, 0);
If I have to use a newtype, it's awful:
Prism(point, Strength(1), Strength(0), Strength(0), Strength(0));
I looked into deriving a builder. For some reason, the main lib for that doesn't support tuple structs because "what would you name the setters?" Pretty sure I'd name the setter for the field Prism.0
something like Prism.set_0()
, but asdf idk. Maybe I'll make that macro myself.
Anyway, just to see how it would work in practice, I wrote my own quick builder. It's only like thirty or forty lines. Then the code looks like this:
Prism::of(point).east(Strength(1)).build();
Still pretty awful. If I need to set a wall on each side, it's even longer than the tuple struct constructor.
It's worth considering that the main use case of these Prism structs will be deserializing them from some config file. It'll still be used in code, but most of that will be using the PointMap trait.
JSON for example: [ [ 1, 2, 5, 1, 0, 0, 0 ], [ /* prisms */ ] ]
Maybe prefer TOML. Maybe make it a bit more readable? Idk. Machine readable is the only real intention. Less metadata means smaller files. Nobody should be writing a map file by hand anyway.
Still. This is Rust. I need to do a better job with the PointMap trait. Then maybe it'll be easier to use. Especially in tests. Stuff like this:
map.insert(point); // defaults to prism with no wall strength
map.update(point).east(Strength(1)); // insert if not exist, set strength
map.update(point).walls(1, 1, 0, 0);
map.update(point).southeast(Strength::Unbreakable);
map.increase(point).down(1); // increase strength
map.increase(point).southeast(-1);
Writing these flood tests is awful. Ideas for functions: