Skip to content

Commit 98deba1

Browse files
committedDec 30, 2018
strategy: naming
1 parent 2c76d79 commit 98deba1

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed
 

‎src/main/java/strategy/Calculator.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
class Calculator {
1717
PriceProvider priceProvider;
1818

19-
int totalValues(List<Stock> integers, IntPredicate take) {
19+
int sumPrices(List<Stock> integers, IntPredicate take) {
2020
return integers.stream()
2121
.map(Stock::getId)
2222
.mapToInt(priceProvider::getPrice)
2323
.filter(take)
2424
.sum();
2525
}
26-
27-
// library of functions
26+
2827
static IntPredicate priceLessThan(int limit) {
2928
return it -> it < limit;
3029
}

‎src/test/groovy/strategy/CalculatorTest.groovy

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import java.util.function.IntUnaryOperator
99
*/
1010
class CalculatorTest extends Specification {
1111

12-
def "test totalValues < 4"() {
12+
def "test sumPrices; prices < 4"() {
1313
given:
1414
def stocks = [new Stock(1),
1515
new Stock(2),
@@ -22,13 +22,13 @@ class CalculatorTest extends Specification {
2222
def calculator = new Calculator(new PriceProvider(IntUnaryOperator.identity()))
2323

2424
when:
25-
def sum = calculator.totalValues(stocks, Calculator.priceLessThan(4))
25+
def sum = calculator.sumPrices(stocks, Calculator.priceLessThan(4))
2626

2727
then:
2828
sum == 6
2929
}
3030

31-
def "test totalValues <= 5"() {
31+
def "test sumPrices, prices < 3 or prices == 5"() {
3232
given:
3333
def stocks = [new Stock(1),
3434
new Stock(2),
@@ -41,7 +41,7 @@ class CalculatorTest extends Specification {
4141
def calculator = new Calculator(new PriceProvider(IntUnaryOperator.identity()))
4242

4343
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))
4545

4646
then:
4747
sum == 8

0 commit comments

Comments
 (0)
Failed to load comments.