Verification by Pattern

Just for linguistic diversity and because regular expressions are easier, let’s translate our example to Perl. To show that some of our techniques apply outside of an object-oriented context, let’s also make this procedural Perl (see Listing 7-4).

Listing 7-4: Listing 7-1 rewritten in Perl

package pattern;sub describeAddition {  my $left = shift;  my $right = shift;  my $sum = $left + $right;  return "The sum of $left and $right is $sum";}

Listing 7-5 shows how our original exact equality test might look like using Test::Unit, the Perl entry into the xUnit family.

Listing 7-5: Listing 7-2 rewritten in Perl using Test::Unit

use Test::Unit::Procedural;use pattern; ...

Get Quality Code: Software Testing Principles, Practices, and Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.