2 files changed +6
-7
lines changed Original file line number Diff line number Diff line change 16
16
class Calculator {
17
17
PriceProvider priceProvider ;
18
18
19
- int totalValues (List <Stock > integers , IntPredicate take ) {
19
+ int sumPrices (List <Stock > integers , IntPredicate take ) {
20
20
return integers .stream ()
21
21
.map (Stock ::getId )
22
22
.mapToInt (priceProvider ::getPrice )
23
23
.filter (take )
24
24
.sum ();
25
25
}
26
-
27
- // library of functions
26
+
28
27
static IntPredicate priceLessThan (int limit ) {
29
28
return it -> it < limit ;
30
29
}
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import java.util.function.IntUnaryOperator
9
9
*/
10
10
class CalculatorTest extends Specification {
11
11
12
- def " test totalValues < 4" () {
12
+ def " test sumPrices; prices < 4" () {
13
13
given :
14
14
def stocks = [new Stock (1 ),
15
15
new Stock (2 ),
@@ -22,13 +22,13 @@ class CalculatorTest extends Specification {
22
22
def calculator = new Calculator (new PriceProvider (IntUnaryOperator . identity()))
23
23
24
24
when :
25
- def sum = calculator. totalValues (stocks, Calculator . priceLessThan(4 ))
25
+ def sum = calculator. sumPrices (stocks, Calculator . priceLessThan(4 ))
26
26
27
27
then :
28
28
sum == 6
29
29
}
30
30
31
- def " test totalValues < = 5" () {
31
+ def " test sumPrices, prices < 3 or prices = = 5" () {
32
32
given :
33
33
def stocks = [new Stock (1 ),
34
34
new Stock (2 ),
@@ -41,7 +41,7 @@ class CalculatorTest extends Specification {
41
41
def calculator = new Calculator (new PriceProvider (IntUnaryOperator . identity()))
42
42
43
43
when :
44
- def sum = calculator. totalValues (stocks, Calculator . priceLessThan(3 ) | Calculator . priceEquals(5 ))
44
+ def sum = calculator. sumPrices (stocks, Calculator . priceLessThan(3 ) | Calculator . priceEquals(5 ))
45
45
46
46
then :
47
47
sum == 8
0 commit comments