libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
numbers.test.h
Go to the documentation of this file.
1 #include "unity.h"
2 #include "numbers.h"
3 
4 #include "propeller.h"
5 
6 class UnityTests {
7 public:
8 
9  static void setUp(void) {
10 
11  }
12 
13  static void tearDown(void) {
14 
15  }
16 
17 
18  // -----------------------------------------------------------------------------
19  // Number to Bin String
20  // -----------------------------------------------------------------------------
21 
22  static void test_BinReturnAddressMatchesGivenAddress(void) {
23  char string[40];
24  char * return_addr = Numbers::Bin(0b110, 4, string);
25  TEST_ASSERT_EQUAL_PTR(string, return_addr);
26  }
27 
28  static void test_BinZero(void) {
29  char string[40];
30  TEST_ASSERT_EQUAL_STRING("0000", Numbers::Bin(0b0000, 4, string));
31  }
32 
33  static void test_BinPositiveNumber(void) {
34  char string[40];
35  TEST_ASSERT_EQUAL_STRING("10100101", Numbers::Bin(0b10100101, 8, string));
36  }
37 
38  static void test_Bin32BitNumber(void) {
39  char string[40];
40  TEST_ASSERT_EQUAL_STRING("10101010000000001111111111001100",
41  Numbers::Bin(0b10101010000000001111111111001100, 32, string));
42  }
43 
44  static void test_BinNoMoreDigitsThanSpecified(void) {
45  char string[40];
46  TEST_ASSERT_EQUAL_STRING("1111", Numbers::Bin(0b11111111, 4, string));
47  }
48 
49  static void test_BinInternalBuffer(void) {
50  TEST_ASSERT_EQUAL_STRING("01010", Numbers::Bin(0b01010, 5));
51  }
52 
53 
54 
55 
56  // -----------------------------------------------------------------------------
57  // Number to Hex String
58  // -----------------------------------------------------------------------------
59 
60  static void test_HexReturnAddressMatchesGivenAddress(void) {
61  char string [20];
62  char * return_addr = Numbers::Hex(0x555, 5, string);
63  TEST_ASSERT_EQUAL_PTR(string, return_addr);
64  }
65 
66  static void test_HexZero(void) {
67  char string[20];
68  TEST_ASSERT_EQUAL_STRING("00", Numbers::Hex(0x0, 2, string));
69 
70  }
71 
72  static void test_HexPositiveNumber(void) {
73  char string[20];
74  TEST_ASSERT_EQUAL_STRING("FA467", Numbers::Hex(0xFA467, 5, string));
75  }
76 
77  static void test_Hex32BitNumber(void) {
78  char string[20];
79  TEST_ASSERT_EQUAL_STRING("FEDCBA98", Numbers::Hex(0xFEDCBA98, 8, string));
80  }
81 
82  static void test_HexNoMoreDigitsThanSpecified(void) {
83  char string [20];
84  TEST_ASSERT_EQUAL_STRING("250F", Numbers::Hex(0x90250F, 4, string));
85  }
86 
87  static void test_HexEachDigit(void) {
88  char string [20];
89  TEST_ASSERT_EQUAL_STRING("01234567", Numbers::Hex(0x01234567, 8, string));
90  TEST_ASSERT_EQUAL_STRING("89ABCDEF", Numbers::Hex(0x89ABCDEF, 8, string));
91  }
92 
93  static void test_HexInternalBuffer(void) {
94  TEST_ASSERT_EQUAL_STRING("DEF", Numbers::Hex(0xDEF, 3));
95  }
96 
97  // -----------------------------------------------------------------------------
98  // Number to Dec String
99  // -----------------------------------------------------------------------------
100 
101  static void test_DecReturnAddressMatchesGivenAddress(void) {
102  char string [20];
103  char * return_addr = Numbers::Dec(555, string);
104  TEST_ASSERT_EQUAL_PTR(string, return_addr);
105  }
106 
107  static void test_DecZero(void) {
108  char string [20];
109  TEST_ASSERT_EQUAL_STRING("0", Numbers::Dec(0, string));
110  }
111 
112  static void test_DecPositiveNumber(void) {
113  char string [20];
114  TEST_ASSERT_EQUAL_STRING("542", Numbers::Dec(542, string));
115  }
116 
117  static void test_DecNegativeNumber(void) {
118  char string [20];
119 
120  //Add some timing information...
121  int start_cnt = CNT;
122  Numbers::Dec(-3258656, string);
123  int end_cnt = CNT;
124 
125  printf("Total CNT==%d ", end_cnt - start_cnt);
126 
127  TEST_ASSERT_EQUAL_STRING("-3258656", string);
128 
129  }
130 
131  static void test_DecVeryLargeNumber(void) {
132  char string [20];
133  TEST_ASSERT_EQUAL_STRING("2000000001", Numbers::Dec(2000000001, string));
134  }
135 
136  static void test_DecInternalBuffer(void) {
137  TEST_ASSERT_EQUAL_STRING("123456", Numbers::Dec(123456));
138  }
139 
140  // -----------------------------------------------------------------------------
141  // Dec String to Number
142  // -----------------------------------------------------------------------------
143 
144  static void test_DecBasic(void) {
145  TEST_ASSERT_EQUAL_INT(1234, Numbers::Dec("1234"));
146  }
147 
148  static void test_DecNegativeBasic(void) {
149  TEST_ASSERT_EQUAL_INT(-987, Numbers::Dec("-987"));
150  }
151 
152  static void test_DecBigNumber(void) {
153  TEST_ASSERT_EQUAL_INT(9864753, Numbers::Dec("9864753"));
154  }
155 
156  static void test_DecNonZeroTerminator(void) {
157  char number [] = {'3', '1', '\n'};
158  TEST_ASSERT_EQUAL_INT(31, Numbers::Dec(number, '\n'));
159  }
160 
161  static void test_DecZeroNumbers(void) {
162  TEST_ASSERT_EQUAL_INT(0, Numbers::Dec("0"));
163  TEST_ASSERT_EQUAL_INT(0, Numbers::Dec("00000"));
164  }
165 
166  static void test_DecLeadingZeros(void) {
167  TEST_ASSERT_EQUAL_INT(135, Numbers::Dec("00135"));
168  }
169 
170  static void test_DecEmptyString(void) {
171  TEST_ASSERT_EQUAL_INT(0, Numbers::Dec(""));
172  }
173 
174  static void test_DecCharArray(void) {
175  char string[] = {'4', '2', 0};
176  TEST_ASSERT_EQUAL_INT(42, Numbers::Dec(string));
177  }
178 
179  // -----------------------------------------------------------------------------
180  // Reverse
181  // -----------------------------------------------------------------------------
182 
183  static void test_ReverseReturnAddressMatchesGivenAddress(void) {
184  char string [20];
185  char * return_addr = Numbers::Reverse(string);
186  TEST_ASSERT_EQUAL_PTR(string, return_addr);
187  }
188 
189  static void test_ReverseEmptyString(void) {
190  char string [20];
191  string[0] = 0;
192  TEST_ASSERT_EQUAL_STRING("", Numbers::Reverse(string));
193  }
194 
195  static void test_ReverseSimpleString(void) {
196  char string [] = "abcdef";
197  TEST_ASSERT_EQUAL_STRING("fedcba", Numbers::Reverse(string));
198  }
199 
200  // -----------------------------------------------------------------------------
201  // Assorted Tests
202  // -----------------------------------------------------------------------------
203 
204  static void test_DecToDec(void) {
205  TEST_ASSERT_EQUAL_INT(531, Numbers::Dec(Numbers::Dec(531)));
206  }
207 
208  static void test_DecToDec2(void) {
209  TEST_ASSERT_EQUAL_STRING("468", Numbers::Dec(Numbers::Dec("468")));
210  }
211 
212  // -----------------------------------------------------------------------------
213  // DecDigits
214  // -----------------------------------------------------------------------------
215 
216  static void test_DecDigitsZero(void) {
217  TEST_ASSERT_EQUAL_INT(1, Numbers::DecDigits(0));
218  }
219 
220  static void test_DecDigits1(void) {
221  TEST_ASSERT_EQUAL_INT(1, Numbers::DecDigits(5));
222  }
223 
224  static void test_DecDigits2(void) {
225  TEST_ASSERT_EQUAL_INT(2, Numbers::DecDigits(55));
226  }
227 
228  static void test_DecDigits3(void) {
229  TEST_ASSERT_EQUAL_INT(3, Numbers::DecDigits(555));
230  }
231 
232  static void test_DecDigits4(void) {
233  TEST_ASSERT_EQUAL_INT(4, Numbers::DecDigits(5555));
234  }
235 
236  static void test_DecDigits5(void) {
237  TEST_ASSERT_EQUAL_INT(5, Numbers::DecDigits(55555));
238  }
239 
240  static void test_DecDigits6(void) {
241  TEST_ASSERT_EQUAL_INT(6, Numbers::DecDigits(555555));
242  }
243 
244  static void test_DecDigits7(void) {
245  TEST_ASSERT_EQUAL_INT(7, Numbers::DecDigits(5555555));
246  }
247 
248  static void test_DecDigits8(void) {
249  TEST_ASSERT_EQUAL_INT(8, Numbers::DecDigits(55555555));
250  }
251 
252  static void test_DecDigits9(void) {
253  TEST_ASSERT_EQUAL_INT(9, Numbers::DecDigits(555555555));
254  }
255 
256  static void test_DecDigits10(void) {
257  TEST_ASSERT_EQUAL_INT(10, Numbers::DecDigits(1555555555));
258  }
259 
260  static void test_DecDigitsNegative1(void) {
261  TEST_ASSERT_EQUAL_INT(2, Numbers::DecDigits(-5));
262  }
263 
264  static void test_DecDigitsNegative2(void) {
265  TEST_ASSERT_EQUAL_INT(3, Numbers::DecDigits(-55));
266  }
267 
268  static void test_DecDigitsNegative3(void) {
269  TEST_ASSERT_EQUAL_INT(4, Numbers::DecDigits(-555));
270  }
271 
272  static void test_DecDigitsNegative4(void) {
273  TEST_ASSERT_EQUAL_INT(5, Numbers::DecDigits(-5555));
274  }
275 
276  static void test_DecDigitsNegative5(void) {
277  TEST_ASSERT_EQUAL_INT(6, Numbers::DecDigits(-55555));
278  }
279 
280  static void test_DecDigitsNegative6(void) {
281  TEST_ASSERT_EQUAL_INT(7, Numbers::DecDigits(-555555));
282  }
283 
284  static void test_DecDigitsNegative7(void) {
285  TEST_ASSERT_EQUAL_INT(8, Numbers::DecDigits(-5555555));
286  }
287 
288  static void test_DecDigitsNegative8(void) {
289  TEST_ASSERT_EQUAL_INT(9, Numbers::DecDigits(-55555555));
290  }
291 
292  static void test_DecDigitsNegative9(void) {
293  TEST_ASSERT_EQUAL_INT(10, Numbers::DecDigits(-555555555));
294  }
295 
296  static void test_DecDigitsNegative10(void) {
297  TEST_ASSERT_EQUAL_INT(11, Numbers::DecDigits(-1555555555));
298  }
299 
300  // -----------------------------------------------------------------------------
301 
302  static void test_HexDigitsZero(void) {
303  TEST_ASSERT_EQUAL_INT(1, Numbers::HexDigits(0x0));
304  }
305 
306  static void test_HexDigits1(void) {
307  TEST_ASSERT_EQUAL_INT(1, Numbers::HexDigits(0xF));
308  }
309 
310  static void test_HexDigits2(void) {
311  TEST_ASSERT_EQUAL_INT(2, Numbers::HexDigits(0xFE));
312  }
313 
314  static void test_HexDigits3(void) {
315  TEST_ASSERT_EQUAL_INT(3, Numbers::HexDigits(0xFED));
316  }
317 
318  static void test_HexDigits4(void) {
319  TEST_ASSERT_EQUAL_INT(4, Numbers::HexDigits(0xFEDC));
320  }
321 
322  static void test_HexDigits5(void) {
323  TEST_ASSERT_EQUAL_INT(5, Numbers::HexDigits(0xFEDCB));
324  }
325 
326  static void test_HexDigits6(void) {
327  TEST_ASSERT_EQUAL_INT(6, Numbers::HexDigits(0xFEDCBA));
328  }
329 
330  static void test_HexDigits7(void) {
331  TEST_ASSERT_EQUAL_INT(7, Numbers::HexDigits(0xFEDCBA9));
332  }
333 
334  static void test_HexDigits8(void) {
335  TEST_ASSERT_EQUAL_INT(8, Numbers::HexDigits(0xFEDCBA98));
336  }
337 
338 };
339 
340 
341 
342 
343 
344 
345 
346 
347 
348 
349 
350 
351 
352 
353 
354 
355 
356 
357 
358 
359 
360 
361 
362