I am having issues with my assertArrayEquals in java. It is asking me to create a new method but i am using JUnit so I don't really understand how i can fix this issue.
This is my Junit test case
@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);
}
This is my word file which has my Word ADT. It includes a @overide for equals
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 + "}";
}
}
If you're using JUnit 4 (as it looks like you are), you presumably aren't extending an existing test class - so you need to call the static assertArrayEquals
with the class name, e.g.
import org.junit.Assert;
...
Assert.assertArrayEquals(...);
Now, that ends up being a bit clunky, so often developers statically import the methods they want, e.g.
import static org.junit.Assert.assertArrayEquals;
...
assertArrayEquals(...);
or just import everthing:
import static org.junit.Assert.*;
...
assertArrayEquals(...);
See more on this question at Stackoverflow