Okay, so I made a method that will take a Track with the MAXIMUM_RATING, which is 10 and make an another ArrayList for those tracks with the highest rating.
public ArrayList allTracksWithMaxRating() {
ArrayList<Track> maxRatingTracks = new ArrayList();
int i = 0;
while (i < tracks.size()) {
if (tracks.get(i).getRating() == Track.MAXIMUM_RATING)
maxRatingTracks.add(tracks.get(i));
i++;
}
return maxRatingTracks;
}
This part works when I test it by hand, but I have to also write a test class for it and I cant get the test to pass.
{
private Playlist theTracks;
public void testShouldMakeArrayListWithOnlySongOne() {
theTracks = new Playlist("mo");
theTracks.add(new Track("song 1", 10));
theTracks.add(new Track("song 2", 4));
theTracks.add(new Track("song 3", 6));
theTracks.add(new Track("song 4", 8));
assertEquals(true, theTracks.allTracksWithMaxRating().contains("song 1"));
}
}
It keeps coming back false, but by hand It always shows that the Tracks with a rating of ten are in the new ArrayList. I have never had to write a test class for a second ArrayList before so it might just be me writing my test code wrong. Any help would be appreciated.
Also here is my contains method if it might help.
public boolean contains(String targetTracksName) {
if (targetTracksName == null) {
throw new IllegalArgumentException("Must not be null");
}
return (indexOf(targetTracksName) >= 0);
}