Skip to content

Commit c8b7773

Browse files
committed
Refactor F_ComparatorTest.java
1 parent 00ae6c7 commit c8b7773

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/test/java/com/github/streams/learn/functional_interfaces/F_ComparatorTest.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package com.github.streams.learn.functional_interfaces;
22

3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
35
import com.github.streams.learn.functional_interfaces.ignore.models.Person;
6+
import java.util.Comparator;
7+
import java.util.function.IntBinaryOperator;
48
import org.junit.jupiter.api.Assertions;
59
import org.junit.jupiter.api.Disabled;
610
import org.junit.jupiter.api.Test;
711

8-
import java.util.Comparator;
9-
import java.util.function.IntBinaryOperator;
10-
11-
import static org.junit.jupiter.api.Assertions.assertFalse;
12-
1312
class F_ComparatorTest {
1413

1514
final Person ayman = new Person("Ayman", "Khan", 51);
@@ -24,12 +23,12 @@ class F_ComparatorTest {
2423
*/
2524
@Test
2625
@Disabled
27-
void comparator01() {
26+
void comparator01() {
2827
Comparator<String> compareByLength = null; // TODO
2928

3029
Assertions.assertTrue(compareByLength.compare("FOUR", "TWO") > 0);
3130
Assertions.assertTrue(compareByLength.compare("ONE", "SEVEN") < 0);
32-
Assertions.assertTrue(compareByLength.compare("ONE", "TWO") == 0);
31+
Assertions.assertEquals(0, compareByLength.compare("ONE", "TWO"));
3332
}
3433

3534
// Hint:
@@ -45,14 +44,14 @@ void comparator01() {
4544
*/
4645
@Test
4746
@Disabled
48-
void comparator02() {
47+
void comparator02() {
4948
Comparator<String> compareByLengthThenAlphabetical = null; // TODO
5049

5150
Assertions.assertTrue(compareByLengthThenAlphabetical.compare("FOUR", "TWO") > 0);
5251
Assertions.assertTrue(compareByLengthThenAlphabetical.compare("ONE", "SEVEN") < 0);
5352
Assertions.assertTrue(compareByLengthThenAlphabetical.compare("ONE", "TWO") < 0);
5453
Assertions.assertTrue(compareByLengthThenAlphabetical.compare("FOUR", "FIVE") > 0);
55-
Assertions.assertTrue(compareByLengthThenAlphabetical.compare("EIGHT", "EIGHT") == 0);
54+
Assertions.assertEquals(0, compareByLengthThenAlphabetical.compare("EIGHT", "EIGHT"));
5655
}
5756

5857
// Hint:
@@ -66,12 +65,12 @@ void comparator02() {
6665
/** Write a Comparator that compares instances of Person using their lastName. */
6766
@Test
6867
@Disabled
69-
void comparator03() {
68+
void comparator03() {
7069
Comparator<Person> comparebyLastName = null; // TODO
7170

7271
Assertions.assertTrue(comparebyLastName.compare(ayman, rod) < 0);
73-
Assertions.assertTrue(comparebyLastName.compare(paul, paul) == 0);
7472
Assertions.assertTrue(comparebyLastName.compare(ayman, jermaine) > 0);
73+
Assertions.assertEquals(0, comparebyLastName.compare(paul, paul));
7574
}
7675

7776
// Hint:
@@ -87,12 +86,12 @@ void comparator03() {
8786
*/
8887
@Test
8988
@Disabled
90-
void comparator04() {
89+
void comparator04() {
9190
Comparator<Person> comparebyLastNameThenFirstName = null; // TODO
9291

9392
Assertions.assertTrue(comparebyLastNameThenFirstName.compare(ayman, rod) < 0);
94-
Assertions.assertTrue(comparebyLastNameThenFirstName.compare(paul, paul) == 0);
9593
Assertions.assertTrue(comparebyLastNameThenFirstName.compare(ayman, jermaine) > 0);
94+
Assertions.assertEquals(0, comparebyLastNameThenFirstName.compare(paul, paul));
9695
}
9796

9897
// Hint:
@@ -108,12 +107,12 @@ void comparator04() {
108107
*/
109108
@Test
110109
@Disabled
111-
void comparator05() {
110+
void comparator05() {
112111
Comparator<Person> comparebyLastNameThenFirstNameReversed = null; // TODO
113112

114113
assertFalse(comparebyLastNameThenFirstNameReversed.compare(ayman, rod) < 0);
115-
Assertions.assertTrue(comparebyLastNameThenFirstNameReversed.compare(paul, paul) == 0);
116114
assertFalse(comparebyLastNameThenFirstNameReversed.compare(ayman, jermaine) > 0);
115+
Assertions.assertEquals(0, comparebyLastNameThenFirstNameReversed.compare(paul, paul));
117116
}
118117

119118
// Hint:
@@ -128,14 +127,14 @@ void comparator05() {
128127
*/
129128
@Test
130129
@Disabled
131-
void comparator06() {
130+
void comparator06() {
132131
Comparator<Person> comparebyLastNameThenFirstNameWithNull = null; // TODO
133132

134133
Assertions.assertTrue(comparebyLastNameThenFirstNameWithNull.compare(ayman, rod) < 0);
135-
Assertions.assertTrue(comparebyLastNameThenFirstNameWithNull.compare(paul, paul) == 0);
136134
Assertions.assertTrue(comparebyLastNameThenFirstNameWithNull.compare(ayman, jermaine) > 0);
137135
Assertions.assertTrue(comparebyLastNameThenFirstNameWithNull.compare(mick, null) < 0);
138136
Assertions.assertTrue(comparebyLastNameThenFirstNameWithNull.compare(null, mick) > 0);
137+
Assertions.assertEquals(0, comparebyLastNameThenFirstNameWithNull.compare(paul, paul));
139138
}
140139

141140
// Hint:
@@ -149,12 +148,12 @@ void comparator06() {
149148
*/
150149
@Test
151150
@Disabled
152-
void comparator07() {
151+
void comparator07() {
153152
Comparator<Person> comparebyAge = null; // TODO
154153

155154
Assertions.assertTrue(comparebyAge.compare(ayman, rod) < 0);
156-
Assertions.assertTrue(comparebyAge.compare(paul, paul) == 0);
157155
Assertions.assertTrue(comparebyAge.compare(mick, jermaine) > 0);
156+
Assertions.assertEquals(0, comparebyAge.compare(paul, paul));
158157
}
159158

160159
// Hint:
@@ -171,14 +170,14 @@ void comparator07() {
171170
*/
172171
@Test
173172
@Disabled
174-
void comparator08() {
173+
void comparator08() {
175174
IntBinaryOperator intCompare = null; // TODO
176175

177176
Assertions.assertTrue(intCompare.applyAsInt(0, 1) < 0);
178-
Assertions.assertTrue(intCompare.applyAsInt(1, 1) == 0);
179177
Assertions.assertTrue(intCompare.applyAsInt(2, 1) > 0);
180178
Assertions.assertTrue(intCompare.applyAsInt(Integer.MIN_VALUE, Integer.MAX_VALUE) < 0);
181179
Assertions.assertTrue(intCompare.applyAsInt(Integer.MAX_VALUE, Integer.MIN_VALUE) > 0);
180+
Assertions.assertEquals(0, intCompare.applyAsInt(1, 1));
182181
}
183182

184183
// Hint:
@@ -192,7 +191,7 @@ void comparator08() {
192191
*/
193192
@Test
194193
@Disabled
195-
void comparator09() {
194+
void comparator09() {
196195
IntBinaryOperator intCompare = null; // TODO
197196

198197
Assertions.assertTrue(intCompare.applyAsInt(0, 1) < 0);
@@ -216,15 +215,16 @@ void comparator09() {
216215
*/
217216
@Test
218217
@Disabled
219-
void comparator10() {
218+
void comparator10() {
220219
DoubleToIntBiFunction doubleCompare = null; // TODO
221220

222221
Assertions.assertTrue(doubleCompare.applyAsInt(0.0, 1.0) < 0);
223-
Assertions.assertTrue(doubleCompare.applyAsInt(1.0, 1.0) == 0);
224222
Assertions.assertTrue(doubleCompare.applyAsInt(2.0, 1.0) > 0);
225-
Assertions.assertTrue(doubleCompare.applyAsInt(Double.NaN, Double.NaN) == 0);
226223
Assertions.assertTrue(doubleCompare.applyAsInt(Double.NaN, 0.0) > 0);
227224
Assertions.assertTrue(doubleCompare.applyAsInt(0.0, Double.NaN) < 0);
225+
226+
Assertions.assertEquals(0, doubleCompare.applyAsInt(Double.NaN, Double.NaN));
227+
Assertions.assertEquals(0, doubleCompare.applyAsInt(1.0, 1.0));
228228
}
229229

230230
interface DoubleToIntBiFunction {

0 commit comments

Comments
 (0)