xy.hpp
, tests.cpp
en main.cpp
); deze staan onderin dit bestand.#ifndef XY_HPP
#define XY_HPP
class xy {
public:
int x;
int y;
xy( int x, int y ):
x( x ), y( y )
{}
xy():
x( 0 ), y( 0 )
{}
};
#endif
xy.hpp
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
main.cpp
#include "ostream"
#include "xy.hpp"
#include "catch.hpp"
bool operator== (xy lhs, xy rhs)
{
return (lhs.x == rhs.x) && (lhs.y == rhs.y);
}
std::ostream& operator<< (std::ostream& lhs, xy rhs)
{
return lhs << "(" << rhs.x << "," << rhs.y << ")";
}
TEST_CASE ("constructors, two_parameters")
{
xy v (3, 4);
REQUIRE (v.x == 3);
REQUIRE (v.y == 4);
}
TEST_CASE ("constructors, default")
{
xy v;
REQUIRE (v == xy (0, 0));
}
tests.cpp