journal extended

Just another WordPress.com weblog

Archive for August 2011

Synchro Test Suite

leave a comment »

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);
}

Then I will use this header file

Read the rest of this entry »

Written by fudanchii

August 20, 2011 at 8:09 pm

Posted in script

Tagged with , , ,

now powered with fixed line

with 2 comments

Yes, It was installed last Monday.
After years, I finally subscribes to this fixed line telephone plus adsl service.
Well I hope I can update these blogs of mine more frequently.
or not.

Umm, for the sake of consistency, I should write something techie related. Or whatever, I guess.
I’m still using Presario CQ42, it’s been 8 months I think, since my office swapped the previous Axioo Neon with this.
It was geared with SuSE Linux Enterprise Desktop 11, which is old, and sucks. The kernel takes ~20% of cpu time while it’s actually idle.

Now I’m using Mint flavoured Debian. And still comfortable with it, despites on edge and unstable proclaim for its rolling based updates.

Well, that’s it for now.

Written by fudanchii

August 19, 2011 at 7:48 am

Posted in Uncategorized

Follow

Get every new post delivered to your Inbox.