NumberUtilitiesTest.java 4.4KB

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