ItEr25S07CUAsignacionGrupoRecursosAPlanificacionItEr24S08: Adding method to know the difference between two share divisions of same number of elements
This commit is contained in:
parent
9960989dd6
commit
46edafb2d3
2 changed files with 25 additions and 0 deletions
|
|
@ -170,4 +170,14 @@ public class ShareDivision {
|
|||
return shares.toString();
|
||||
}
|
||||
|
||||
public int[] to(ShareDivision newDivison) {
|
||||
Validate.isTrue(shares.size() == newDivison.shares.size());
|
||||
int[] result = new int[shares.size()];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = newDivison.shares.get(i).getHours()
|
||||
- shares.get(i).getHours();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,6 +108,21 @@ public class ShareDivisionTest {
|
|||
assertThat(shareDivision.plus(12), haveValues(2, 2, 2));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void cantKnowTheDifferenceBetweenTwoDivisionsOfDifferentNumberOfShares(){
|
||||
givenDivisionShare(new Share(2), new Share(-5), new Share(-3));
|
||||
shareDivision.to(ShareDivision.create(Arrays.asList(new Share(2),
|
||||
new Share(1))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canKnowTheDifferenceBetweenTwoDivisions() {
|
||||
givenDivisionShare(new Share(2), new Share(-5), new Share(-3));
|
||||
int[] difference = shareDivision.to(ShareDivision.create(Arrays.asList(
|
||||
new Share(1), new Share(1), new Share(-2))));
|
||||
assertTrue(Arrays.equals(difference, new int[] { -1, 6, 1 }));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("TODO handling substractions")
|
||||
public void canDistributeSubstraction() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue