123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import org.junit.Assert;
  2. import org.junit.Test;
  3. /**
  4. * Created by leon on 1/31/18.
  5. */
  6. public class TableUtilitiesTest {
  7. @Test
  8. public void testGetMulplicationTable_forOne(){
  9. String expected = " 1 |\n";
  10. String actual = TableUtilities.getMultiplicationTable(1);
  11. Assert.assertEquals(expected, actual);
  12. }
  13. @Test
  14. public void testGetMulplicationTable_forTwo(){
  15. String expected = " 1 | 2 |\n" +
  16. " 2 | 4 |\n";
  17. String actual = TableUtilities.getMultiplicationTable(2);
  18. Assert.assertEquals(expected, actual);
  19. }
  20. @Test
  21. public void testGetLargeMultiplicationTable() {
  22. String expected =
  23. " 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |\n" +
  24. " 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 |\n" +
  25. " 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 |\n" +
  26. " 4 | 8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | 40 |\n" +
  27. " 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 |\n" +
  28. " 6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 | 60 |\n" +
  29. " 7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 | 70 |\n" +
  30. " 8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 |\n" +
  31. " 9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 | 90 |\n" +
  32. " 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 |100 |\n";
  33. String actual = TableUtilities.getLargeMultiplicationTable();
  34. Assert.assertEquals(expected, actual);
  35. }
  36. @Test
  37. public void testGetSmallMultiplicationTable() {
  38. String expected =
  39. " 1 | 2 | 3 | 4 | 5 |\n" +
  40. " 2 | 4 | 6 | 8 | 10 |\n" +
  41. " 3 | 6 | 9 | 12 | 15 |\n" +
  42. " 4 | 8 | 12 | 16 | 20 |\n" +
  43. " 5 | 10 | 15 | 20 | 25 |\n";
  44. String actual = TableUtilities.getSmallMultiplicationTable();
  45. Assert.assertEquals(expected, actual);
  46. }
  47. @Test
  48. public void TEST() {
  49. String expected =
  50. " 1 | 2 | 3 | 4 | 5 |\n" +
  51. " 2 | 4 | 6 | 8 | 10 |\n" +
  52. " 3 | 6 | 9 | 12 | 15 |\n" +
  53. " 4 | 8 | 12 | 16 | 20 |\n" +
  54. " 5 | 10 | 15 | 20 | 25 |\n";
  55. String actual = TableUtilities.getSmallMultiplicationTable();
  56. Assert.assertEquals(expected, actual);
  57. }
  58. @Test
  59. public void testGetMultiplicationTable() {
  60. String expected =
  61. " 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |\n" +
  62. " 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 |\n" +
  63. " 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 | 33 | 36 | 39 | 42 | 45 | 48 | 51 | 54 | 57 | 60 |\n" +
  64. " 4 | 8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | 64 | 68 | 72 | 76 | 80 |\n" +
  65. " 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 |100 |\n" +
  66. " 6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 | 60 | 66 | 72 | 78 | 84 | 90 | 96 |102 |108 |114 |120 |\n" +
  67. " 7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 | 70 | 77 | 84 | 91 | 98 |105 |112 |119 |126 |133 |140 |\n" +
  68. " 8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 | 88 | 96 |104 |112 |120 |128 |136 |144 |152 |160 |\n" +
  69. " 9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 | 90 | 99 |108 |117 |126 |135 |144 |153 |162 |171 |180 |\n" +
  70. " 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 |100 |110 |120 |130 |140 |150 |160 |170 |180 |190 |200 |\n" +
  71. " 11 | 22 | 33 | 44 | 55 | 66 | 77 | 88 | 99 |110 |121 |132 |143 |154 |165 |176 |187 |198 |209 |220 |\n" +
  72. " 12 | 24 | 36 | 48 | 60 | 72 | 84 | 96 |108 |120 |132 |144 |156 |168 |180 |192 |204 |216 |228 |240 |\n" +
  73. " 13 | 26 | 39 | 52 | 65 | 78 | 91 |104 |117 |130 |143 |156 |169 |182 |195 |208 |221 |234 |247 |260 |\n" +
  74. " 14 | 28 | 42 | 56 | 70 | 84 | 98 |112 |126 |140 |154 |168 |182 |196 |210 |224 |238 |252 |266 |280 |\n" +
  75. " 15 | 30 | 45 | 60 | 75 | 90 |105 |120 |135 |150 |165 |180 |195 |210 |225 |240 |255 |270 |285 |300 |\n" +
  76. " 16 | 32 | 48 | 64 | 80 | 96 |112 |128 |144 |160 |176 |192 |208 |224 |240 |256 |272 |288 |304 |320 |\n" +
  77. " 17 | 34 | 51 | 68 | 85 |102 |119 |136 |153 |170 |187 |204 |221 |238 |255 |272 |289 |306 |323 |340 |\n" +
  78. " 18 | 36 | 54 | 72 | 90 |108 |126 |144 |162 |180 |198 |216 |234 |252 |270 |288 |306 |324 |342 |360 |\n" +
  79. " 19 | 38 | 57 | 76 | 95 |114 |133 |152 |171 |190 |209 |228 |247 |266 |285 |304 |323 |342 |361 |380 |\n" +
  80. " 20 | 40 | 60 | 80 |100 |120 |140 |160 |180 |200 |220 |240 |260 |280 |300 |320 |340 |360 |380 |400 |\n";
  81. String actual = TableUtilities.getMultiplicationTable(20);
  82. Assert.assertEquals(expected, actual);
  83. }
  84. @Test
  85. public void testStrLen()
  86. {
  87. TableUtilities tableUti1 = new TableUtilities();
  88. Assert.assertEquals(10, tableUti1.testStringLen("qwertyuiop"));
  89. }
  90. @Test
  91. public void testStrLen2()
  92. {
  93. TableUtilities tableUti1 = new TableUtilities();
  94. Assert.assertEquals(4, tableUti1.testStringLen("ðððð"));
  95. }
  96. }