BAEL-3191 - review changes
This commit is contained in:
parent
dd5a432614
commit
b7368cb6db
@ -10,8 +10,8 @@ class BaeldungCategory {
|
|||||||
return capitalizedStr
|
return capitalizedStr
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Number square(Number self) {
|
public static double toThePower(Number self, Number exponent) {
|
||||||
return self*self;
|
return Math.pow(self, exponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,9 @@ class NumberCategory {
|
|||||||
return this*this*this
|
return this*this*this
|
||||||
}
|
}
|
||||||
|
|
||||||
public Number toThePower(Number exponent) {
|
public int divideWithRoundUp(BigDecimal divisor, boolean isRoundUp) {
|
||||||
return Math.pow(this, exponent)
|
def mathRound = isRoundUp ? BigDecimal.ROUND_UP : BigDecimal.ROUND_DOWN
|
||||||
|
return (int)new BigDecimal(this).divide(divisor, 0, mathRound)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -82,18 +82,20 @@ class CategoryUnitTest extends GroovyTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_whenUsingBaeldungCategory_thenSquareNumber() {
|
void test_whenUsingBaeldungCategory_thenOperationsOnNumber() {
|
||||||
use (BaeldungCategory) {
|
use (BaeldungCategory) {
|
||||||
assert 50.square() == 2500
|
assert 50.toThePower(2) == 2500
|
||||||
assert 20.01.square() == 400.4001
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_whenUsingNumberUtils_thenCubeNumber() {
|
|
||||||
use (NumberCategory) {
|
|
||||||
assert 3.cube() == 27
|
|
||||||
assert 2.4.toThePower(4) == 33.1776
|
assert 2.4.toThePower(4) == 33.1776
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_whenUsingNumberCategory_thenOperationsOnNumber() {
|
||||||
|
use (NumberCategory) {
|
||||||
|
assert 3.cube() == 27
|
||||||
|
assert 25.divideWithRoundUp(6, true) == 5
|
||||||
|
assert 120.23.divideWithRoundUp(6.1, true) == 20
|
||||||
|
assert 150.9.divideWithRoundUp(12.1, false) == 12
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user