Following a test-driven en development (TDD) approach. consider first this JUnit
ID: 3754165 • Letter: F
Question
Following a test-driven en development (TDD) approach. consider first this JUnit test trogment: final IntPair new DefaultIntPair (3, 5): final IntPairq-new DefaultIntPair assertTrue (p. firstO3): assertTrue (p. second O 5): assertEquals (11 (3, 511, p. toString O) assertTrue (p. equals(p)): assertFalse (p. equals (q)): assertFalse (q. equals (p)): assertFalse (p. equals (null)); assertTrue (p. equals (q. reverse O)): ineer the IntPair interface in a way that is consistent with the test shown above.Leave out any methods already provided by the class lava. lana.0biest. a) 1.5 Your first job is to reverse-engExplanation / Answer
Please find the code below.
CODE
======================
public class DefaultIntPair {
private int first, second;
public DefaultIntPair(int first, int second) {
this.first = first;
this.second = second;
}
public int first() {
return first;
}
public int second() {
return second;
}
@Override
public String toString() {
return "<" + first + ", " + second + ">";
}
public DefaultIntPair reverse() {
return new DefaultIntPair(second, first);
}
@Override
public boolean equals(Object obj) {
DefaultIntPair pair = (DefaultIntPair) obj;
return first == pair.first() && second == pair.second();
}
}