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

DiamondPrinterTest.java 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import org.junit.Ignore;
  2. import org.junit.Before;
  3. import org.junit.Test;
  4. import java.util.List;
  5. import static java.util.Arrays.asList;
  6. import static java.util.Collections.singletonList;
  7. import static org.hamcrest.CoreMatchers.is;
  8. import static org.junit.Assert.assertThat;
  9. public class DiamondPrinterTest {
  10. private DiamondPrinter diamondPrinter;
  11. @Before
  12. public void setUp() {
  13. diamondPrinter = new DiamondPrinter();
  14. }
  15. @Test
  16. public void testOneByOneDiamond() {
  17. List<String> output = diamondPrinter.printToList('A');
  18. assertThat(output, is(singletonList("A")));
  19. }
  20. @Ignore("Remove to run test")
  21. @Test
  22. public void testTwoByTwoDiamond() {
  23. List<String> output = diamondPrinter.printToList('B');
  24. assertThat(output, is(asList(" A ",
  25. "B B",
  26. " A ")));
  27. }
  28. @Ignore("Remove to run test")
  29. @Test
  30. public void testThreeByThreeDiamond() {
  31. List<String> output = diamondPrinter.printToList('C');
  32. assertThat(output, is(asList(" A ",
  33. " B B ",
  34. "C C",
  35. " B B ",
  36. " A ")));
  37. }
  38. @Ignore("Remove to run test")
  39. @Test
  40. public void testFiveByFiveDiamond() {
  41. List<String> output = diamondPrinter.printToList('E');
  42. assertThat(output, is(asList(" A ",
  43. " B B ",
  44. " C C ",
  45. " D D ",
  46. "E E",
  47. " D D ",
  48. " C C ",
  49. " B B ",
  50. " A ")));
  51. }
  52. @Ignore("Remove to run test")
  53. @Test
  54. public void testFullDiamond() {
  55. List<String> output = diamondPrinter.printToList('Z');
  56. assertThat(output, is(asList(" A ",
  57. " B B ",
  58. " C C ",
  59. " D D ",
  60. " E E ",
  61. " F F ",
  62. " G G ",
  63. " H H ",
  64. " I I ",
  65. " J J ",
  66. " K K ",
  67. " L L ",
  68. " M M ",
  69. " N N ",
  70. " O O ",
  71. " P P ",
  72. " Q Q ",
  73. " R R ",
  74. " S S ",
  75. " T T ",
  76. " U U ",
  77. " V V ",
  78. " W W ",
  79. " X X ",
  80. " Y Y ",
  81. "Z Z",
  82. " Y Y ",
  83. " X X ",
  84. " W W ",
  85. " V V ",
  86. " U U ",
  87. " T T ",
  88. " S S ",
  89. " R R ",
  90. " Q Q ",
  91. " P P ",
  92. " O O ",
  93. " N N ",
  94. " M M ",
  95. " L L ",
  96. " K K ",
  97. " J J ",
  98. " I I ",
  99. " H H ",
  100. " G G ",
  101. " F F ",
  102. " E E ",
  103. " D D ",
  104. " C C ",
  105. " B B ",
  106. " A ")));
  107. }
  108. }