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