Index

Code Explanation


A warm welcom, I am PairTest.

My Job is to construct Pair object instances and hammer on them. I hope I find a bug.

I also am a good place to learn about how to use an Pair.

My superclass is Abstract Test.

Read more about me below.

  • Run the tests
  • Show the testing summary
public static void main(String[] args)  {
	PairTest test = new PairTest();
	test.testLatLongPair();
	test.testNameAgePair();
	test.testComplexCase();
	test.printSummary();
}
The latitude of NHCC is 45.094167
The longitude of NHCC is -93.356111
Let's test that a pair holds these properly
private void testLatLongPair()  {
	header("Starting -- testLatLongPair");
	//Declare
	Pair<Double, Double> pair;
	double
		latitude = 45.094167,
		longitude = -93.356111;
	//Construct
	pair = new Pair<>(latitude, longitude);
	//Test
	assertEquals(latitude, pair.getFirst());
	assertEquals(longitude, pair.getSecond());
}
Test that pair will hold a
private void testNameAgePair()  {
	header("Starting -- testNameAgePair");
	//Declare
	Pair<String, Integer> pair;
	String nm = "Chin";
	int age = 25;
	//Construct
	pair = new Pair<>(nm, age);
	//Test
	assertEquals(nm, pair.getFirst());
	assertEquals(age, pair.getSecond());
}
Assert that the pair can hold more complex objects
Have it hold a pair of teams
private void testComplexCase()  {
	header("Starting -- testComplexCase");
	//Declare
	Pair<List<String>, List<String>> teamPair;
	List<String>
		team1 = Arrays.asList("Riya", "Asha"),
		team2 = Arrays.asList("Chin", "Bruce");
	//Construct
	teamPair = new Pair<>(team1, team2);
	//Test
	assertEquals(team1, teamPair.getFirst());
	assertEquals(team2, teamPair.getSecond());
}

Complete Source Code


Here is my code.

Have Fun.

Yours,
PairTest

package pair.test;
import java.util.Arrays;
import java.util.List;

import pair.model.Pair;
import testutil.AbstractTest;
import testutil.Employee;

public class PairTest extends AbstractTest {

	//--------------------------
	//Main (Entry Point)

	public static void main(String[] args) {
		PairTest test = new PairTest();
		test.testLatLongPair();
		test.testNameAgePair();
		test.testComplexCase();
		test.printSummary();
	}

	//--------------------------
	//Tests

	private void testLatLongPair() {
		header("Starting -- testLatLongPair");
		//Declare
		Pair<Double, Double> pair;
		double
			latitude = 45.094167,
			longitude = -93.356111;
		//Construct
		pair = new Pair<>(latitude, longitude);
		//Test
		assertEquals(latitude, pair.getFirst());
		assertEquals(longitude, pair.getSecond());
	}

	private void testNameAgePair() {
		header("Starting -- testNameAgePair");
		//Declare
		Pair<String, Integer> pair;
		String nm = "Chin";
		int age = 25;
		//Construct
		pair = new Pair<>(nm, age);
		//Test
		assertEquals(nm, pair.getFirst());
		assertEquals(age, pair.getSecond());
	}
	
	private void testComplexCase() {
		header("Starting -- testComplexCase");
		//Declare
		Pair<List<String>, List<String>> teamPair;
		List<String>
			team1 = Arrays.asList("Riya", "Asha"),
			team2 = Arrays.asList("Chin", "Bruce");
		//Construct
		teamPair = new Pair<>(team1, team2);
		//Test
		assertEquals(team1, teamPair.getFirst());
		assertEquals(team2, teamPair.getSecond());
	}


}