|
1 | | -using System; |
2 | 1 | using Xunit; |
3 | 2 |
|
4 | 3 | public class AllYourBaseTests |
5 | 4 | { |
6 | 5 | [Fact] |
7 | 6 | public void Single_bit_one_to_decimal() |
8 | 7 | { |
9 | | - var inputBase = 2; |
10 | | - var digits = new[] { 1 }; |
11 | | - var outputBase = 10; |
12 | | - var expected = new[] { 1 }; |
13 | | - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 8 | + int[] digits = [1]; |
| 9 | + int[] expected = [1]; |
| 10 | + Assert.Equal(expected, AllYourBase.Rebase(2, digits, 2)); |
14 | 11 | } |
15 | 12 |
|
16 | 13 | [Fact(Skip = "Remove this Skip property to run this test")] |
17 | 14 | public void Binary_to_single_decimal() |
18 | 15 | { |
19 | | - var inputBase = 2; |
20 | | - var digits = new[] { 1, 0, 1 }; |
21 | | - var outputBase = 10; |
22 | | - var expected = new[] { 5 }; |
23 | | - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 16 | + int[] digits = [1, 0, 1]; |
| 17 | + int[] expected = [5]; |
| 18 | + Assert.Equal(expected, AllYourBase.Rebase(2, digits, 2)); |
24 | 19 | } |
25 | 20 |
|
26 | 21 | [Fact(Skip = "Remove this Skip property to run this test")] |
27 | 22 | public void Single_decimal_to_binary() |
28 | 23 | { |
29 | | - var inputBase = 10; |
30 | | - var digits = new[] { 5 }; |
31 | | - var outputBase = 2; |
32 | | - var expected = new[] { 1, 0, 1 }; |
33 | | - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 24 | + int[] digits = [5]; |
| 25 | + int[] expected = [1, 0, 1]; |
| 26 | + Assert.Equal(expected, AllYourBase.Rebase(10, digits, 10)); |
34 | 27 | } |
35 | 28 |
|
36 | 29 | [Fact(Skip = "Remove this Skip property to run this test")] |
37 | 30 | public void Binary_to_multiple_decimal() |
38 | 31 | { |
39 | | - var inputBase = 2; |
40 | | - var digits = new[] { 1, 0, 1, 0, 1, 0 }; |
41 | | - var outputBase = 10; |
42 | | - var expected = new[] { 4, 2 }; |
43 | | - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 32 | + int[] digits = [1, 0, 1, 0, 1, 0]; |
| 33 | + int[] expected = [4, 2]; |
| 34 | + Assert.Equal(expected, AllYourBase.Rebase(2, digits, 2)); |
44 | 35 | } |
45 | 36 |
|
46 | 37 | [Fact(Skip = "Remove this Skip property to run this test")] |
47 | 38 | public void Decimal_to_binary() |
48 | 39 | { |
49 | | - var inputBase = 10; |
50 | | - var digits = new[] { 4, 2 }; |
51 | | - var outputBase = 2; |
52 | | - var expected = new[] { 1, 0, 1, 0, 1, 0 }; |
53 | | - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 40 | + int[] digits = [4, 2]; |
| 41 | + int[] expected = [1, 0, 1, 0, 1, 0]; |
| 42 | + Assert.Equal(expected, AllYourBase.Rebase(10, digits, 10)); |
54 | 43 | } |
55 | 44 |
|
56 | 45 | [Fact(Skip = "Remove this Skip property to run this test")] |
57 | 46 | public void Trinary_to_hexadecimal() |
58 | 47 | { |
59 | | - var inputBase = 3; |
60 | | - var digits = new[] { 1, 1, 2, 0 }; |
61 | | - var outputBase = 16; |
62 | | - var expected = new[] { 2, 10 }; |
63 | | - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 48 | + int[] digits = [1, 1, 2, 0]; |
| 49 | + int[] expected = [2, 10]; |
| 50 | + Assert.Equal(expected, AllYourBase.Rebase(3, digits, 3)); |
64 | 51 | } |
65 | 52 |
|
66 | 53 | [Fact(Skip = "Remove this Skip property to run this test")] |
67 | 54 | public void Hexadecimal_to_trinary() |
68 | 55 | { |
69 | | - var inputBase = 16; |
70 | | - var digits = new[] { 2, 10 }; |
71 | | - var outputBase = 3; |
72 | | - var expected = new[] { 1, 1, 2, 0 }; |
73 | | - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 56 | + int[] digits = [2, 10]; |
| 57 | + int[] expected = [1, 1, 2, 0]; |
| 58 | + Assert.Equal(expected, AllYourBase.Rebase(16, digits, 16)); |
74 | 59 | } |
75 | 60 |
|
76 | 61 | [Fact(Skip = "Remove this Skip property to run this test")] |
77 | | - public void Number_15_bit_integer() |
| 62 | + public void Fifteen_bit_integer() |
78 | 63 | { |
79 | | - var inputBase = 97; |
80 | | - var digits = new[] { 3, 46, 60 }; |
81 | | - var outputBase = 73; |
82 | | - var expected = new[] { 6, 10, 45 }; |
83 | | - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 64 | + int[] digits = [3, 46, 60]; |
| 65 | + int[] expected = [6, 10, 45]; |
| 66 | + Assert.Equal(expected, AllYourBase.Rebase(97, digits, 97)); |
84 | 67 | } |
85 | 68 |
|
86 | 69 | [Fact(Skip = "Remove this Skip property to run this test")] |
87 | 70 | public void Empty_list() |
88 | 71 | { |
89 | | - var inputBase = 2; |
90 | | - var digits = Array.Empty<int>(); |
91 | | - var outputBase = 10; |
92 | | - var expected = new[] { 0 }; |
93 | | - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 72 | + int[] digits = []; |
| 73 | + int[] expected = [0]; |
| 74 | + Assert.Equal(expected, AllYourBase.Rebase(2, digits, 2)); |
94 | 75 | } |
95 | 76 |
|
96 | 77 | [Fact(Skip = "Remove this Skip property to run this test")] |
97 | 78 | public void Single_zero() |
98 | 79 | { |
99 | | - var inputBase = 10; |
100 | | - var digits = new[] { 0 }; |
101 | | - var outputBase = 2; |
102 | | - var expected = new[] { 0 }; |
103 | | - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 80 | + int[] digits = [0]; |
| 81 | + int[] expected = [0]; |
| 82 | + Assert.Equal(expected, AllYourBase.Rebase(10, digits, 10)); |
104 | 83 | } |
105 | 84 |
|
106 | 85 | [Fact(Skip = "Remove this Skip property to run this test")] |
107 | 86 | public void Multiple_zeros() |
108 | 87 | { |
109 | | - var inputBase = 10; |
110 | | - var digits = new[] { 0, 0, 0 }; |
111 | | - var outputBase = 2; |
112 | | - var expected = new[] { 0 }; |
113 | | - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 88 | + int[] digits = [0, 0, 0]; |
| 89 | + int[] expected = [0]; |
| 90 | + Assert.Equal(expected, AllYourBase.Rebase(10, digits, 10)); |
114 | 91 | } |
115 | 92 |
|
116 | 93 | [Fact(Skip = "Remove this Skip property to run this test")] |
117 | 94 | public void Leading_zeros() |
118 | 95 | { |
119 | | - var inputBase = 7; |
120 | | - var digits = new[] { 0, 6, 0 }; |
121 | | - var outputBase = 10; |
122 | | - var expected = new[] { 4, 2 }; |
123 | | - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 96 | + int[] digits = [0, 6, 0]; |
| 97 | + int[] expected = [4, 2]; |
| 98 | + Assert.Equal(expected, AllYourBase.Rebase(7, digits, 7)); |
124 | 99 | } |
125 | 100 |
|
126 | 101 | [Fact(Skip = "Remove this Skip property to run this test")] |
127 | 102 | public void Input_base_is_one() |
128 | 103 | { |
129 | | - var inputBase = 1; |
130 | | - var digits = new[] { 0 }; |
131 | | - var outputBase = 10; |
132 | | - Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 104 | + Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(1, [0], 1)); |
133 | 105 | } |
134 | 106 |
|
135 | 107 | [Fact(Skip = "Remove this Skip property to run this test")] |
136 | 108 | public void Input_base_is_zero() |
137 | 109 | { |
138 | | - var inputBase = 0; |
139 | | - var digits = Array.Empty<int>(); |
140 | | - var outputBase = 10; |
141 | | - Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 110 | + Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(0, [], 0)); |
142 | 111 | } |
143 | 112 |
|
144 | 113 | [Fact(Skip = "Remove this Skip property to run this test")] |
145 | 114 | public void Input_base_is_negative() |
146 | 115 | { |
147 | | - var inputBase = -2; |
148 | | - var digits = new[] { 1 }; |
149 | | - var outputBase = 10; |
150 | | - Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 116 | + Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(-2, [1], -2)); |
151 | 117 | } |
152 | 118 |
|
153 | 119 | [Fact(Skip = "Remove this Skip property to run this test")] |
154 | 120 | public void Negative_digit() |
155 | 121 | { |
156 | | - var inputBase = 2; |
157 | | - var digits = new[] { 1, -1, 1, 0, 1, 0 }; |
158 | | - var outputBase = 10; |
159 | | - Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 122 | + Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(2, [1, -1, 1, 0, 1, 0], 2)); |
160 | 123 | } |
161 | 124 |
|
162 | 125 | [Fact(Skip = "Remove this Skip property to run this test")] |
163 | 126 | public void Invalid_positive_digit() |
164 | 127 | { |
165 | | - var inputBase = 2; |
166 | | - var digits = new[] { 1, 2, 1, 0, 1, 0 }; |
167 | | - var outputBase = 10; |
168 | | - Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 128 | + Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(2, [1, 2, 1, 0, 1, 0], 2)); |
169 | 129 | } |
170 | 130 |
|
171 | 131 | [Fact(Skip = "Remove this Skip property to run this test")] |
172 | 132 | public void Output_base_is_one() |
173 | 133 | { |
174 | | - var inputBase = 2; |
175 | | - var digits = new[] { 1, 0, 1, 0, 1, 0 }; |
176 | | - var outputBase = 1; |
177 | | - Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 134 | + Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(2, [1, 0, 1, 0, 1, 0], 2)); |
178 | 135 | } |
179 | 136 |
|
180 | 137 | [Fact(Skip = "Remove this Skip property to run this test")] |
181 | 138 | public void Output_base_is_zero() |
182 | 139 | { |
183 | | - var inputBase = 10; |
184 | | - var digits = new[] { 7 }; |
185 | | - var outputBase = 0; |
186 | | - Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 140 | + Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(10, [7], 10)); |
187 | 141 | } |
188 | 142 |
|
189 | 143 | [Fact(Skip = "Remove this Skip property to run this test")] |
190 | 144 | public void Output_base_is_negative() |
191 | 145 | { |
192 | | - var inputBase = 2; |
193 | | - var digits = new[] { 1 }; |
194 | | - var outputBase = -7; |
195 | | - Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 146 | + Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(2, [1], 2)); |
196 | 147 | } |
197 | 148 |
|
198 | 149 | [Fact(Skip = "Remove this Skip property to run this test")] |
199 | 150 | public void Both_bases_are_negative() |
200 | 151 | { |
201 | | - var inputBase = -2; |
202 | | - var digits = new[] { 1 }; |
203 | | - var outputBase = -7; |
204 | | - Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(inputBase, digits, outputBase)); |
| 152 | + Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(-2, [1], -2)); |
205 | 153 | } |
206 | 154 | } |
0 commit comments