Laugh Test
mipri
mipri at minimaltype.com
Thu Sep 24 19:54:40 UTC 2020
On Thursday, 24 September 2020 at 19:15:00 UTC, Ruby The Roobster
wrote:
> So I'm making some sort of library(it's not online yet).
> In that Library there is a class called
> dextend.gameengine.shape.
> In this class, I've made part of an update function(that the
> user of the library calls to update the status of the flag).
> Now, this update function has to check a lot of things(flags,
> certain variables, checks that are in these checks,etc.) Here
> is the function so far(It probably has errors and bugs but I'll
> fix those when I actually finish the function):
>
...
>
> There. Does that look confusing or what?
There are parts of that I don't understand at all, like the
sorted_point logic, and this.next_move, so that limits what I
can suggest.
But you might prefer writing this with an eye on
https://dlang.org/spec/arrays.html#array-operations
https://dlang.org/phobos/std_exception.html#enforce
ex:
struct Mobile {
int[3] pos, delta;
void step() {
import std.exception : enforce;
pos[] += delta[];
enforce(pos[] < [666, 666, 666], "example position
violation");
}
}
unittest {
import std.stdio : writeln;
auto m1 = Mobile([0, 0, 0], [5, 0, -1]);
m1.step;
m1.step;
m1.step;
writeln(m1);
}
unittest {
import std.exception : assertThrown;
auto m1 = Mobile([0, 0, 0], [1000, 1000, 1000]);
m1.step.assertThrown; // position violation
}
More information about the Digitalmars-d
mailing list