123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
-
- import org.junit.Assert;
- import org.junit.Test;
-
- public class NumberUtilitiesTest {
-
- @Test
- public void testGetRangeForSmallRange() {
- // : Given
- String expected = "012";
- int stop = 3;
-
- // : When
- String actual = NumberUtilities.getRange(stop);
-
- // : Then
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testGetRangeToTwoDigits() {
- // : Given
- String expected = "01234567891011";
- int stop = 12;
-
- // : When
- String actual = NumberUtilities.getRange(stop);
-
- // : Then
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testGetRangeWithAStartNumber() {
- // : Given
- String expected = "5678910111213141516171819";
- int start = 5;
- int stop = 20;
-
- // : When
- String actual = NumberUtilities.getRange(start, stop);
-
- // : Then
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testGetRangeStartAt100() {
- // : Given
- String expected = "100101102103104105106107108109";
- int start = 100;
- int stop = 110;
-
- // : When
- String actual = NumberUtilities.getRange(start, stop);
-
- // : Then
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testGetRangeWithOneStep() {
- // : Given
- String expected = "012345678910111213141516171819";
- int start = 0;
- int stop = 20;
- int step = 1;
-
- // : When
- String actual = NumberUtilities.getRange(start, stop, step);
-
- // : Then
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testGetRangeWithTwoStep() {
- // : Given
- String expected = "0246810";
- int start = 0;
- int stop = 11;
- int step = 2;
-
- // : When
- String actual = NumberUtilities.getRange(start, stop, step);
-
- // : Then
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testGetRangeWithFiveStep() {
- // : Given
- String expected = "51015";
- int start = 5;
- int stop = 20;
- int step = 5;
-
- // : When
- String actual = NumberUtilities.getRange(start, stop, step);
-
- // : Then
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testGetEvenNumbersStartAndEndAtEven() {
- // : Given
- String expected = "4681012141618";
- int start = 4;
- int stop = 20;
-
- // : When
- String actual = NumberUtilities.getEvenNumbers(start, stop);
-
- // : Then
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testGetEvenNumbersStartAndEndAtOdd() {
- // : Given
- String expected = "68101214161820";
- int start = 5;
- int stop = 21;
-
- // : When
- String actual = NumberUtilities.getEvenNumbers(start, stop);
-
- // : Then
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testGetOddNumbersStartAndEndAtOdd() {
- // : Given
- String expected = "5791113151719";
- int start = 5;
- int stop = 21;
-
- // : When
- String actual = NumberUtilities.getOddNumbers(start, stop);
-
- // : Then
- Assert.assertEquals(expected, actual);
- }
-
- public void testGetOddNumbersStartAndEndAtEven() {
- // : Given
- String expected = "579111315";
- int start = 4;
- int stop = 16;
-
- // : When
- String actual = NumberUtilities.getOddNumbers(start, stop);
-
- // : Then
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testGetExponentiationNumbersForSquare() {
- // : Given
- String expected = "4916253649";
- int start = 2;
- int stop = 7;
- int exponent = 2;
-
- // : When
- String actual = NumberUtilities.getExponentiations(start, stop, exponent);
-
- // : Then
- Assert.assertEquals(expected, actual);
- }
-
-
-
- @Test
- public void testGetExponentiationNumbersForCube() {
- // : Given
- String expected = "182764";
- int start = 1;
- int stop = 4;
- int exponent = 3;
-
- // : When
- String actual = NumberUtilities.getExponentiations(start, stop, exponent);
-
- // : Then
- Assert.assertEquals(expected, actual);
- }
- }
|