tests pass now
This commit is contained in:
parent
15621a57c3
commit
f547a37e8d
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){
|
||||
|
72
src/test.cpp
72
src/test.cpp
@ -1,20 +1,23 @@
|
||||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this
|
||||
// in one cpp file
|
||||
#include "Point.h"
|
||||
#include "../external/catch2.hpp"
|
||||
#include "Point.h"
|
||||
#include "shapes.h"
|
||||
|
||||
|
||||
TEST_CASE("Points are created correctly", "[POINT]") {
|
||||
SECTION("constructor") {
|
||||
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") {
|
||||
TEST_CASE("Point operations", "[POINT]")
|
||||
{
|
||||
SECTION("addition")
|
||||
{
|
||||
Point test {5, 6};
|
||||
Vector translation {1, 1};
|
||||
test = test + translation;
|
||||
@ -24,29 +27,30 @@ TEST_CASE("Point operations", "[POINT]") {
|
||||
REQUIRE(test.x == 7);
|
||||
REQUIRE(test.y == 8);
|
||||
}
|
||||
SECTION("subtraction") {
|
||||
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") {
|
||||
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") {
|
||||
TEST_CASE("Vector operations work correctly", "[VECTOR]")
|
||||
{
|
||||
SECTION("multiply")
|
||||
{
|
||||
Vector test {5, 6};
|
||||
const int scalar = 2;
|
||||
test = test * scalar;
|
||||
@ -57,14 +61,16 @@ TEST_CASE("Vector operations work correctly", "[VECTOR]") {
|
||||
REQUIRE(test.y_ == 24);
|
||||
}
|
||||
|
||||
SECTION("addition") {
|
||||
SECTION("addition")
|
||||
{
|
||||
Vector test {5, 6};
|
||||
Vector test2 {1, 1};
|
||||
test = test + test2;
|
||||
REQUIRE(test.x_ == 6);
|
||||
REQUIRE(test.y_ == 7);
|
||||
}
|
||||
SECTION("subtraction") {
|
||||
SECTION("subtraction")
|
||||
{
|
||||
Vector test {5, 6};
|
||||
Vector test2 {1, 1};
|
||||
test = test - test2;
|
||||
@ -73,8 +79,10 @@ TEST_CASE("Vector operations work correctly", "[VECTOR]") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Vectors are created correctly from points", "[VECTOR][POINT]") {
|
||||
SECTION("constructor") {
|
||||
TEST_CASE("Vectors are created correctly from points", "[VECTOR][POINT]")
|
||||
{
|
||||
SECTION("constructor")
|
||||
{
|
||||
Point a {5, 6};
|
||||
Point b {2, 5};
|
||||
auto test {a - b};
|
||||
@ -83,10 +91,10 @@ TEST_CASE("Vectors are created correctly from points", "[VECTOR][POINT]") {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("rects are created correctly from points", "[RECTANGLE]") {
|
||||
SECTION("constructor") {
|
||||
TEST_CASE("rects are created correctly from points", "[RECTANGLE]")
|
||||
{
|
||||
SECTION("constructor")
|
||||
{
|
||||
Point a {5, 6};
|
||||
Point b {2, 5};
|
||||
Rect test {a, b};
|
||||
@ -97,8 +105,10 @@ TEST_CASE("rects are created correctly from points", "[RECTANGLE]") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("rect operations", "[RECTANGLE]") {
|
||||
SECTION("MOVE") {
|
||||
TEST_CASE("rect operations", "[RECTANGLE]")
|
||||
{
|
||||
SECTION("MOVE")
|
||||
{
|
||||
Point a {5, 6};
|
||||
Point b {2, 5};
|
||||
Rect test {a, b};
|
||||
@ -110,17 +120,17 @@ TEST_CASE("rect operations", "[RECTANGLE]") {
|
||||
REQUIRE(test.tl.x == a.x + 1);
|
||||
REQUIRE(test.tl.y == a.y + 1);
|
||||
}
|
||||
SECTION("SCALE") {
|
||||
SECTION("SCALE")
|
||||
{
|
||||
Point a {5, 6};
|
||||
Point b {2, 5};
|
||||
Rect test {a, b};
|
||||
Point newb = a + (b - a) * 2;
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
57
testoo
Normal file
57
testoo
Normal file
@ -0,0 +1,57 @@
|
||||
SHELL=/usr/bin/zsh
|
||||
SESSION_MANAGER=local/manjari-linuj:@/tmp/.ICE-unix/1070,unix/manjari-linuj:/tmp/.ICE-unix/1070
|
||||
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session2
|
||||
DESKTOP_SESSION=/usr/share/xsessions/plasma
|
||||
GTK_RC_FILES=/etc/gtk/gtkrc:/home/massiveatoms/.gtkrc:/home/massiveatoms/.config/gtkrc
|
||||
EDITOR=/usr/bin/nano
|
||||
GTK_MODULES=canberra-gtk-module
|
||||
XDG_SEAT=seat0
|
||||
PWD=/home/massiveatoms/Desktop/testobuild
|
||||
XDG_SESSION_DESKTOP=KDE
|
||||
LOGNAME=massiveatoms
|
||||
XDG_SESSION_TYPE=x11
|
||||
_=/usr/bin/printenv
|
||||
XAUTHORITY=/tmp/xauth-1000-_0
|
||||
GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/massiveatoms/.gtkrc-2.0:/home/massiveatoms/.config/gtkrc-2.0
|
||||
HOME=/home/massiveatoms
|
||||
LANG=en_US.UTF-8
|
||||
XDG_CURRENT_DESKTOP=KDE
|
||||
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
|
||||
KDE_SESSION_UID=1000
|
||||
XDG_SESSION_CLASS=user
|
||||
USER=massiveatoms
|
||||
KDE_SESSION_VERSION=5
|
||||
PAM_KWALLET5_LOGIN=/run/user/1000/kwallet5.socket
|
||||
DISPLAY=:0
|
||||
SHLVL=1
|
||||
XDG_VTNR=1
|
||||
XDG_SESSION_ID=2
|
||||
QT_LINUX_ACCESSIBILITY_ALWAYS_ON=1
|
||||
MOZ_PLUGIN_PATH=/usr/lib/mozilla/plugins
|
||||
XDG_RUNTIME_DIR=/run/user/1000
|
||||
QT_AUTO_SCREEN_SCALE_FACTOR=0
|
||||
LC_COLLATE=C
|
||||
XCURSOR_THEME=volantes_cursors
|
||||
XDG_DATA_DIRS=/home/massiveatoms/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop
|
||||
KDE_FULL_SESSION=true
|
||||
BROWSER=/usr/bin/firefox
|
||||
PATH=/home/massiveatoms/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin
|
||||
GTK_USE_PORTAL=1
|
||||
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
|
||||
MAIL=/var/spool/mail/massiveatoms
|
||||
OLDPWD=/home/massiveatoms/Desktop/testobuild
|
||||
APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL=true
|
||||
NO_AT_BRIDGE=1
|
||||
CHROME_DESKTOP=code-oss.desktop
|
||||
TERM_PROGRAM=vscode
|
||||
TERM_PROGRAM_VERSION=1.43.2
|
||||
COLORTERM=truecolor
|
||||
TERM=xterm-256color
|
||||
LESS_TERMCAP_mb=[01;32m
|
||||
LESS_TERMCAP_md=[01;32m
|
||||
LESS_TERMCAP_me=[0m
|
||||
LESS_TERMCAP_se=[0m
|
||||
LESS_TERMCAP_so=[01;47;34m
|
||||
LESS_TERMCAP_ue=[0m
|
||||
LESS_TERMCAP_us=[01;36m
|
||||
LESS=-r
|
Loading…
Reference in New Issue
Block a user