Test.pmmodule. This comes distributed with Rakudo, but initially I cloned it to Vector just to simplify setting up the tests. The magic of
Configure.pmhandles the path to Rakudo's
Test.pmproperly, so I've deleted the Vector's local version.
The top of the file sets everything up:
etc. I'm sure there's a better way to define
is_approx_vector, but this version works okay. (Actually, if
-worked properly for Vector, and we defined
absto be a synonym for
Length, I believe
is_approxwould compare two Vectors quite nicely.) We use
test *to declare we have no plan -- that means instead of specifying the number of tests to run, we have to use
done_testingat the end of the tests. Then it defines a bunch of Vectors to use in the tests, and we are off and running.
I only use a tiny subset of the functions available in
isa_oklet's me test if the type of the supposed Vector objects is actually Vector.
ischecks its first two parameters for string equality. Absolute equality is a bad idea with floating point numbers, so
is_approxchecks that the absolute difference between two numbers is less than a small epsilon. My
is_approx_vectordoes the same sort of thing for two Vectors.
dies_oktakes a closure and tests that it dies as expected. For instance, I use this to test that taking the dot product of Vectors of different dimensions fails instead of generating a meaningless result.
lives_okdoes the opposite, testing that code doesn't die without specifying what it actually does.
Put them together and it's possible to do a decent set of tests. In some cases (like 7D cross product) I had no idea what the correct answer of the operation is (other than just duplicating the formula for it again, but that seems pretty useless), but I did test that the results have the expected properties. Overall at the moment my test suite runs 256 tests, which is a lovely number IMO.
And that's pretty much it for Vector for now. I'm going to tackle doing a few simple projects using it and see what I learn from them. And I promise to revisit Vector when changes to Rakudo make it work better.