Thanks for the tests!
I don't suppose there's a nice way to calculate the expected values in the test, the same way we would in the implementation? It'd make the test clearer, and possibly allow for a bunch of nested loops instead of a long list of permutations. On the theory that that is indeed an improvement. I don't know if that'd be hard, though.