ItEr51S04ValidacionEProbasFuncionaisItEr50S04: Fixed division by zero problem with task of 0 hours.
This commit is contained in:
parent
1d2356dd44
commit
2a0050439b
2 changed files with 14 additions and 2 deletions
|
|
@ -47,8 +47,9 @@ public class ProportionalDistributor {
|
|||
BigDecimal total = new BigDecimal(initialTotal);
|
||||
BigDecimal[] result = new BigDecimal[shares.length];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = new BigDecimal(shares[i]).divide(total, 4,
|
||||
RoundingMode.DOWN);
|
||||
result[i] = (total.equals(BigDecimal.ZERO)) ? BigDecimal.ZERO
|
||||
: new BigDecimal(shares[i]).divide(total, 4,
|
||||
RoundingMode.DOWN);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,5 +125,16 @@ public class ProportionalDistributorTest {
|
|||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notThrowDivisionByZeroException() {
|
||||
ProportionalDistributor.create(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notThrowDivisionByZeroExceptionAtDistributeMehtod() {
|
||||
ProportionalDistributor distributor = ProportionalDistributor
|
||||
.create(100);
|
||||
distributor.distribute(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue