How to use it if the project has a main

46 views
Skip to first unread message

Dmitrij Moreinis

unread,
Mar 14, 2019, 10:08:31 AM3/14/19
to CATCH
Hello 
I am having problems to use it with a main file. 
is there a way to add test case after each function in the main file.

Here is an example
#define CATCH_CONFIG_MAIN  // This tells Catch to provide a main() - only do this in one cpp file
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include "catch.hpp"
//using namespace std;


double a,b,c;
int indikator;

double linsolve( double b, double c )
{
 return -c/b;

}

int Typ( double a, double b , double c)
{
   if
              ((a==0)&&(b==0)&&(c==0)) indikator=1; // Fall unendlich viele Lösungen
   else if ((a==0)&&(b==0)&&(c!=0))   indikator=2;  // Fall keine Lösung
   else if (((a==0)&&(b!=0)&&(c==0))||((a==0)&&(b!=0)&&(c!=0))) indikator=3; // Fall Lineare Gleichung
   else if ((a!=0)&&(b!=0)&&(c!=0)) indikator=4; // Fall quadratische Gleichung
 return indikator;

}


/*
int main()
{
  std::cin >>  a >>  b >>  c;
  std::cout << " a ist= " << b << " b ist= " << b << " c ist= " << c << "\n";


  std::cout << " Fall " << Typ(a,b,c) << "\n";


}

*/

  TEST_CASE( "Prüfe die Fallunterscheidungen", "[Typ]" ) {
    REQUIRE( Typ(0,0,0) == 1 );
    REQUIRE( Typ(0,0,1) == 2 );
    REQUIRE( Typ(0,1,0) == 3 );
    REQUIRE( Typ(0,1,1) == 3 );
    REQUIRE( Typ(1,1,1) == 4 );
}



Phil Nash

unread,
Mar 14, 2019, 10:11:03 AM3/14/19
to Dmitrij Moreinis, CATCH
--
You received this message because you are subscribed to the Google Groups "CATCH" group.
To unsubscribe from this group and stop receiving emails from it, send an email to catch-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages