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