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