TriangleUtilitiesTest.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. System.out.println(actual);
  44. Assert.assertEquals(expected, actual);
  45. }
  46. @Test
  47. public void testGetTriangle_ForBigTriangle() {
  48. String expected =
  49. "*\n" +
  50. "**\n" +
  51. "***\n" +
  52. "****\n" +
  53. "*****\n" +
  54. "******\n" +
  55. "*******\n" +
  56. "********\n" +
  57. "*********\n" +
  58. "**********\n";
  59. String actual = TriangleUtilities.getTriangle(10);
  60. Assert.assertEquals(expected, actual);
  61. }
  62. @Test
  63. public void testGetLargeTriangle() {
  64. String expected =
  65. "*\n" +
  66. "**\n" +
  67. "***\n" +
  68. "****\n" +
  69. "*****\n" +
  70. "******\n" +
  71. "*******\n" +
  72. "********\n" +
  73. "*********\n";
  74. String actual = TriangleUtilities.getLargeTriangle();
  75. Assert.assertEquals(expected, actual);
  76. }
  77. @Test
  78. public void testGetSmallTriangle() {
  79. String expected =
  80. "*\n" +
  81. "**\n" +
  82. "***\n" +
  83. "****\n";
  84. String actual = TriangleUtilities.getSmallTriangle();
  85. Assert.assertEquals(expected, actual);
  86. }
  87. }