📄 testathletescores.java
字号:
package yls;
import java.io.*;
/**
* Test driver for class <code>AthleteScores</code>.
*
* @author Wangshuo_200732580237
* @version final
*/
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 */
//Testing accessors
AthleteScores ws = new AthleteScores("WangShuo",0.0,0.0,0.0);
assertTrue("1:testing method getName()",ws.getName() == "WangShuo");
assertTrue("2:testing method getScoreOne()",ws.getScoreOne() == 0.0);
assertTrue("3:testing method getScoreTwo()",ws.getScoreTwo() == 0.0);
assertTrue("4:testing method getScoreThree()",ws.getScoreThree() == 0.0);
//Testing mutator
ws.setScoreOne(1.0);
assertTrue("5:testing method setScoreOne",ws.getScoreOne() == 1.0);
ws.setScoreTwo(2.0);
assertTrue("6:testing method setScoreTwo",ws.getScoreTwo() == 2.0);
ws.setScoreThree(3.0);
assertTrue("7:testing method setScoreThree",ws.getScoreThree() == 3.0);
//Testing getMinimum
AthleteScores yls = new AthleteScores("YanLiShan",90,91,92);
assertTrue("8:testing method getMinimum() when ScoreOne is the smallest score",yls.getMinimum() == yls.getScoreOne());
AthleteScores cyw = new AthleteScores("CaoYouWen",90,89,90);
assertTrue("9:testing method getMinimum() when ScoreTwo is the smallest score",cyw.getMinimum() == cyw.getScoreTwo());
AthleteScores zh = new AthleteScores("ZhangHan",90,90,89);
assertTrue("10:testing method getMinimum() when ScoreThree is the smallest score",zh.getMinimum() == zh.getScoreThree());
//Testing equals
AthleteScores t1 = new AthleteScores("Kevin",0.0,0.0,0.0);
AthleteScores t2 = new AthleteScores("Kevin",1.0,2.0,3.0);
AthleteScores t3 = new AthleteScores("Cap",1.0,2.0,3.0);
String haha = "XieQiCheng is a dog";
assertTrue("11:testing method equals when t1 and t2 have the same name",t1.equals(t2));
assertTrue("12:testing method equals when t2 and t3 have different name",!t2.equals(t3));
assertTrue("13:testing method equals when comparing two different instances of different class",!t3.equals(haha));
//Testing toString
AthleteScores t4 = new AthleteScores("ShanShan",100,100,100);
stdOut.println(t4);
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 + -