@@ -34,7 +34,7 @@ class MinByMaxByTest {
34
34
* Any other exception is propagated.
35
35
*/
36
36
def assertThrows [T <: Throwable : ClassTag ](body : => Any ,
37
- checkMessage : String => Boolean = s => true ): Unit = {
37
+ checkMessage : String => Boolean = s => true ): Unit = {
38
38
assertThrown[T ](t => checkMessage(t.getMessage))(body)
39
39
}
40
40
@@ -49,7 +49,8 @@ class MinByMaxByTest {
49
49
ae.addSuppressed(failed)
50
50
throw ae
51
51
case NonFatal (other) =>
52
- val ae = new AssertionError (s " Wrong exception: expected ${implicitly[ClassTag [T ]]} but was ${other.getClass.getName}" )
52
+ val ae = new AssertionError (
53
+ s " Wrong exception: expected ${implicitly[ClassTag [T ]]} but was ${other.getClass.getName}" )
53
54
ae.addSuppressed(other)
54
55
throw ae
55
56
}
@@ -65,21 +66,27 @@ class MinByMaxByTest {
65
66
@ Test
66
67
def testCorrectness () = {
67
68
def f (x : Int ) = - 1 * x
68
- val max = list.maxBy(f)
69
- assertTrue(" f(list.maxBy(f)) should ≥ f(x) where x is any element of list." , list.forall(f(_) <= f(max)))
69
+ val max = list.maxBy(f)
70
+ assertTrue(" f(list.maxBy(f)) should ≥ f(x) where x is any element of list." ,
71
+ list.forall(f(_) <= f(max)))
70
72
val min = list.minBy(f)
71
- assertTrue(" f(list.minBy(f)) should ≤ f(x) where x is any element of list." , list.forall(f(_) >= f(min)))
73
+ assertTrue(" f(list.minBy(f)) should ≤ f(x) where x is any element of list." ,
74
+ list.forall(f(_) >= f(min)))
72
75
}
73
76
74
77
// Ensure that it always returns the first match if more than one element have the same largest/smallest f(x).
75
- // Note that this behavior is not explicitly stated before.
78
+ // Note that this behavior is not explicitly stated before.
76
79
// To make it compatible with the previous implementation, I add this behavior to docs.
77
80
@ Test
78
81
def testReturnTheFirstMatch () = {
79
- val d = List (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 )
82
+ val d = List (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 )
80
83
def f (x : Int ) = x % 3 ;
81
- assert(d.maxBy(f) == 2 , " If multiple elements evaluated to the largest value, maxBy should return the first one." )
82
- assert(d.minBy(f) == 3 , " If multiple elements evaluated to the largest value, minBy should return the first one." )
84
+ assert(
85
+ d.maxBy(f) == 2 ,
86
+ " If multiple elements evaluated to the largest value, maxBy should return the first one." )
87
+ assert(
88
+ d.minBy(f) == 3 ,
89
+ " If multiple elements evaluated to the largest value, minBy should return the first one." )
83
90
}
84
91
85
92
// Make sure it evaluates f no more than list.length times.
@@ -91,15 +98,19 @@ class MinByMaxByTest {
91
98
evaluatedCountOfMaxBy += 1
92
99
x * 10
93
100
})
94
- assert(evaluatedCountOfMaxBy == list.length, s " maxBy: should evaluate f only ${list.length} times, but it evaluated $evaluatedCountOfMaxBy times. " )
101
+ assert(
102
+ evaluatedCountOfMaxBy == list.length,
103
+ s " maxBy: should evaluate f only ${list.length} times, but it evaluated $evaluatedCountOfMaxBy times. " )
95
104
96
105
var evaluatedCountOfMinBy = 0
97
106
98
107
val min = list.minBy(x => {
99
108
evaluatedCountOfMinBy += 1
100
109
x * 10
101
110
})
102
- assert(evaluatedCountOfMinBy == list.length, s " minBy: should evaluate f only ${list.length} times, but it evaluated $evaluatedCountOfMinBy times. " )
111
+ assert(
112
+ evaluatedCountOfMinBy == list.length,
113
+ s " minBy: should evaluate f only ${list.length} times, but it evaluated $evaluatedCountOfMinBy times. " )
103
114
}
104
115
105
116
@ Test
@@ -125,6 +136,6 @@ class MinByMaxByTest {
125
136
assert(seq.min.isNaN)
126
137
assert(seq.max.isNaN)
127
138
}
128
- */
139
+ */
129
140
130
141
}
0 commit comments