|
|
@@ -1,49 +1,114 @@
|
|
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
|
|
-import org.junit.runners.Parameterized.Parameters;
|
|
6
|
|
-
|
|
7
|
|
-import java.util.Arrays;
|
|
8
|
|
-import java.util.Collection;
|
|
9
|
3
|
|
|
10
|
4
|
import static org.junit.Assert.assertEquals;
|
|
11
|
5
|
|
|
12
|
|
-@RunWith(Parameterized.class)
|
|
13
|
6
|
public class BinaryTest {
|
|
14
|
7
|
|
|
15
|
|
- private String binaryNumberAsString;
|
|
16
|
|
- private int decimalNumber;
|
|
|
8
|
+ private Binary binary;
|
|
17
|
9
|
|
|
18
|
|
- @Parameters(name = "{index}: expected {1} when converting \"{0}\" from binary to decimal.")
|
|
19
|
|
- public static Collection<Object[]> data() {
|
|
20
|
|
- return Arrays.asList(new Object[][]{
|
|
21
|
|
- {"1", 1},
|
|
22
|
|
- {"10", 2},
|
|
23
|
|
- {"11", 3},
|
|
24
|
|
- {"100", 4},
|
|
25
|
|
- {"1001", 9},
|
|
26
|
|
- {"11010", 26},
|
|
27
|
|
- {"10001101000", 1128},
|
|
28
|
|
- {"2", 0},
|
|
29
|
|
- {"5", 0},
|
|
30
|
|
- {"9", 0},
|
|
31
|
|
- {"134678", 0},
|
|
32
|
|
- {"abc10z", 0},
|
|
33
|
|
- {"011", 3}
|
|
34
|
|
- });
|
|
|
10
|
+ @Test
|
|
|
11
|
+ public void testBinary0IsDecimal0() {
|
|
|
12
|
+ binary = new Binary("0");
|
|
|
13
|
+ assertEquals(0, binary.getDecimal());
|
|
|
14
|
+ }
|
|
|
15
|
+
|
|
|
16
|
+ @Ignore("Remove to run test")
|
|
|
17
|
+ @Test
|
|
|
18
|
+ public void testBinary1IsDecimal1() {
|
|
|
19
|
+ binary = new Binary("1");
|
|
|
20
|
+ assertEquals(1, binary.getDecimal());
|
|
35
|
21
|
}
|
|
36
|
22
|
|
|
37
|
|
- public BinaryTest(String binaryNumberAsString, int decimalNumber) {
|
|
38
|
|
- this.binaryNumberAsString = binaryNumberAsString;
|
|
39
|
|
- this.decimalNumber = decimalNumber;
|
|
|
23
|
+ @Ignore("Remove to run test")
|
|
|
24
|
+ @Test
|
|
|
25
|
+ public void testBinary10IsDecimal2() {
|
|
|
26
|
+ binary = new Binary("10");
|
|
|
27
|
+ assertEquals(2, binary.getDecimal());
|
|
40
|
28
|
}
|
|
41
|
29
|
|
|
|
30
|
+ @Ignore("Remove to run test")
|
|
|
31
|
+ @Test
|
|
|
32
|
+ public void testBinary11IsDecimal3() {
|
|
|
33
|
+ binary = new Binary("11");
|
|
|
34
|
+ assertEquals(3, binary.getDecimal());
|
|
|
35
|
+ }
|
|
42
|
36
|
|
|
|
37
|
+ @Ignore("Remove to run test")
|
|
43
|
38
|
@Test
|
|
44
|
|
- public void test() {
|
|
45
|
|
- Binary binary = new Binary(binaryNumberAsString);
|
|
|
39
|
+ public void testBinary100IsDecimal4() {
|
|
|
40
|
+ binary = new Binary("100");
|
|
|
41
|
+ assertEquals(4, binary.getDecimal());
|
|
|
42
|
+ }
|
|
46
|
43
|
|
|
47
|
|
- assertEquals(decimalNumber, binary.getDecimal());
|
|
|
44
|
+ @Ignore("Remove to run test")
|
|
|
45
|
+ @Test
|
|
|
46
|
+ public void testBinary1001IsDecimal9() {
|
|
|
47
|
+ binary = new Binary("1001");
|
|
|
48
|
+ assertEquals(9, binary.getDecimal());
|
|
|
49
|
+ }
|
|
|
50
|
+
|
|
|
51
|
+ @Ignore("Remove to run test")
|
|
|
52
|
+ @Test
|
|
|
53
|
+ public void testBinary11010IsDecimal26() {
|
|
|
54
|
+ binary = new Binary("11010");
|
|
|
55
|
+ assertEquals(26, binary.getDecimal());
|
|
|
56
|
+ }
|
|
|
57
|
+
|
|
|
58
|
+ @Ignore("Remove to run test")
|
|
|
59
|
+ @Test
|
|
|
60
|
+ public void testBinary10001101000IsDecimal1128() {
|
|
|
61
|
+ binary = new Binary("10001101000");
|
|
|
62
|
+ assertEquals(1128, binary.getDecimal());
|
|
|
63
|
+ }
|
|
|
64
|
+
|
|
|
65
|
+ @Ignore("Remove to run test")
|
|
|
66
|
+ @Test
|
|
|
67
|
+ public void testBinaryIgnoresLeadingZeros() {
|
|
|
68
|
+ binary = new Binary("000011111");
|
|
|
69
|
+ assertEquals(31, binary.getDecimal());
|
|
48
|
70
|
}
|
|
|
71
|
+
|
|
|
72
|
+ @Ignore("Remove to run test")
|
|
|
73
|
+ @Test
|
|
|
74
|
+ public void test2NotValidBinaryDigit() {
|
|
|
75
|
+ binary = new Binary("2");
|
|
|
76
|
+ assertEquals(0, binary.getDecimal());
|
|
|
77
|
+ }
|
|
|
78
|
+
|
|
|
79
|
+ @Ignore("Remove to run test")
|
|
|
80
|
+ @Test
|
|
|
81
|
+ public void testNumberContainingNonBinaryDigitInvalid() {
|
|
|
82
|
+ binary = new Binary("01201");
|
|
|
83
|
+ assertEquals(0, binary.getDecimal());
|
|
|
84
|
+ }
|
|
|
85
|
+
|
|
|
86
|
+ @Ignore("Remove to run test")
|
|
|
87
|
+ @Test
|
|
|
88
|
+ public void testNumberWithTrailingNonBinaryCharactersInvalid() {
|
|
|
89
|
+ binary = new Binary("10nope");
|
|
|
90
|
+ assertEquals(0, binary.getDecimal());
|
|
|
91
|
+ }
|
|
|
92
|
+
|
|
|
93
|
+ @Ignore("Remove to run test")
|
|
|
94
|
+ @Test
|
|
|
95
|
+ public void testNumberWithLeadingNonBinaryCharactersInvalid() {
|
|
|
96
|
+ binary = new Binary("nope10");
|
|
|
97
|
+ assertEquals(0, binary.getDecimal());
|
|
|
98
|
+ }
|
|
|
99
|
+
|
|
|
100
|
+ @Ignore("Remove to run test")
|
|
|
101
|
+ @Test
|
|
|
102
|
+ public void testNumberWithInternalNonBinaryCharactersInvalid() {
|
|
|
103
|
+ binary = new Binary("10nope10");
|
|
|
104
|
+ assertEquals(0, binary.getDecimal());
|
|
|
105
|
+ }
|
|
|
106
|
+
|
|
|
107
|
+ @Ignore("Remove to run test")
|
|
|
108
|
+ @Test
|
|
|
109
|
+ public void testNumberAndWordWhitespaceSeparatedInvalid() {
|
|
|
110
|
+ binary = new Binary("001 nope");
|
|
|
111
|
+ assertEquals(0, binary.getDecimal());
|
|
|
112
|
+ }
|
|
|
113
|
+
|
|
49
|
114
|
}
|