📄 testathletescores.java
字号:
import java.io.*;
/**
* Test driver for class <code>AthleteScores</code>.
*
* @author LiGuoLiang
* @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) {
/* PLACE YOUR CODE HERE */
//Test accessors
AthleteScores athleteone = new AthleteScores("one",50,60,70);
assertTrue("1:name is not equal",athleteone.getName()=="one");
assertTrue("2:scoreone is not equal",athleteone.getScoreOne()==50);
assertTrue("3:scoretwo is not equal",athleteone.getScoreTwo()==60);
assertTrue("4:scorethree is not equal",athleteone.getScoreThree()==70);
//Test mutators
AthleteScores athletetwo = new AthleteScores("two",0,0,0);
athletetwo.setScoreOne(10);
assertTrue("5:new scoreone is not equal",athletetwo.getScoreOne()==10);
athletetwo.setScoreTwo(20);
assertTrue("6:new scoretwo is not equal",athletetwo.getScoreTwo()==20);
athletetwo.setScoreThree(30);
assertTrue("7:new scorethree is not equal",athletetwo.getScoreThree()==30);
//Test method getMinimum
AthleteScores athletethree = new AthleteScores("three",50,50,50);
athletethree.setScoreOne(40);
assertTrue("8:the smallest score is not the first score",athletethree.getMinimum()==athletethree.getScoreOne());
athletethree.setScoreTwo(30);
assertTrue("9:the smallest score is not the second score",athletethree.getMinimum()==athletethree.getScoreTwo());
athletethree.setScoreThree(20);
assertTrue("10:the smallest score is not the third score",athletethree.getMinimum()==athletethree.getScoreThree());
//Test method equals
AthleteScores athletefour = new AthleteScores("four",0,0,0);
assertTrue("11:objects are not equal",athletefour.equals(new AthleteScores("four",10,20,30))==true);
assertTrue("12:objects are equal",athletefour.equals(new AthleteScores("five",0,0,0))==false);
assertTrue("13:objects are instances of AthleteScores",athletefour.equals(new Object())==false);
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 + -