TriangleUtilitiesTest.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import org.junit.Assert;
  2. import org.junit.Test;
  3. public class TriangleUtilitiesTest {
  4. @Test
  5. public void testGetRow_ForSmallWidth(){
  6. //Given
  7. String expected = "*";
  8. int width = 1;
  9. //When
  10. String actual = TriangleUtilities.getRow(width);
  11. //Then
  12. Assert.assertEquals(expected, actual);
  13. }
  14. @Test
  15. public void testGetRow_ForBigWidth() {
  16. //Given
  17. String expected = "********************";
  18. int width = 20;
  19. //When
  20. String actual = TriangleUtilities.getRow(width);
  21. //Then
  22. Assert.assertEquals(expected, actual);
  23. }
  24. @Test
  25. public void testGetTriangle_ForOneRow() {
  26. // Given
  27. String expected = "*\n";
  28. // When
  29. String actual = TriangleUtilities.getTriangle(1);
  30. // Then
  31. Assert.assertEquals(expected, actual);
  32. }
  33. @Test
  34. public void testGetTriangle_ForSmallTriangle() {
  35. // Given
  36. String expected =
  37. "*\n" +
  38. "**\n" +
  39. "***\n";
  40. // When
  41. String actual = TriangleUtilities.getTriangle(3);
  42. // Then
  43. Assert.assertEquals(expected, actual);
  44. }
  45. @Test
  46. public void testGetTriangle_ForBigTriangle() {
  47. String expected =
  48. "*\n" +
  49. "**\n" +
  50. "***\n" +
  51. "****\n" +
  52. "*****\n" +
  53. "******\n" +
  54. "*******\n" +
  55. "********\n" +
  56. "*********\n" +
  57. "**********\n";
  58. String actual = TriangleUtilities.getTriangle(10);
  59. Assert.assertEquals(expected, actual);
  60. }
  61. @Test
  62. public void testGetLargeTriangle() {
  63. String expected =
  64. "*\n" +
  65. "**\n" +
  66. "***\n" +
  67. "****\n" +
  68. "*****\n" +
  69. "******\n" +
  70. "*******\n" +
  71. "********\n" +
  72. "*********\n";
  73. String actual = TriangleUtilities.getLargeTriangle();
  74. Assert.assertEquals(expected, actual);
  75. }
  76. @Test
  77. public void testGetSmallTriangle() {
  78. String expected =
  79. "*\n" +
  80. "**\n" +
  81. "***\n" +
  82. "****\n";
  83. String actual = TriangleUtilities.getSmallTriangle();
  84. Assert.assertEquals(expected, actual);
  85. }
  86. @Test
  87. public void test()
  88. {
  89. }
  90. }