Basic Types

Tests for primitive types, wrapper classes and numeric ranges.

Overview

The examples here illustrate the design of tests for all primitive types, Math numeric types that represent big numbers, and the wrapper classes for all primitive types. Additionally, we include examples of the use of checking whether the given numerical value falls within the specified range.

The class ExamplesBasicTypes contains all test cases. The additional classes allow us to verify that the testing of the primitive types extends to fields of classes.

Code sources

Here is the complete source code for this test suite.

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

Complete test results are shown here.

Brief Examples

The tests for primitive types compare the expected and actual value of the same primitive type, or an instance of the corresponding wrapper class. The tester does not distinguish between the primitive type and its wrapper class. So,

t.checkExpect(5, new Integer(5))

will always succeed. The checkRange check method can be used to determine whether the actual value is within the range defined by the values of the same type. So,

t.checkRange(5, 3, new Integer(8))

is correct and will succeed, while

t.checkRange(0.4, 0, 1)

will not compile, due to the incompatible types between the value and the range bounds.

The checkNumRange alleviates this problem and allows the user to define the range and the actual value to be of any type that extends (or whose wrapper class extends) the Java Number. So the previous example can be written as:

t.checkNumRange(0.4 0, 1)


back

Last updated: March 29, 2011 11:20 am