I am following the book "The D Programming Language" and am at the portion about functions and unittest. For some reason I cannot get unittest to do anything noticeable.

I right clicked on my Project > Properties > Command Line and under additional options added -unittest (--main gave me an error saying unrecognized switch). After I compiled the code, the program ran as normal. Am I missing something? This is what I have so far:

int[]find(int[] haystack, int needle)
{
        while(haystack.length > 0 && haystack[0] != needle){
                haystack = haystack[1 .. $];
        }
        return haystack;        
}

unittest
{
        int[] a = [];
        assert(find(a, 5) == []);
        a = [ 1, 2, 3 ];
        assert(find(a, 0) == []);
        assert(find(a, 1).length == 3);
        assert(find(a, 2).length == 2);
        assert(a[0 $ - find(a, 3).length] [ 1, 2 ]);
}

void main()
{
        int[3] array = [3, 4, 5];
        int needle = 4;

        find(array, needle);
}

Reply via email to