[racket] tests/eli-tester feedback (Was: Racket unit testing)

From: Don Blaheta (dblaheta at monm.edu)
Date: Sat Feb 19 22:58:26 EST 2011

Quoth Eli Barzilay:
> Three hours ago, Hendrik Boom wrote:
> > It almost looks as if you want predicates on the right side of =>'
> Yes -- the whole point of the simple arrow-less version is to make
> using predicates very easy.  For example, instead of some
> 1. (test E1 =satisfies> even?
>          E2 =satisfies> (lambda (x) (> x 50)))
> you'd write
> 2. (test (even? E1)
>          (> E2 50))
> It's probably good to compare this to the suggestions in this threads
> for the arrow-less version:
> 3. (test (and (even? E1) #t) => #t
>          (and (> E2 50) #t)  => #t)
> IMO, (2) gains much readability over (1), and (3) loses most of that.

The disadvantage of (2) and (3) is that they don't front-load the name
of the thing you're testing, and when you actually throw function calls
in there instead of E1 and E2, it can get sort of confusing as to what
the test is even testing:

(test (even? (function-of-interest (* x 4)))
      (string=? (output->string (function-of-interest 42)) "fnord"))

Of course, presumably these would all be sitting immediately before or
immediately after the definition of function-of-interest, so you might
know that "these are the tests for function-of-interest".  All the same,
having a consistent function-first format like:

(test (function-of-interest (* x 4))  =?>  even?
      (function-of-interest 42)       =?>
                        (lambda (x) (string=? (output->string x) "fnord")))

seems like a valuable property.  Especially if you have a single test
block that is meant to test a related suite of two or three functions,
and would like to be able to glance through quickly and see what is
being tested.  Also especially if part of the verification includes a
user-defined predicate; we're unlikely to think that a test case is
trying to test even? or > but in something like

      (string=? (output->string (function-of-interest 42)) "fnord")

it's not obvious whether it's output->string or function-of-interest
being tested, while in 

      (function-of-interest 42)       =?>
                        (lambda (x) (string=? (output->string x) "fnord"))

it's clearer that this is a test case for function-of-interest (and
presumably output->string is tested elsewhere).

-=-Don Blaheta-=-dblaheta at monm.edu-=-=-<http://www.monmsci.net/~dblaheta/>-=-
"Do what's right. You'll please some people, and amaze everyone else."
							--Mark Twain

Posted on the users mailing list.