// Solutions to "Richard Kaiser: C++ with Borland C++Builder", ISBN: 3540010270
// Copyright Richard Kaiser, 2004, All rights reserved
// oder doch besser weglassen ???

#ifndef TestUtils_cpp
#define TestUtils_cpp


#include "NearlyEqual.cpp"

/*
#include "NearlyEqual.cpp"
*/
int TestUtilsPassCount=0,TestUtilsFailCount=0;

void InitTestUtils()
{
TestUtilsPassCount=0;
TestUtilsFailCount=0;
}


bool CheckEqual_int(int f, int s, AnsiString msg)
{ // tests one test case
if (f!=s)
  {
    Form1->Memo1->Lines->Add("Test failed: "+msg+"=="+IntToStr(f)+", expected: "+IntToStr(s));
    ++TestUtilsFailCount;
    return false;
  }
else
  {
#if LOG_TEST_CASES
    Form1->Memo1->Lines->Add("Test passed: "+msg+"=="+IntToStr(f)+", expected: "+IntToStr(s));
#endif
    ++TestUtilsPassCount;
    return true;
  }
}

AnsiString BoolToString(bool b)
{
if (b) return "true";
else return "false";
}

bool CheckEqual_bool(bool f, bool s, AnsiString msg)
{ // tests one test case
if (f!=s)
  {
    Form1->Memo1->Lines->Add("Test failed: "+msg+"=="+BoolToString(f)+", expected: "+BoolToString(s));
    ++TestUtilsFailCount;
    return false;
  }
else
  {
#if LOG_TEST_CASES
    Form1->Memo1->Lines->Add("Test passed: "+msg+"=="+BoolToString(f)+", expected: "+BoolToString(s));
#endif
    ++TestUtilsPassCount;
    return true;
  }
}

bool CheckEqual_double(double f, double s, AnsiString msg)
{ // tests one test case
if (!NearlyEqual2(f,s,10))
  {
    Form1->Memo1->Lines->Add("Test failed: "+msg+"=="+FloatToStr(f)+", expected: "+FloatToStr(s));
    ++TestUtilsFailCount;
    return false;
  }
else
  {
#if LOG_TEST_CASES
    Form1->Memo1->Lines->Add("Test passed: "+msg+"=="+FloatToStr(f)+", expected: "+FloatToStr(s));
#endif
    ++TestUtilsPassCount;
    return true;
  }
}


#endif
