ItEr58S04ValidacionEProbasFuncionaisItEr57S04: [Bug #470] Fix bug.
If shares are zero, the remainder can be bigger than the number of shares
This commit is contained in:
parent
1461d5d01d
commit
9bcc65b0ef
2 changed files with 11 additions and 1 deletions
|
|
@ -117,7 +117,8 @@ public class ProportionalDistributor {
|
|||
.transform(difference(currentProportions));
|
||||
Collections.sort(transform, Collections.reverseOrder());
|
||||
for (int i = 0; i < remaining; i++) {
|
||||
ProportionWithPosition proportionWithPosition = transform.get(i);
|
||||
ProportionWithPosition proportionWithPosition = transform.get(i
|
||||
% currentProportions.length);
|
||||
result[proportionWithPosition.position] = result[proportionWithPosition.position] + 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,15 @@ public class ProportionalDistributorTest {
|
|||
assertThat(distributor.distribute(100), equalToDistribution(50, 50, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifNoSharesProvidedItDistributesEqually() {
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(0,
|
||||
0, 0, 0);
|
||||
assertThat(distributor.distribute(4), equalToDistribution(1, 1, 1, 1));
|
||||
assertThat(distributor.distribute(5), equalToDistribution(2, 1, 1, 1));
|
||||
assertThat(distributor.distribute(6), equalToDistribution(2, 2, 1, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disputedPartGoesToFirstIfEqualWeight() {
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue