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

RectangleCounterTest.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import org.junit.Before;
  2. import org.junit.Ignore;
  3. import org.junit.Test;
  4. import static org.junit.Assert.assertEquals;
  5. public class RectangleCounterTest {
  6. private RectangleCounter rectangleCounter;
  7. @Before
  8. public void setUp() {
  9. rectangleCounter = new RectangleCounter();
  10. }
  11. @Test
  12. public void testInputWithNoColumnsContainsNoRectangles() {
  13. String[] inputGrid = new String[]{};
  14. assertEquals(0, rectangleCounter.countRectangles(inputGrid));
  15. }
  16. @Ignore("Remove to run test")
  17. @Test
  18. public void testNonTrivialInputWithNoRectangles() {
  19. String[] inputGrid = new String[]{" "};
  20. assertEquals(0, rectangleCounter.countRectangles(inputGrid));
  21. }
  22. @Ignore("Remove to run test")
  23. @Test
  24. public void testInputWithOneRectangle() {
  25. String[] inputGrid = new String[]{
  26. "+-+",
  27. "| |",
  28. "+-+"
  29. };
  30. assertEquals(1, rectangleCounter.countRectangles(inputGrid));
  31. }
  32. @Ignore("Remove to run test")
  33. @Test
  34. public void testInputWithTwoRectanglesWithoutSharedEdges() {
  35. String[] inputGrid = new String[]{
  36. " +-+",
  37. " | |",
  38. "+-+-+",
  39. "| | ",
  40. "+-+ "
  41. };
  42. assertEquals(2, rectangleCounter.countRectangles(inputGrid));
  43. }
  44. @Ignore("Remove to run test")
  45. @Test
  46. public void testInputWithFiveRectanglesWithSharedEdges() {
  47. String[] inputGrid = new String[]{
  48. " +-+",
  49. " | |",
  50. "+-+-+",
  51. "| | |",
  52. "+-+-+"
  53. };
  54. assertEquals(5, rectangleCounter.countRectangles(inputGrid));
  55. }
  56. @Ignore("Remove to run test")
  57. @Test
  58. public void testThatRectangleOfHeightOneIsCounted() {
  59. String[] inputGrid = new String[]{
  60. "+--+",
  61. "+--+"
  62. };
  63. assertEquals(1, rectangleCounter.countRectangles(inputGrid));
  64. }
  65. @Ignore("Remove to run test")
  66. @Test
  67. public void testThatRectangleOfWidthOneIsCounted() {
  68. String[] inputGrid = new String[]{
  69. "++",
  70. "||",
  71. "++"
  72. };
  73. assertEquals(1, rectangleCounter.countRectangles(inputGrid));
  74. }
  75. @Ignore("Remove to run test")
  76. @Test
  77. public void testThatOneByOneSquareIsCounted() {
  78. String[] inputGrid = new String[]{
  79. "++",
  80. "++"
  81. };
  82. assertEquals(1, rectangleCounter.countRectangles(inputGrid));
  83. }
  84. @Ignore("Remove to run test")
  85. @Test
  86. public void testThatIncompleteRectanglesAreNotCounted() {
  87. String[] inputGrid = new String[]{
  88. " +-+",
  89. " |",
  90. "+-+-+",
  91. "| | -",
  92. "+-+-+"
  93. };
  94. assertEquals(1, rectangleCounter.countRectangles(inputGrid));
  95. }
  96. @Ignore("Remove to run test")
  97. @Test
  98. public void testThatRectanglesOfDifferentSizesAreAllCounted() {
  99. String[] inputGrid = new String[]{
  100. "+------+----+",
  101. "| | |",
  102. "+---+--+ |",
  103. "| | |",
  104. "+---+-------+"
  105. };
  106. assertEquals(3, rectangleCounter.countRectangles(inputGrid));
  107. }
  108. @Ignore("Remove to run test")
  109. @Test
  110. public void testThatIntersectionsWithoutCornerCharacterDoNotCountAsRectangleCorners() {
  111. String[] inputGrid = new String[]{
  112. "+------+----+",
  113. "| | |",
  114. "+------+ |",
  115. "| | |",
  116. "+---+-------+"
  117. };
  118. assertEquals(2, rectangleCounter.countRectangles(inputGrid));
  119. }
  120. @Ignore("Remove to run test")
  121. @Test
  122. public void testLargeInputWithManyRectangles() {
  123. String[] inputGrid = new String[]{
  124. "+---+--+----+",
  125. "| +--+----+",
  126. "+---+--+ |",
  127. "| +--+----+",
  128. "+---+--+--+-+",
  129. "+---+--+--+-+",
  130. "+------+ | |",
  131. " +-+"
  132. };
  133. assertEquals(60, rectangleCounter.countRectangles(inputGrid));
  134. }
  135. }