⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 practical quiz 5.testathletescores.java

📁 CMU SSD3 课程完整答案(除EXAM)
💻 JAVA
字号:
import java.io.*;

/**
 * Test driver for class <code>AthleteScores</code>.
 * 
 * @author Neil
 * @version 1.0.0
 */
public class TestAthleteScores {

	/* Standard output stream */
	private static PrintWriter stdOut = new PrintWriter(System.out, true);

	/* Standard error stream */
	private static PrintWriter stdErr = new PrintWriter(System.err, true);

	/**
	 * Test driver for class <code>AthleteScores</code>.
	 * 
	 * @param args
	 *            not used.
	 */
	public static void main(String[] args) {

		// Testing constructor and accessors
		AthleteScores testOne = new AthleteScores("Jack", 70.0, 80.0, 90.0);

		assertTrue("1: testing method getName()", testOne.getName() == "Jack");
		assertTrue("2: testing method getScoreOne()",
				testOne.getScoreOne() == 70.0);
		assertTrue("3: testing method getScoreTwo()",
				testOne.getScoreTwo() == 80.0);
		assertTrue("4: testing method getScoreThree()",
				testOne.getScoreThree() == 90.0);

		// Testing mutators
		AthleteScores testTwo = new AthleteScores("Jack", 70.0, 80.0, 90.0);

		testTwo.setScoreOne(75.0);
		assertTrue("5: testing method setScoreOne()",
				testTwo.getScoreOne() == 75.0);
		testTwo.setScoreTwo(85.0);
		assertTrue("6: testing method setScoreTwo()",
				testTwo.getScoreTwo() == 85.0);
		testTwo.setScoreThree(95.0);
		assertTrue("7: testing method setScoreThree()",
				testTwo.getScoreThree() == 95.0);

		// Testing method getMinimum
		AthleteScores testThree = new AthleteScores("Jack", 70.0, 80.0, 90.0);

		assertTrue(
				"8: does not return the first score when the second score is the smallest score",
				testThree.getMinimum() == 70.0);

		testThree.setScoreOne(80.0);
		testThree.setScoreTwo(70.0);
		assertTrue(
				"9: does not return the second score when the second score is the smallest score",
				testThree.getMinimum() == 70.0);

		testThree.setScoreTwo(90.0);
		testThree.setScoreThree(70.0);
		assertTrue(
				"10: does not return the third score when the third score is the smallest score",
				testThree.getMinimum() == 70.0);

		// Testing method equals

		AthleteScores testFour = new AthleteScores("Jack", 70.0, 80.0, 90.0);

		assertTrue(
				"11: does not return true when objects being compared have the same name",
				testFour.equals(new AthleteScores("Jack", 60.0, 70.0, 80.0)));
		assertTrue(
				"12: does not return false when objects being compared do not have the same name",
				!testFour.equals(new AthleteScores("Tom", 60.0, 70.0, 80.0)));
		assertTrue(
				"13: does not return false when objects being compared are not instances of AthleteScores",
				!testFour.equals(new Integer(0)));

		// Testing method toString

		AthleteScores testFive = new AthleteScores("Jack", 70.0, 80.0, 90.0);

		assertTrue("14: testing method toString", "Jack,70.0,80.0,90.0"
				.equals(testFive.toString()));

		stdOut.println("done");
	}

	/**
	 * Displays a message in the standard error stream if the value specified by
	 * parameter <code>condition<code> is <code>false</code>.
	 *
	 * @param message  the error message.
	 * @param condition  the test condition.
	 */
	public static void assertTrue(String message, boolean condition) {

		if (!condition) {
			stdErr.print("** Test failure ");
			stdErr.println(message);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -