1
1
package com .github .streams .learn .functional_interfaces ;
2
2
3
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
4
+
3
5
import com .github .streams .learn .functional_interfaces .ignore .models .Person ;
6
+ import java .util .Comparator ;
7
+ import java .util .function .IntBinaryOperator ;
4
8
import org .junit .jupiter .api .Assertions ;
5
9
import org .junit .jupiter .api .Disabled ;
6
10
import org .junit .jupiter .api .Test ;
7
11
8
- import java .util .Comparator ;
9
- import java .util .function .IntBinaryOperator ;
10
-
11
- import static org .junit .jupiter .api .Assertions .assertFalse ;
12
-
13
12
class F_ComparatorTest {
14
13
15
14
final Person ayman = new Person ("Ayman" , "Khan" , 51 );
@@ -24,12 +23,12 @@ class F_ComparatorTest {
24
23
*/
25
24
@ Test
26
25
@ Disabled
27
- void comparator01 () {
26
+ void comparator01 () {
28
27
Comparator <String > compareByLength = null ; // TODO
29
28
30
29
Assertions .assertTrue (compareByLength .compare ("FOUR" , "TWO" ) > 0 );
31
30
Assertions .assertTrue (compareByLength .compare ("ONE" , "SEVEN" ) < 0 );
32
- Assertions .assertTrue ( compareByLength .compare ("ONE" , "TWO" ) == 0 );
31
+ Assertions .assertEquals ( 0 , compareByLength .compare ("ONE" , "TWO" ));
33
32
}
34
33
35
34
// Hint:
@@ -45,14 +44,14 @@ void comparator01() {
45
44
*/
46
45
@ Test
47
46
@ Disabled
48
- void comparator02 () {
47
+ void comparator02 () {
49
48
Comparator <String > compareByLengthThenAlphabetical = null ; // TODO
50
49
51
50
Assertions .assertTrue (compareByLengthThenAlphabetical .compare ("FOUR" , "TWO" ) > 0 );
52
51
Assertions .assertTrue (compareByLengthThenAlphabetical .compare ("ONE" , "SEVEN" ) < 0 );
53
52
Assertions .assertTrue (compareByLengthThenAlphabetical .compare ("ONE" , "TWO" ) < 0 );
54
53
Assertions .assertTrue (compareByLengthThenAlphabetical .compare ("FOUR" , "FIVE" ) > 0 );
55
- Assertions .assertTrue ( compareByLengthThenAlphabetical .compare ("EIGHT" , "EIGHT" ) == 0 );
54
+ Assertions .assertEquals ( 0 , compareByLengthThenAlphabetical .compare ("EIGHT" , "EIGHT" ));
56
55
}
57
56
58
57
// Hint:
@@ -66,12 +65,12 @@ void comparator02() {
66
65
/** Write a Comparator that compares instances of Person using their lastName. */
67
66
@ Test
68
67
@ Disabled
69
- void comparator03 () {
68
+ void comparator03 () {
70
69
Comparator <Person > comparebyLastName = null ; // TODO
71
70
72
71
Assertions .assertTrue (comparebyLastName .compare (ayman , rod ) < 0 );
73
- Assertions .assertTrue (comparebyLastName .compare (paul , paul ) == 0 );
74
72
Assertions .assertTrue (comparebyLastName .compare (ayman , jermaine ) > 0 );
73
+ Assertions .assertEquals (0 , comparebyLastName .compare (paul , paul ));
75
74
}
76
75
77
76
// Hint:
@@ -87,12 +86,12 @@ void comparator03() {
87
86
*/
88
87
@ Test
89
88
@ Disabled
90
- void comparator04 () {
89
+ void comparator04 () {
91
90
Comparator <Person > comparebyLastNameThenFirstName = null ; // TODO
92
91
93
92
Assertions .assertTrue (comparebyLastNameThenFirstName .compare (ayman , rod ) < 0 );
94
- Assertions .assertTrue (comparebyLastNameThenFirstName .compare (paul , paul ) == 0 );
95
93
Assertions .assertTrue (comparebyLastNameThenFirstName .compare (ayman , jermaine ) > 0 );
94
+ Assertions .assertEquals (0 , comparebyLastNameThenFirstName .compare (paul , paul ));
96
95
}
97
96
98
97
// Hint:
@@ -108,12 +107,12 @@ void comparator04() {
108
107
*/
109
108
@ Test
110
109
@ Disabled
111
- void comparator05 () {
110
+ void comparator05 () {
112
111
Comparator <Person > comparebyLastNameThenFirstNameReversed = null ; // TODO
113
112
114
113
assertFalse (comparebyLastNameThenFirstNameReversed .compare (ayman , rod ) < 0 );
115
- Assertions .assertTrue (comparebyLastNameThenFirstNameReversed .compare (paul , paul ) == 0 );
116
114
assertFalse (comparebyLastNameThenFirstNameReversed .compare (ayman , jermaine ) > 0 );
115
+ Assertions .assertEquals (0 , comparebyLastNameThenFirstNameReversed .compare (paul , paul ));
117
116
}
118
117
119
118
// Hint:
@@ -128,14 +127,14 @@ void comparator05() {
128
127
*/
129
128
@ Test
130
129
@ Disabled
131
- void comparator06 () {
130
+ void comparator06 () {
132
131
Comparator <Person > comparebyLastNameThenFirstNameWithNull = null ; // TODO
133
132
134
133
Assertions .assertTrue (comparebyLastNameThenFirstNameWithNull .compare (ayman , rod ) < 0 );
135
- Assertions .assertTrue (comparebyLastNameThenFirstNameWithNull .compare (paul , paul ) == 0 );
136
134
Assertions .assertTrue (comparebyLastNameThenFirstNameWithNull .compare (ayman , jermaine ) > 0 );
137
135
Assertions .assertTrue (comparebyLastNameThenFirstNameWithNull .compare (mick , null ) < 0 );
138
136
Assertions .assertTrue (comparebyLastNameThenFirstNameWithNull .compare (null , mick ) > 0 );
137
+ Assertions .assertEquals (0 , comparebyLastNameThenFirstNameWithNull .compare (paul , paul ));
139
138
}
140
139
141
140
// Hint:
@@ -149,12 +148,12 @@ void comparator06() {
149
148
*/
150
149
@ Test
151
150
@ Disabled
152
- void comparator07 () {
151
+ void comparator07 () {
153
152
Comparator <Person > comparebyAge = null ; // TODO
154
153
155
154
Assertions .assertTrue (comparebyAge .compare (ayman , rod ) < 0 );
156
- Assertions .assertTrue (comparebyAge .compare (paul , paul ) == 0 );
157
155
Assertions .assertTrue (comparebyAge .compare (mick , jermaine ) > 0 );
156
+ Assertions .assertEquals (0 , comparebyAge .compare (paul , paul ));
158
157
}
159
158
160
159
// Hint:
@@ -171,14 +170,14 @@ void comparator07() {
171
170
*/
172
171
@ Test
173
172
@ Disabled
174
- void comparator08 () {
173
+ void comparator08 () {
175
174
IntBinaryOperator intCompare = null ; // TODO
176
175
177
176
Assertions .assertTrue (intCompare .applyAsInt (0 , 1 ) < 0 );
178
- Assertions .assertTrue (intCompare .applyAsInt (1 , 1 ) == 0 );
179
177
Assertions .assertTrue (intCompare .applyAsInt (2 , 1 ) > 0 );
180
178
Assertions .assertTrue (intCompare .applyAsInt (Integer .MIN_VALUE , Integer .MAX_VALUE ) < 0 );
181
179
Assertions .assertTrue (intCompare .applyAsInt (Integer .MAX_VALUE , Integer .MIN_VALUE ) > 0 );
180
+ Assertions .assertEquals (0 , intCompare .applyAsInt (1 , 1 ));
182
181
}
183
182
184
183
// Hint:
@@ -192,7 +191,7 @@ void comparator08() {
192
191
*/
193
192
@ Test
194
193
@ Disabled
195
- void comparator09 () {
194
+ void comparator09 () {
196
195
IntBinaryOperator intCompare = null ; // TODO
197
196
198
197
Assertions .assertTrue (intCompare .applyAsInt (0 , 1 ) < 0 );
@@ -216,15 +215,16 @@ void comparator09() {
216
215
*/
217
216
@ Test
218
217
@ Disabled
219
- void comparator10 () {
218
+ void comparator10 () {
220
219
DoubleToIntBiFunction doubleCompare = null ; // TODO
221
220
222
221
Assertions .assertTrue (doubleCompare .applyAsInt (0.0 , 1.0 ) < 0 );
223
- Assertions .assertTrue (doubleCompare .applyAsInt (1.0 , 1.0 ) == 0 );
224
222
Assertions .assertTrue (doubleCompare .applyAsInt (2.0 , 1.0 ) > 0 );
225
- Assertions .assertTrue (doubleCompare .applyAsInt (Double .NaN , Double .NaN ) == 0 );
226
223
Assertions .assertTrue (doubleCompare .applyAsInt (Double .NaN , 0.0 ) > 0 );
227
224
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 ));
228
228
}
229
229
230
230
interface DoubleToIntBiFunction {
0 commit comments