Skip to content

Commit

Permalink
Criação de novos casos de testes.
Browse files Browse the repository at this point in the history
  • Loading branch information
wegneto committed Apr 20, 2015
1 parent 1e4ffcf commit 4a65242
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
22 changes: 19 additions & 3 deletions codejam/src/main/java/codejam/Milkshakes.java
Expand Up @@ -2,8 +2,24 @@

public class Milkshakes {

public String getBatches() {
return "Case #1: 1 0 0 0 0";
}
public String getBatches(int numFlavors, int numCustomers, int[][] customerFlavors) {
int[] result = new int[numFlavors];

for (int customer = 0; customer < numCustomers; customer++) {
for (int flavor = 0; flavor < numFlavors; flavor++) {
for (int i = 0; i < customerFlavors[customer].length; i = i + 2) {
if (customerFlavors[customer][i] == (flavor + 1)) {
result[flavor] = customerFlavors[customer][i + 1];
}
}
}
}

StringBuilder output = new StringBuilder();
for (int i = 0; i < result.length; i++) {
output.append(result[i]).append(" ");
}

return "Case #1: " + output.toString();
}
}
30 changes: 24 additions & 6 deletions codejam/src/test/java/codejam/MilkshakesTest.java
Expand Up @@ -7,15 +7,33 @@
public class MilkshakesTest {

@Test
public void getBatchesForThreeClientsAndFiveFlavors() {
String output = (new Milkshakes()).getBatches();
assertEquals("Case #1: 1 0 0 0 0", output);
public void getBatchesForOneClientThatLikeOneFlavorUnmalted() {
String output = (new Milkshakes()).getBatches(1, 1, new int[][] { { 1, 0 } });
assertEquals("Case #1: 0 ", output);
}

@Test
public void getBatchesForOneClientThatLikeTwoFlavorsUnmalted() {
String output = (new Milkshakes()).getBatches(2, 1, new int[][] { { 1, 0, 2, 0 } });
assertEquals("Case #1: 0 0 ", output);
}

@Test
public void getBatchesForOneClientThatLikeTwoFlavorsOneMaltedBetweenFiveFlavors() {
String output = (new Milkshakes()).getBatches(5, 1, new int[][] { { 1, 0, 4, 1 } });
assertEquals("Case #1: 0 0 0 1 0 ", output);
}

@Test
public void getBatchesForTwoClientsThatLikeThreeFlavorsBetweenFiveFlavors() {
String output = (new Milkshakes()).getBatches(5, 2, new int[][] { { 1, 0 }, { 2, 0, 4, 0 } });
assertEquals("Case #1: 0 0 0 0 0 ", output);
}

@Test
public void getBatchesForTwoClientsOneFlavorOneMalted() {
String output = (new Milkshakes()).getBatches();
assertEquals("Case #1: IMPOSSIBLE", output);
public void getBatchesForTwoClientsThatLikeFourFlavorsOneMaltedBetweenFiveFlavors() {
String output = (new Milkshakes()).getBatches(5, 2, new int[][] { { 1, 0, 3, 1 }, { 2, 0, 4, 0 } });
assertEquals("Case #1: 0 0 1 0 0 ", output);
}

}

0 comments on commit 4a65242

Please sign in to comment.