Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public double calculate(double firstOperand, double secondOperand, char operator
case ':':{
return divide(firstOperand,secondOperand);
}
case '^':{
return square(firstOperand);
}
default:
throw new IllegalArgumentException("Unsupported operation :"+operator);
}
Expand All @@ -37,4 +40,8 @@ private double subtract(double firstOperand, double secondOperand) {
private double add(double firstOperand, double secondOperand) {
return firstOperand + secondOperand;
}

private double square(double x) {
return x * x;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ void divideSimple(){
double result = calculator.calculate(1,1,':');
Assertions.assertEquals(1,result);
}

@Test
void squareSimple(){
// the signature isn't flexible so we repeat the same number twice
double result = calculator.calculate(10, 10, '^');
Assertions.assertEquals(100.0,result);
}

}
Loading