|
|
@@ -1,49 +1,98 @@
|
|
1
|
1
|
import org.junit.Test;
|
|
2
|
2
|
import org.junit.Ignore;
|
|
3
|
|
-import org.junit.runner.RunWith;
|
|
4
|
|
-import org.junit.runners.Parameterized;
|
|
5
|
|
-
|
|
6
|
|
-import java.util.Arrays;
|
|
7
|
|
-import java.util.Collection;
|
|
8
|
3
|
|
|
9
|
4
|
import static org.junit.Assert.assertEquals;
|
|
10
|
5
|
|
|
11
|
|
-@RunWith(Parameterized.class)
|
|
12
|
6
|
public class OctalTest {
|
|
13
|
7
|
|
|
14
|
|
- private String octalNumberAsString;
|
|
15
|
|
- private int decimalNumber;
|
|
|
8
|
+ @Test
|
|
|
9
|
+ public void testCovertDecimalOneToOctal() {
|
|
|
10
|
+ Octal octal = new Octal("1");
|
|
|
11
|
+ assertEquals(1, octal.getDecimal());
|
|
|
12
|
+ }
|
|
|
13
|
+
|
|
|
14
|
+ @Ignore("Remove to run test")
|
|
|
15
|
+ @Test
|
|
|
16
|
+ public void testCovertDecimalTenToOctal() {
|
|
|
17
|
+ Octal octal = new Octal("10");
|
|
|
18
|
+ assertEquals(8, octal.getDecimal());
|
|
|
19
|
+ }
|
|
|
20
|
+
|
|
|
21
|
+ @Ignore("Remove to run test")
|
|
|
22
|
+ @Test
|
|
|
23
|
+ public void testCovertDecimalSeventeenToOctal() {
|
|
|
24
|
+ Octal octal = new Octal("17");
|
|
|
25
|
+ assertEquals(15, octal.getDecimal());
|
|
|
26
|
+ }
|
|
16
|
27
|
|
|
17
|
|
- @Parameterized.Parameters(name = "{index}: expected {1} when converting \"{0}\" from octal to decimal.")
|
|
18
|
|
- public static Collection<Object[]> data() {
|
|
19
|
|
- return Arrays.asList(new Object[][]{
|
|
20
|
|
- {"1", 1},
|
|
21
|
|
- {"10", 8},
|
|
22
|
|
- {"17", 15},
|
|
23
|
|
- {"11", 9},
|
|
24
|
|
- {"130", 88},
|
|
25
|
|
- {"2047", 1063},
|
|
26
|
|
- {"7777", 4095},
|
|
27
|
|
- {"1234567", 342391},
|
|
28
|
|
- {"carrot", 0},
|
|
29
|
|
- {"8", 0},
|
|
30
|
|
- {"9", 0},
|
|
31
|
|
- {"6789", 0},
|
|
32
|
|
- {"abc1z", 0},
|
|
33
|
|
- {"011", 9}
|
|
34
|
|
- });
|
|
|
28
|
+ @Ignore("Remove to run test")
|
|
|
29
|
+ @Test
|
|
|
30
|
+ public void testCovertElevenToOctal() {
|
|
|
31
|
+ Octal octal = new Octal("11");
|
|
|
32
|
+ assertEquals(9, octal.getDecimal());
|
|
35
|
33
|
}
|
|
36
|
34
|
|
|
37
|
|
- public OctalTest(String octalNumberAsString, int decimalNumber) {
|
|
38
|
|
- this.octalNumberAsString = octalNumberAsString;
|
|
39
|
|
- this.decimalNumber = decimalNumber;
|
|
|
35
|
+ @Ignore("Remove to run test")
|
|
|
36
|
+ @Test
|
|
|
37
|
+ public void testCovertDecimalElevenWithZeroToOctal() {
|
|
|
38
|
+ Octal octal = new Octal("011");
|
|
|
39
|
+ assertEquals(9, octal.getDecimal());
|
|
40
|
40
|
}
|
|
41
|
41
|
|
|
|
42
|
+ @Ignore("Remove to run test")
|
|
|
43
|
+ @Test
|
|
|
44
|
+ public void testThreeDigitDecimalToOctal() {
|
|
|
45
|
+ Octal octal = new Octal("130");
|
|
|
46
|
+ assertEquals(88, octal.getDecimal());
|
|
|
47
|
+ }
|
|
42
|
48
|
|
|
|
49
|
+ @Ignore("Remove to run test")
|
|
43
|
50
|
@Test
|
|
44
|
|
- public void test() {
|
|
45
|
|
- Octal octal = new Octal(octalNumberAsString);
|
|
|
51
|
+ public void testSmallFourDigitDecimalToOctal() {
|
|
|
52
|
+ Octal octal = new Octal("2047");
|
|
|
53
|
+ assertEquals(1063, octal.getDecimal());
|
|
|
54
|
+ }
|
|
46
|
55
|
|
|
47
|
|
- assertEquals(decimalNumber, octal.getDecimal());
|
|
|
56
|
+ @Ignore("Remove to run test")
|
|
|
57
|
+ @Test
|
|
|
58
|
+ public void testLargeFourDigitDecimalToOctal() {
|
|
|
59
|
+ Octal octal = new Octal("7777");
|
|
|
60
|
+ assertEquals(4095, octal.getDecimal());
|
|
48
|
61
|
}
|
|
|
62
|
+
|
|
|
63
|
+ @Ignore("Remove to run test")
|
|
|
64
|
+ @Test
|
|
|
65
|
+ public void testSevenDigitDecimalToOctal() {
|
|
|
66
|
+ Octal octal = new Octal("1234567");
|
|
|
67
|
+ assertEquals(342391, octal.getDecimal());
|
|
|
68
|
+ }
|
|
|
69
|
+
|
|
|
70
|
+ @Ignore("Remove to run test")
|
|
|
71
|
+ @Test
|
|
|
72
|
+ public void testInvalidStringFirst() {
|
|
|
73
|
+ Octal octal = new Octal("carrot");
|
|
|
74
|
+ assertEquals(0, octal.getDecimal());
|
|
|
75
|
+ }
|
|
|
76
|
+
|
|
|
77
|
+ @Ignore("Remove to run test")
|
|
|
78
|
+ @Test
|
|
|
79
|
+ public void testInvalidStringSecond() {
|
|
|
80
|
+ Octal octal = new Octal("abc1z");
|
|
|
81
|
+ assertEquals(0, octal.getDecimal());
|
|
|
82
|
+ }
|
|
|
83
|
+
|
|
|
84
|
+ @Ignore("Remove to run test")
|
|
|
85
|
+ @Test
|
|
|
86
|
+ public void testInvalidDecimalEight() {
|
|
|
87
|
+ Octal octal = new Octal("8");
|
|
|
88
|
+ assertEquals(0, octal.getDecimal());
|
|
|
89
|
+ }
|
|
|
90
|
+
|
|
|
91
|
+ @Ignore("Remove to run test")
|
|
|
92
|
+ @Test
|
|
|
93
|
+ public void testInvalidNumberNine() {
|
|
|
94
|
+ Octal octal = new Octal("9");
|
|
|
95
|
+ assertEquals(0, octal.getDecimal());
|
|
|
96
|
+ }
|
|
|
97
|
+
|
|
49
|
98
|
}
|