tests pass now
This commit is contained in:
		
							
								
								
									
										10
									
								
								src/Point.h
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/Point.h
									
									
									
									
									
								
							@@ -36,19 +36,15 @@ public:
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Point operator+(Vector lhs, Point rhs) {
 | 
			
		||||
  return Point{rhs.x + lhs.x_, rhs.x + lhs.x_};
 | 
			
		||||
  return Point{rhs.x + lhs.x_, rhs.y + lhs.y_};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Point operator+(Point lhs, Vector rhs) {
 | 
			
		||||
  return Point{rhs.x_ + lhs.x, rhs.x_ + lhs.x};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Point operator-(Vector lhs, Point rhs) {
 | 
			
		||||
  return Point{rhs.x - lhs.x_, rhs.x - lhs.x_};
 | 
			
		||||
  return Point{rhs.x_ + lhs.x, rhs.y_ + lhs.y};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Point operator-(Point lhs, Vector rhs) {
 | 
			
		||||
  return Point{rhs.x_ - lhs.x, rhs.x_ - lhs.x};
 | 
			
		||||
  return Point{lhs.x - rhs.x_, lhs.y - rhs.y_};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Vector operator-(Point lhs, Point rhs){
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										226
									
								
								src/test.cpp
									
									
									
									
									
								
							
							
						
						
									
										226
									
								
								src/test.cpp
									
									
									
									
									
								
							@@ -1,126 +1,136 @@
 | 
			
		||||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this
 | 
			
		||||
                          // in one cpp file
 | 
			
		||||
#include "Point.h"
 | 
			
		||||
			  // in one cpp file
 | 
			
		||||
#include "../external/catch2.hpp"
 | 
			
		||||
#include "Point.h"
 | 
			
		||||
#include "shapes.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
TEST_CASE("Points are created correctly", "[POINT]") {
 | 
			
		||||
  SECTION("constructor") {
 | 
			
		||||
    Point test{5, 6};
 | 
			
		||||
    REQUIRE(test.x == 5);
 | 
			
		||||
    REQUIRE(test.y == 6);
 | 
			
		||||
  }
 | 
			
		||||
TEST_CASE("Points are created correctly", "[POINT]")
 | 
			
		||||
{
 | 
			
		||||
    SECTION("constructor")
 | 
			
		||||
    {
 | 
			
		||||
	Point test {5, 6};
 | 
			
		||||
	REQUIRE(test.x == 5);
 | 
			
		||||
	REQUIRE(test.y == 6);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST_CASE("Point operations", "[POINT]") {
 | 
			
		||||
  SECTION("addition") {
 | 
			
		||||
    Point test{5, 6};
 | 
			
		||||
    Vector translation {1,1};
 | 
			
		||||
    test = test + translation;
 | 
			
		||||
    REQUIRE(test.x == 6);
 | 
			
		||||
    REQUIRE(test.y == 7);
 | 
			
		||||
    test = translation + test;
 | 
			
		||||
    REQUIRE(test.x == 7);
 | 
			
		||||
    REQUIRE(test.y == 8);
 | 
			
		||||
  }
 | 
			
		||||
    SECTION("subtraction") {
 | 
			
		||||
    Point test{5, 6};
 | 
			
		||||
    Vector translation {1,1};
 | 
			
		||||
    test = test - translation;
 | 
			
		||||
    REQUIRE(test.x == 4);
 | 
			
		||||
    REQUIRE(test.y == 5);
 | 
			
		||||
    test = translation - test;
 | 
			
		||||
        REQUIRE(test.x == 3);
 | 
			
		||||
    REQUIRE(test.y == 4);
 | 
			
		||||
  }
 | 
			
		||||
TEST_CASE("Point operations", "[POINT]")
 | 
			
		||||
{
 | 
			
		||||
    SECTION("addition")
 | 
			
		||||
    {
 | 
			
		||||
	Point test {5, 6};
 | 
			
		||||
	Vector translation {1, 1};
 | 
			
		||||
	test = test + translation;
 | 
			
		||||
	REQUIRE(test.x == 6);
 | 
			
		||||
	REQUIRE(test.y == 7);
 | 
			
		||||
	test = translation + test;
 | 
			
		||||
	REQUIRE(test.x == 7);
 | 
			
		||||
	REQUIRE(test.y == 8);
 | 
			
		||||
    }
 | 
			
		||||
    SECTION("subtraction")
 | 
			
		||||
    {
 | 
			
		||||
	Point test {5, 6};
 | 
			
		||||
	Vector translation {1, 1};
 | 
			
		||||
	test = test - translation;
 | 
			
		||||
	REQUIRE(test.x == 4);
 | 
			
		||||
	REQUIRE(test.y == 5);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST_CASE("Vectors are created correctly", "[VECTOR]") {
 | 
			
		||||
  SECTION("constructor") {
 | 
			
		||||
    Vector test{5, 6};
 | 
			
		||||
    REQUIRE(test.x_ == 5);
 | 
			
		||||
    REQUIRE(test.y_ == 6);
 | 
			
		||||
  }
 | 
			
		||||
TEST_CASE("Vectors are created correctly", "[VECTOR]")
 | 
			
		||||
{
 | 
			
		||||
    SECTION("constructor")
 | 
			
		||||
    {
 | 
			
		||||
	Vector test {5, 6};
 | 
			
		||||
	REQUIRE(test.x_ == 5);
 | 
			
		||||
	REQUIRE(test.y_ == 6);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST_CASE("Vector operations work correctly", "[VECTOR]")
 | 
			
		||||
{
 | 
			
		||||
    SECTION("multiply")
 | 
			
		||||
    {
 | 
			
		||||
	Vector test {5, 6};
 | 
			
		||||
	const int scalar = 2;
 | 
			
		||||
	test             = test * scalar;
 | 
			
		||||
	REQUIRE(test.x_ == 10);
 | 
			
		||||
	REQUIRE(test.y_ == 12);
 | 
			
		||||
	test = scalar * test;
 | 
			
		||||
	REQUIRE(test.x_ == 20);
 | 
			
		||||
	REQUIRE(test.y_ == 24);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
TEST_CASE("Vector operations work correctly", "[VECTOR]") {
 | 
			
		||||
  SECTION("multiply") {
 | 
			
		||||
    Vector test{5, 6};
 | 
			
		||||
    const int scalar = 2;
 | 
			
		||||
    test = test * scalar;
 | 
			
		||||
    REQUIRE(test.x_ == 10);
 | 
			
		||||
    REQUIRE(test.y_ == 12);
 | 
			
		||||
    test =  scalar * test;
 | 
			
		||||
    REQUIRE(test.x_ == 20);
 | 
			
		||||
    REQUIRE(test.y_ == 24);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
    SECTION("addition") {
 | 
			
		||||
    Vector test{5, 6};
 | 
			
		||||
    Vector test2{1,1};
 | 
			
		||||
    test = test + test2;
 | 
			
		||||
    REQUIRE(test.x_ == 6);
 | 
			
		||||
    REQUIRE(test.y_ == 7);
 | 
			
		||||
  }
 | 
			
		||||
      SECTION("subtraction") {
 | 
			
		||||
    Vector test{5, 6};
 | 
			
		||||
    Vector test2{1,1};
 | 
			
		||||
    test = test - test2;
 | 
			
		||||
    REQUIRE(test.x_ == 4);
 | 
			
		||||
    REQUIRE(test.y_ == 5);
 | 
			
		||||
  }
 | 
			
		||||
    SECTION("addition")
 | 
			
		||||
    {
 | 
			
		||||
	Vector test {5, 6};
 | 
			
		||||
	Vector test2 {1, 1};
 | 
			
		||||
	test = test + test2;
 | 
			
		||||
	REQUIRE(test.x_ == 6);
 | 
			
		||||
	REQUIRE(test.y_ == 7);
 | 
			
		||||
    }
 | 
			
		||||
    SECTION("subtraction")
 | 
			
		||||
    {
 | 
			
		||||
	Vector test {5, 6};
 | 
			
		||||
	Vector test2 {1, 1};
 | 
			
		||||
	test = test - test2;
 | 
			
		||||
	REQUIRE(test.x_ == 4);
 | 
			
		||||
	REQUIRE(test.y_ == 5);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST_CASE("Vectors are created correctly from points", "[VECTOR][POINT]") {
 | 
			
		||||
  SECTION("constructor") {
 | 
			
		||||
    Point a {5,6};
 | 
			
		||||
    Point b {2,5};
 | 
			
		||||
    auto test {a-b}; 
 | 
			
		||||
    REQUIRE(test.x_ == 3);
 | 
			
		||||
    REQUIRE(test.y_ == 1);
 | 
			
		||||
  }
 | 
			
		||||
TEST_CASE("Vectors are created correctly from points", "[VECTOR][POINT]")
 | 
			
		||||
{
 | 
			
		||||
    SECTION("constructor")
 | 
			
		||||
    {
 | 
			
		||||
	Point a {5, 6};
 | 
			
		||||
	Point b {2, 5};
 | 
			
		||||
	auto test {a - b};
 | 
			
		||||
	REQUIRE(test.x_ == 3);
 | 
			
		||||
	REQUIRE(test.y_ == 1);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
TEST_CASE("rects are created correctly from points", "[RECTANGLE]") {
 | 
			
		||||
  SECTION("constructor") {
 | 
			
		||||
    Point a {5,6};
 | 
			
		||||
    Point b {2,5};
 | 
			
		||||
    Rect test {a,b};
 | 
			
		||||
    REQUIRE(test.br.x == b.x);
 | 
			
		||||
    REQUIRE(test.br.y == b.y);
 | 
			
		||||
    REQUIRE(test.tl.x == a.x);
 | 
			
		||||
    REQUIRE(test.tl.y == a.y);
 | 
			
		||||
  }
 | 
			
		||||
TEST_CASE("rects are created correctly from points", "[RECTANGLE]")
 | 
			
		||||
{
 | 
			
		||||
    SECTION("constructor")
 | 
			
		||||
    {
 | 
			
		||||
	Point a {5, 6};
 | 
			
		||||
	Point b {2, 5};
 | 
			
		||||
	Rect test {a, b};
 | 
			
		||||
	REQUIRE(test.br.x == b.x);
 | 
			
		||||
	REQUIRE(test.br.y == b.y);
 | 
			
		||||
	REQUIRE(test.tl.x == a.x);
 | 
			
		||||
	REQUIRE(test.tl.y == a.y);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST_CASE("rect operations", "[RECTANGLE]") {
 | 
			
		||||
  SECTION("MOVE") {
 | 
			
		||||
    Point a {5,6};
 | 
			
		||||
    Point b {2,5};
 | 
			
		||||
    Rect test {a,b};
 | 
			
		||||
    const int scale = 2;
 | 
			
		||||
    Vector move {1,1};
 | 
			
		||||
    test.move(move);
 | 
			
		||||
    REQUIRE(test.br.x == b.x + 1);
 | 
			
		||||
    REQUIRE(test.br.y == b.y + 1);
 | 
			
		||||
    REQUIRE(test.tl.x == a.x+1);
 | 
			
		||||
    REQUIRE(test.tl.y == a.y+1);
 | 
			
		||||
  }
 | 
			
		||||
    SECTION("SCALE") {
 | 
			
		||||
    Point a {5,6};
 | 
			
		||||
    Point b {2,5};
 | 
			
		||||
    Rect test {a,b};
 | 
			
		||||
    const int scale = 2;
 | 
			
		||||
    Vector move = (b-a) * 2;
 | 
			
		||||
    Point newpoint = a + move;
 | 
			
		||||
    test.move(move);
 | 
			
		||||
    REQUIRE(test.br.x == newpoint.x);
 | 
			
		||||
    REQUIRE(test.br.y == newpoint.y);
 | 
			
		||||
    REQUIRE(test.tl.x == a.x);
 | 
			
		||||
    REQUIRE(test.tl.y == a.y);
 | 
			
		||||
  }
 | 
			
		||||
TEST_CASE("rect operations", "[RECTANGLE]")
 | 
			
		||||
{
 | 
			
		||||
    SECTION("MOVE")
 | 
			
		||||
    {
 | 
			
		||||
	Point a {5, 6};
 | 
			
		||||
	Point b {2, 5};
 | 
			
		||||
	Rect test {a, b};
 | 
			
		||||
	const int scale = 2;
 | 
			
		||||
	Vector move {1, 1};
 | 
			
		||||
	test.move(move);
 | 
			
		||||
	REQUIRE(test.br.x == b.x + 1);
 | 
			
		||||
	REQUIRE(test.br.y == b.y + 1);
 | 
			
		||||
	REQUIRE(test.tl.x == a.x + 1);
 | 
			
		||||
	REQUIRE(test.tl.y == a.y + 1);
 | 
			
		||||
    }
 | 
			
		||||
    SECTION("SCALE")
 | 
			
		||||
    {
 | 
			
		||||
	Point a {5, 6};
 | 
			
		||||
	Point b {2, 5};
 | 
			
		||||
	Rect test {a, b};
 | 
			
		||||
	Point newb = a + (b - a) * 2;
 | 
			
		||||
	const int scale = 2;
 | 
			
		||||
	test.scale(scale);
 | 
			
		||||
	REQUIRE(test.tl.x == a.x);
 | 
			
		||||
	REQUIRE(test.tl.y == a.y);
 | 
			
		||||
	REQUIRE(test.br.x == newb.x);
 | 
			
		||||
	REQUIRE(test.br.y == newb.y);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user