Avoid division by 0 when there are no contract samples.
Refactor testing grammar.
Make TR random tester more robust against special values.