File tree Expand file tree Collapse file tree 2 files changed +19
-19
lines changed
main/java/stringbasic/exercises
test/java/stringbasic/exercises Expand file tree Collapse file tree 2 files changed +19
-19
lines changed Original file line number Diff line number Diff line change 11package stringbasic .exercises ;
22
3- import java .util .Objects ;
4-
53/**
64 * Pair container for int elements
75 */
@@ -10,10 +8,6 @@ public class IntPair {
108 private int first ;
119 private int second ;
1210
13- public IntPair () {
14-
15- }
16-
1711 public IntPair (int first , int second ) {
1812 this .first = first ;
1913 this .second = second ;
@@ -23,18 +17,10 @@ public int getFirst() {
2317 return first ;
2418 }
2519
26- public void setFirst (int first ) {
27- this .first = first ;
28- }
29-
3020 public int getSecond () {
3121 return second ;
3222 }
3323
34- public void setSecond (int second ) {
35- this .second = second ;
36- }
37-
3824 @ Override
3925 public boolean equals (Object o ) {
4026 if (this == o ) return true ;
@@ -43,9 +29,4 @@ public boolean equals(Object o) {
4329 return getFirst () == intPair .getFirst () &&
4430 getSecond () == intPair .getSecond ();
4531 }
46-
47- @ Override
48- public int hashCode () {
49- return Objects .hash (getFirst (), getSecond ());
50- }
5132}
Original file line number Diff line number Diff line change 1+ package stringbasic .exercises ;
2+
3+ import org .junit .Assert ;
4+ import org .junit .Test ;
5+
6+ public class IntPairTest {
7+
8+ @ Test
9+ public void testConstructor () {
10+ IntPair firstPair = new IntPair (2 ,4 );
11+ IntPair equalPair = new IntPair (2 ,4 );
12+ IntPair differentPair = new IntPair (3 ,5 );
13+ Assert .assertTrue (firstPair .equals (equalPair ));
14+ Assert .assertTrue (firstPair .equals (firstPair ));
15+ Assert .assertFalse (firstPair .equals (differentPair ));
16+ Assert .assertFalse (firstPair .equals (null ));
17+ Assert .assertFalse (firstPair .equals ("not a pair" ));
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments