123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #include "assertion.h"
- #include <stdio.h>
- #include "bits.h"
- static void test1(void)
- {
- static bit_array bits[SIZE(40)] = {0};
- assert(get_bit(bits, 0) == 0);
- set_bit(bits, 1);
- assert(get_bit(bits, 1) == 1);
- clear_bit(bits, 1);
- assert(get_bit(bits, 1) == 0);
- set_bit(bits, 2);
- assert(get_bit(bits, 2) == 1);
- set_bit(bits, 3);
- assert(get_bit(bits, 3) == 1);
- for (size_t i = 4; i < 40; i++) {
- assert(get_bit(bits, i) == 0);
- }
- printf("Test1 Passed!\n");
- }
- static void test2(void)
- {
- static bit_array bits[SIZE(40)] = {0};
- hex2bits(bits, 0, 12450);
- hex2bits(bits, 16, 11037);
- assert(bits2hex(bits, 0) == 12450);
- assert(bits2hex(bits, 16) == 11037);
- for (size_t i = 32; i < 40; i++) {
- assert(get_bit(bits, i) == 0);
- }
- printf("Test2 Passed!\n");
- }
- static void test3(void)
- {
- static bit_array bits[SIZE(20)] = {0};
- char2bits(bits, 0, 'B');
- char2bits(bits, 8, 'C');
- assert(bits2char(bits, 0) == 'B');
- assert(bits2char(bits, 8) == 'C');
- for (size_t i = 16; i < 20; i++) {
- assert(get_bit(bits, i) == 0);
- }
- printf("Test3 Passed!\n");
- }
- static void test4(void)
- {
- static bit_array bits[SIZE(4)] = {0};
- set_bit(bits, 0);
- set_bit(bits, 1);
- clear_bit(bits, 2);
- assert(get_bit(bits, 0) == 1);
- assert(get_bit(bits, 1) == 1);
- assert(get_bit(bits, 2) == 0);
- bits_left_shift(bits, 3, 1);
- assert(get_bit(bits, 0) == 1);
- assert(get_bit(bits, 1) == 0);
- assert(get_bit(bits, 2) == 1);
- assert(get_bit(bits, 3) == 0);
- bits_left_shift(bits, 4, 1);
- assert(get_bit(bits, 0) == 0);
- assert(get_bit(bits, 1) == 1);
- assert(get_bit(bits, 2) == 0);
- assert(get_bit(bits, 3) == 1);
- printf("Test4 Passed!\n");
- }
- int main(void)
- {
- test1();
- test2();
- test3();
- test4();
- return 0;
- }
|