我遇到了java中的assertArrayEquals問題。這是要求我創建一個新的方法,但我使用JUnit,所以我真的不明白我該如何解決這個問題。assertArrayEquals在Junit中不起作用
這是我的JUnit測試案例
@Test
public void testSortInsert() throws IOException {
Word tester1 [] = input(0,16);
Word tester2 [] = input(1,256);
Word tester3 [] = input(2,256);
Insertion.sortInsert(tester1);
Word insert1 [] = input(0,16);
StopWatch time = new StopWatch();
time.start();
Insertion.sortInsert(insert1);
time.stop();
int insertTime = timer(time);
assertArrayEquals(insert1,tester1);
}
這是有我的Word ADT我的Word文件。它包括一個用於@overide等於
package sort;
public class Word implements Comparable<Word>{
private String word;
private int score;
public Word(String w, int s)
{
this.word = w;
this.score = s;
}
public Word() {
// TODO Auto-generated constructor stub
}
public int getScore()
{
return this.score;
}
public void setScore(int s)
{
this.score = s;
}
public String getWord()
{
return this.word;
}
public void setWord(Word w)
{
this.word = w.word;
}
@Override
public int compareTo(Word w)
{
if (this.score > w.score){
return 1;
}
if (this.score < w.score){
return -1;
}
return 0;
}
@Override
public boolean equals(Object x)
{
if (this == x) { return true; }
if (x == null) { return false; }
if (getClass() != x.getClass()) { return false; }
Word other = (Word) x;
if (score != other.score) { return false; }
if (word == null)
{
if (other.word != null) { return false; }
else if (!word.equals(other.word)) { return false; }
}
return true;
}
public String toString()
{
//TODO
return "{" + this.word + "," + this.score + "}";
}
}
凡定義'assertArrayEquals'? – immibis 2015-02-10 22:58:17
它是一個內置的java函數,可以處理int和字符串數組。我只是希望它能與字類型的數組一起工作 – HassaanM 2015-02-10 23:01:24
@immibis這是來自JUnit框架的一種方法。 – 2015-02-10 23:01:26