lots of exercises in java... from https://github.com/exercism/java

BinaryTest.java 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import org.junit.Test;
  2. import org.junit.runner.RunWith;
  3. import org.junit.runners.Parameterized;
  4. import org.junit.runners.Parameterized.Parameters;
  5. import java.util.Arrays;
  6. import java.util.Collection;
  7. import static org.junit.Assert.assertEquals;
  8. @RunWith(Parameterized.class)
  9. public class BinaryTest {
  10. private String input;
  11. private int expectedOutput;
  12. @Parameters
  13. public static Collection<Object[]> data() {
  14. return Arrays.asList(new Object[][]{
  15. {"1", 1},
  16. {"10", 2},
  17. {"11", 3},
  18. {"100", 4},
  19. {"1001", 9},
  20. {"11010", 26},
  21. {"10001101000", 1128},
  22. {"2", 0},
  23. {"5", 0},
  24. {"9", 0},
  25. {"134678", 0},
  26. {"abc10z", 0},
  27. {"011", 3}
  28. });
  29. }
  30. public BinaryTest(String input, int expectedOutput) {
  31. this.input = input;
  32. this.expectedOutput = expectedOutput;
  33. }
  34. @Test
  35. public void test() {
  36. Binary binary = new Binary(input);
  37. assertEquals(expectedOutput, binary.getDecimal());
  38. }
  39. }