Synchro Test Suite
I use this mainly for unit testing my C programs. Since most of the programs were targetted for embedded device, it’s a bit tricky to test, but at least this small suite forced me to separate the modules and make sure they’re all decoupled
Most of the main features were actually macros. Stored at test_fwx.h
,
the source is self-documented, just take a read to figure out
how to use the assertions. And then I was inspired by Python doctest, a tool
to execute unit test written at docstring in the source code. It was actually
came from Peter Norvig’s docex.py. So I decide
to create similar tool, written in C, I used bison and flex to generate the
parser, which I call chouchou.
Here be example on how to use chouchou:
First, make sure you already have bison and flex installed, then compile
chouchou with gcc, just type make
and you’ll set.
I’ll start with this C source file
//this file will be named lychrel.c
//It's not actually finding lychrel number
//but you've got the idea.
//http://en.wikipedia.org/wiki/Lychrel_number
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lychrel.h"
int do_reverse(int number) {
char m[11];
int len, i, j;
if (!sprintf(m, "%d", number))
return 0;
len = strlen(m);
for(i = 0, j = len - 1; i < j; i++, j--) {
char c = m[i];
m[i] = m[j];
m[j] = c;
}
return atoi(m);
}
int is_palindrom(int num) {
int test = do_reverse(num);
if (test == num)
return 1;
return 0;
}
long do_addition(int num) {
return num + do_reverse(num);
}