| Sets | |||||||||||||||||||||||||||
The tester has a special way of comparing elements of a collection that implements
the For comparing elements of a set we use the Java equals method when comparing two objects, as this is what is used to determine duplicates in a Set. If the user implements the Here is an example comparing a
...
Song song1a = new Song("title1", 4);
Song song1b = this.song1;
HashSet<Song> songSet1a =
new HashSet<Song>(Arrays.asList(this.song1a, this.song2, this.song3));
HashSet<Song> songSet1b =
new HashSet<Song>(Arrays.asList(this.song1b, this.song3, this.song2));
TreeSet<Song> songSet1c =
new TreeSet<Song>(Arrays.asList(this.song1b, this.song3, this.song2));
The test cases would be:
void testSets(Tester t){
t.checkExpect(songSet1a, songSet1b, "should succeed");
t.checkExpect(songSet1a, songSet1c, "should fail");
t.checkSet(songSet1a, songSet1c, "should succeed");
}
Code sourcesHere is the complete source code for this test suite. You can also download the entire souce code as a zip file. Complete test results are shown here. | ||||||||||||||||||||||||||||
| last updated on Mon Apr 4 15:26:25 EDT 2011 | generated with DrRacket |