#ifndef TESTUTILS_CPP__
#define TESTUTILS_CPP__

#include "NearlyEqual_vc.cpp"


bool log_Testcases=false;

// Die folgenden Funktionen sind so geschrieben, dass man sie einfach
// in einer Klasse zusammenfassen kann, indem man sie zwischen
// class { ... } einfügt. ??? 


int TestUtilsPassCount=0,TestUtilsFailCount=0;

void initTestUtils()
{
TestUtilsPassCount=0;
TestUtilsFailCount=0;
}


#if  _MANAGED
using namespace System;
using namespace System::Windows::Forms;

bool assertTrue(bool condition, String^ msg, TextBox^ tb)
{ // tests one test case
if (!condition)
  {
    tb->AppendText("Test failed: "+msg+"\r\n");
    ++TestUtilsFailCount;
  }
else
  {
    if (log_Testcases)
      tb->AppendText("Test passed: "+msg+"\r\n");
    ++TestUtilsPassCount;
  }
return condition;
}

bool assertEqual_int(int f, int s, String^  msg, TextBox^ tb)
{ // tests one test case
return assertTrue(f==s,msg+"=="+Convert::ToString(f)+", expected: "+Convert::ToString(s), tb);
}

String^ BoolToString(bool b)
{
if (b) return "true";
else return "false";
}

bool assertEqual_bool(bool f, bool s, String^ msg, TextBox^ tb)
{ // tests one test case
return assertTrue(f==s, msg+"=="+BoolToString(f)+", expected: "+BoolToString(s),tb);
}

bool assertEqual_double(double f, double s, String^ msg, TextBox^ tb, int digits=10)
{ // tests one test case
return assertTrue(NearlyEqual2(f,s,digits),msg+"=="+Convert::ToString(f)+", expected: "+Convert::ToString(s),tb);
}

bool assertNotEqual_double(double f, double s, String^ msg, TextBox^ tb, int digits=10)
{ // tests one test case
return assertTrue(!NearlyEqual2(f,s,digits),msg+"=="+Convert::ToString(f)+", expected: "+Convert::ToString(s),tb);
}


bool assertEqual_String(String^ f, String^ s, String^ msg, TextBox^ tb)
{ // tests one test case
return assertTrue(f==s,msg+"=="+f+", expected: "+s,tb);
}

bool assertEqual_Pointer(const void* f, const void* s, String^ msg, TextBox^ tb)
{ // tests one test case
return assertTrue(f==s,msg+"=="+Convert::ToString(f)+", expected: "+Convert::ToString(s),tb);
}

bool assertEqual(bool f, bool s, String^ msg, TextBox^ tb)
{
return assertEqual_bool(f, s, msg, tb);
}

bool assertEqual(int f, int s, String^ msg, TextBox^ tb)
{
return assertEqual_int(f, s, msg, tb);
}

bool assertEqual(double f, double s, String^ msg, TextBox^ tb, int digits=10)
{ // tests one test case
return assertEqual_double(f, s, msg, tb, digits);
}

bool assertEqual(String^ f, String^ s, String^ msg, TextBox^ tb)
{ // tests one test case
return assertEqual_String(f, s, msg, tb);
}

bool assertEqual(void* f, void* s, String^ msg, TextBox^ tb)
{ // tests one test case
return assertEqual_Pointer(f, s, msg, tb);
}

#endif

#endif
