📄 testathletescores.java
字号:
import java.io.*;
/**
* Test driver for class <code>AthleteScores</code>.
*
* @author Guimin Lin
* @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) {
/* test the constructor */
AthleteScores athleteScores = new AthleteScores("Lin",70,80,90);
/* test the method: getName */
assertTrue("1: testing method getName",athleteScores.getName() == "Lin");
/* test the method: getScoreOne */
assertTrue("2: testing method getScoreOne",athleteScores.getScoreOne() == 70);
/* test the method: getScoreTwo */
assertTrue("3: testing method getScoreTwo",athleteScores.getScoreTwo() == 80);
/* test the method: getScoreThree */
assertTrue("4: testing method getScoreThree",athleteScores.getScoreThree() == 90);
/* test the mutators: setScoreOne */
athleteScores.setScoreOne(75);
assertTrue("5: testing method setScoreOne",athleteScores.getScoreOne() == 75);
/* test the mutators: setScoreTwo */
athleteScores.setScoreTwo(85);
assertTrue("6: testing method setScoreTwo",athleteScores.getScoreTwo() == 85);
/* test the mutators: setScoreThree */
athleteScores.setScoreThree(95);
assertTrue("7: testing method setScoreThree",athleteScores.getScoreThree() == 95);
/* test the method: getMinimum
* Verify that it returns the first score when the first score is the smallest score. */
assertTrue("8: testing method getMinimum",athleteScores.getMinimum() == 75);
/* Verify that it returns the second score when the second score is the smallest score. */
athleteScores.setScoreTwo(70);
assertTrue("9: testing method getMinimum",athleteScores.getMinimum() == 70);
/* Verify that it returns the third score when the third score is the smallest score. */
athleteScores.setScoreThree(65);
assertTrue("10: testing method getMinimum",athleteScores.getMinimum() == 65);
/* test the method: equals
* Verify that it returns true when objects being compared have the same name. */
AthleteScores athleteScores1 = new AthleteScores("Lin",70,80,90);
assertTrue("11: testing method equals",athleteScores.equals(athleteScores1));
/* Verify that it returns false when objects being compared do not have the same name. */
AthleteScores athleteScores2 = new AthleteScores("Lu",75,85,95);
assertTrue("12: testing method equals",!athleteScores.equals(athleteScores2));
/* Verify that it returns false when objects being compared are not instances of AthleteScores. */
TestAthleteScores test = new TestAthleteScores();
assertTrue("13: testing method equals",!athleteScores.equals(test));
/* test the method toString */
assertTrue("14: testing method toString",athleteScores.toString().equals("Lin,75.0,70.0,65.0"));
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 + -