testobuild/test.cpp
TinyAtoms e1979c3da9 done
2020-04-17 13:17:19 -03:00

126 lines
2.8 KiB
C++

#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this
// in one cpp file
#include "Point.h"
#include "catch2.hpp"
#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("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("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);
}
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("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);
}
}