JavaLib
 
Tester
 
Overview
Basic Types
User Types
Inexact Values
Sets
Iterable
Traversals
Maps
Random Choice
Range Check
Equivalence
ISame
Exceptions
Constructors
Methods
CheckFail
 
Sources
Downloads
 
TSRJ Home
TSRJ Local

CheckFail

At times the user may want to set up a test that verify that the actual value differs from the expected value. The tester supports this version of tests with the checkFail method. It works for the primitive types, the wrapper classes, the user defined types, as well as traversals and maps.

Here is a simple example of its use:

public class Song{

  protected String title;
  private int time; // the playing time
  
  public Song(String title, int time){
    this.title=title;
    this.time=time;
  }
  
  // Produce a new song with the same title, but decreased time
  public Song changedTime(int dec){
    return new Song(this.title, this.time - dec;
  }
} 

// Tests:
class Examples{
Song song1 = new Song("title1", 4);
Song song2 = new Song("title2", 2);

public void testMethods(Tester t){
  // make sure the time has been changed...
  t.checkFail(song1.changedTime(2), song1);
}}

A similar variant can be used to verify that an inexact comparison fails. The method checkInexactFail works for the prinitive types, the wrapper classes, the user defined types, as well as traversals and maps.

Caution: The test checkInexact fails whe the two values involved in the comparison are of the primitive types or are instances of wrapper classes that represent exact values (i.e. whole numbers, characters, boolean values, and bytes). As the results, the corresponding checkInexactFail test will succeed.

Here are examples of its use:

// test should succeed:
t.checkInexact(123000.0, 128000.0, 0.1);

// test should fail:
t.checkInexactFail(123000.0, 128000.0, 0.1);

// test should fail:
t.checkInexact(143000.0, 128000.0, 0.1);

// test should succeed:
t.checkInexactFail(143000.0, 128000.0, 0.1);

// test should fail (comparing exact values):
t.checkInexact(123000, 128000, 0.1);

// test should succeed (comparing exact values):
t.checkInexactFail(123000, 128000, 0.1);

The last two cases will produce the messages:

Attempt to make inexact comparison of exact primitive or wrapper data.

and

Test failed because we cannot make inexact comparison of exact primitive or wrapper data.


Code sources

Tests for checkFail variant are included with user types tests.

Here is the source code for this test suite.

You can also download the entire souce code as a zip file.

Complete test results are shown here.


Tests for checkInexactFail variant are included with inexact values tests.

Here is the source code for this test suite.

You can also download the entire souce code as a zip file.

Complete test results are shown here.


last updated on Mon Apr 4 15:46:34 EDT 2011generated with DrRacket