123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import org.junit.Assert;
  2. import org.junit.Test;
  3. public class NumberUtilitiesTest {
  4. @Test
  5. public void testGetRange1A() {
  6. // : Given
  7. String expected = "0123456789";
  8. int stop = 11;
  9. // : When
  10. String actual = NumberUtilities.getRange(stop);
  11. // : Then
  12. Assert.assertEquals(expected, actual);
  13. }
  14. @Test
  15. public void testGetRange2A() {
  16. // : Given
  17. String expected = "01234";
  18. int stop = 5;
  19. // : When
  20. String actual = NumberUtilities.getRange(stop);
  21. // : Then
  22. Assert.assertEquals(expected, actual);
  23. }
  24. @Test
  25. public void testGetRange3A() {
  26. // : Given
  27. String expected = "012345678910111213141516171819";
  28. int stop = 20;
  29. // : When
  30. String actual = NumberUtilities.getRange(stop);
  31. // : Then
  32. Assert.assertEquals(expected, actual);
  33. }
  34. @Test
  35. public void testGetRange1B() {
  36. // : Given
  37. String expected = "5678910111213141516171819";
  38. int start = 5;
  39. int stop = 20;
  40. // : When
  41. String actual = NumberUtilities.getRange(start, stop);
  42. // : Then
  43. Assert.assertEquals(expected, actual);
  44. }
  45. @Test
  46. public void testGetRange2B() {
  47. // : Given
  48. String expected = "101112131415161718192021222324";
  49. int start = 10;
  50. int stop = 25;
  51. // : When
  52. String actual = NumberUtilities.getRange(start, stop);
  53. // : Then
  54. Assert.assertEquals(expected, actual);
  55. }
  56. @Test
  57. public void testGetRange3B() {
  58. // : Given
  59. String expected = "100101103104105106107108109";
  60. int start = 100;
  61. int stop = 110;
  62. // : When
  63. String actual = NumberUtilities.getRange(start, stop);
  64. // : Then
  65. Assert.assertEquals(expected, actual);
  66. }
  67. @Test
  68. public void testGetRange1C() {
  69. // : Given
  70. String expected = "51015";
  71. int start = 5;
  72. int stop = 20;
  73. int step = 5;
  74. // : When
  75. String actual = NumberUtilities.getRange(start, stop, step);
  76. // : Then
  77. Assert.assertEquals(expected, actual);
  78. }
  79. @Test
  80. public void testGetRange2C() {
  81. // : Given
  82. String expected = "012345678910111213141516171819";
  83. int start = 0;
  84. int stop = 20;
  85. int step = 1;
  86. // : When
  87. String actual = NumberUtilities.getRange(start, stop, step);
  88. // : Then
  89. Assert.assertEquals(expected, actual);
  90. }
  91. @Test
  92. public void testGetRange3C() {
  93. // : Given
  94. String expected = "0246810";
  95. int start = 0;
  96. int stop = 11;
  97. int step = 2;
  98. // : When
  99. String actual = NumberUtilities.getRange(start, stop, step);
  100. // : Then
  101. Assert.assertEquals(expected, actual);
  102. }
  103. @Test
  104. public void testGetEvenNumbers() {
  105. // : Given
  106. String expected = "5791113151719";
  107. int start = 5;
  108. int stop = 20;
  109. // : When
  110. String actual = NumberUtilities.getEvenNumbers(start, stop);
  111. // : Then
  112. Assert.assertEquals(expected, actual);
  113. }
  114. @Test
  115. public void testGetOddNumbers() {
  116. // : Given
  117. String expected = "681012141618";
  118. int start = 5;
  119. int stop = 20;
  120. int step = 5;
  121. // : When
  122. String actual = NumberUtilities.getOddNumbers(start, stop);
  123. // : Then
  124. Assert.assertEquals(expected, actual);
  125. }
  126. @Test
  127. public void testGetExponentsNumbersForSquare() {
  128. // : Given
  129. String expected = "25100225";
  130. int start = 5;
  131. int stop = 20;
  132. int step = 5;
  133. // : When
  134. String actual = NumberUtilities.getExponentiations(start, stop, step);
  135. // : Then
  136. Assert.assertEquals(expected, actual);
  137. }
  138. @Test
  139. public void testGetExponentiationNumbersForCube() {
  140. // : Given
  141. String expected = "25100225";
  142. int start = 5;
  143. int stop = 20;
  144. int step = 5;
  145. int exponent = 2;
  146. // : When
  147. String actual = NumberUtilities.getExponentiations(start, stop, exponent);
  148. Assert.assertEquals(expected, actual);
  149. }
  150. }