June 24, 2010

Test results QuickCheck and RSpec

There are lame code-snippet in posts bellow:



  1. class Rational from Programming in Scala




  2. org.scalatest.Spec for Rational




  3. org.scalacheck a.k.a QuickCheck


They helped me to decide on my personal preference in testing style.

Conditionally on task at hand, but I'm inclined towards RSpec and QuickCheck tools.



While tossing code around my tests caught two not trivial BUGs.



BUG 1: Rational should normalize not only the quotient but also sign of nominator and denominator.


BUG 2: Scala library description of Ordering isn't accurate.

trait   Ordering[T] extends Comparator[T] with PartialOrdering[T]   
Theorem:
transitive: 
if 
   compare(x, y) == z 
   and compare(y, w) == v 
   and math.signum(z) >= 0 
   and math.signum(v) >= 0 
then 
   compare(x, w) == u 
   and math.signum(z + v) == math.signum(u), 

for any x, y, and w of type T and z, v, and u of type Int.



Both were detected by ScalaCheck tests.

So, it is 2:0 for QuickCheck against RSpec on foreign (Scala) field.

No comments:

Post a Comment