mercredi 15 juillet 2015

Writing automated tests for unix/linux

This is a constraint based question. I am using my school's server to SSH into. I have created a binary search program in C++. Here's the code:

#include <iostream>
using namespace std;
template<typename T>

bool bsearch(T num)
{
    T arr[] = {5.3, 6.62, 7.74, 10.22, 13.22};
    int len = (sizeof(arr)/sizeof(*arr));
    int mid, l_bound=0, u_bound = len-1;
    while (l_bound <= u_bound)
    {
        mid =(l_bound+u_bound)/2;
        if (num > arr[mid])
            l_bound = mid+1;
        else if (num < arr[mid])
            u_bound = mid -1;
        else
            return true;
    }
    return false;
}

int main()
{
    float num;
    cout <<"Number to search: ";
    cin >>num;
    if (bsearch(num) == true)
        cout <<"Number found!\n";
    else
        cout <<"Nubmer not found!\n";

}

It's pretty simple. The only thing is: I want to write some unit tests for this, but I'm having problems getting any of the libraries on my schools SSH server. Is there another way to do this? When I try to include gtest and write this:

#include <gtest/gtest.h>
ASSERT_NE(1, 1);

It just gives me the error that

error: expected unqualified-id before 'switch'

error: expected unqualified-id before 'else'"

Is there a standard library for C++ that I can use? Or how could I get Google's test suite working on this?

Aucun commentaire:

Enregistrer un commentaire