Added a trainer, and a quick randomized test for it. Should turn test into a Quickcheck version.