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

DiamondPrinterTest.java 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 testFourByFourDiamond() {
  41. List<String> output = diamondPrinter.printToList('D');
  42. assertThat(output, is(asList(" A ",
  43. " B B ",
  44. " C C ",
  45. "D D",
  46. " C C ",
  47. " B B ",
  48. " A ")));
  49. }
  50. @Ignore("Remove to run test")
  51. @Test
  52. public void testFullDiamond() {
  53. List<String> output = diamondPrinter.printToList('Z');
  54. assertThat(output, is(asList(" A ",
  55. " B B ",
  56. " C C ",
  57. " D D ",
  58. " E E ",
  59. " F F ",
  60. " G G ",
  61. " H H ",
  62. " I I ",
  63. " J J ",
  64. " K K ",
  65. " L L ",
  66. " M M ",
  67. " N N ",
  68. " O O ",
  69. " P P ",
  70. " Q Q ",
  71. " R R ",
  72. " S S ",
  73. " T T ",
  74. " U U ",
  75. " V V ",
  76. " W W ",
  77. " X X ",
  78. " Y Y ",
  79. "Z Z",
  80. " Y Y ",
  81. " X X ",
  82. " W W ",
  83. " V V ",
  84. " U U ",
  85. " T T ",
  86. " S S ",
  87. " R R ",
  88. " Q Q ",
  89. " P P ",
  90. " O O ",
  91. " N N ",
  92. " M M ",
  93. " L L ",
  94. " K K ",
  95. " J J ",
  96. " I I ",
  97. " H H ",
  98. " G G ",
  99. " F F ",
  100. " E E ",
  101. " D D ",
  102. " C C ",
  103. " B B ",
  104. " A ")));
  105. }
  106. }