File tree Expand file tree Collapse file tree 2 files changed +38
-3
lines changed Expand file tree Collapse file tree 2 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -26,9 +26,24 @@ static class BWEMMap{
26
26
this .chokes = chokes ;
27
27
}
28
28
29
- public boolean equals (Object object ) {
30
- BWEMMap bwemMap = (BWEMMap ) object ;
31
- return areas == bwemMap .areas && bases == bwemMap .bases && chokes == bwemMap .chokes ;
29
+ @ Override
30
+ public boolean equals (Object o ) {
31
+ if (this == o ) return true ;
32
+ if (o == null || getClass () != o .getClass ()) return false ;
33
+
34
+ BWEMMap bwemMap = (BWEMMap ) o ;
35
+
36
+ if (areas != bwemMap .areas ) return false ;
37
+ if (bases != bwemMap .bases ) return false ;
38
+ return chokes == bwemMap .chokes ;
39
+ }
40
+
41
+ @ Override
42
+ public int hashCode () {
43
+ int result = areas ;
44
+ result = 31 * result + bases ;
45
+ result = 31 * result + chokes ;
46
+ return result ;
32
47
}
33
48
}
34
49
Original file line number Diff line number Diff line change 3
3
import org .junit .Test ;
4
4
5
5
import java .util .Random ;
6
+ import java .util .TreeSet ;
6
7
7
8
import static org .junit .Assert .*;
8
9
@@ -131,4 +132,23 @@ public void randomPointTests() {
131
132
assertEquals (p1 .y / 32 , tp2 .y );
132
133
}
133
134
}
135
+
136
+ @ Test
137
+ public void testComparablePoint () {
138
+ TreeSet <Point <?>> points = new TreeSet <>();
139
+
140
+ points .add (new Position (0 , 1 ));
141
+ points .add (new Position (0 ,0 ));
142
+ points .add (new TilePosition (0 , 0 ));
143
+ points .add (new Position (1 , 0 ));
144
+ points .add (new WalkPosition (0 , 0 ));
145
+
146
+ assertArrayEquals (new Point <?>[]{
147
+ new Position (0 , 0 ),
148
+ new Position (0 , 1 ),
149
+ new Position (1 , 0 ),
150
+ new WalkPosition (0 , 0 ),
151
+ new TilePosition (0 , 0 )
152
+ }, points .toArray ());
153
+ }
134
154
}
You can’t perform that action at this time.
0 commit comments