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) {
|
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) {
|
Point operator+(Point lhs, Vector rhs) {
|
||||||
return Point{rhs.x_ + lhs.x, rhs.x_ + lhs.x};
|
return Point{rhs.x_ + lhs.x, rhs.y_ + lhs.y};
|
||||||
}
|
|
||||||
|
|
||||||
Point operator-(Vector lhs, Point rhs) {
|
|
||||||
return Point{rhs.x - lhs.x_, rhs.x - lhs.x_};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Point operator-(Point lhs, Vector rhs) {
|
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){
|
Vector operator-(Point lhs, Point rhs){
|
||||||
|
124
src/test.cpp
124
src/test.cpp
@ -1,22 +1,25 @@
|
|||||||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this
|
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this
|
||||||
// in one cpp file
|
// in one cpp file
|
||||||
#include "Point.h"
|
|
||||||
#include "../external/catch2.hpp"
|
#include "../external/catch2.hpp"
|
||||||
|
#include "Point.h"
|
||||||
#include "shapes.h"
|
#include "shapes.h"
|
||||||
|
|
||||||
|
TEST_CASE("Points are created correctly", "[POINT]")
|
||||||
TEST_CASE("Points are created correctly", "[POINT]") {
|
{
|
||||||
SECTION("constructor") {
|
SECTION("constructor")
|
||||||
Point test{5, 6};
|
{
|
||||||
|
Point test {5, 6};
|
||||||
REQUIRE(test.x == 5);
|
REQUIRE(test.x == 5);
|
||||||
REQUIRE(test.y == 6);
|
REQUIRE(test.y == 6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Point operations", "[POINT]") {
|
TEST_CASE("Point operations", "[POINT]")
|
||||||
SECTION("addition") {
|
{
|
||||||
Point test{5, 6};
|
SECTION("addition")
|
||||||
Vector translation {1,1};
|
{
|
||||||
|
Point test {5, 6};
|
||||||
|
Vector translation {1, 1};
|
||||||
test = test + translation;
|
test = test + translation;
|
||||||
REQUIRE(test.x == 6);
|
REQUIRE(test.x == 6);
|
||||||
REQUIRE(test.y == 7);
|
REQUIRE(test.y == 7);
|
||||||
@ -24,30 +27,31 @@ TEST_CASE("Point operations", "[POINT]") {
|
|||||||
REQUIRE(test.x == 7);
|
REQUIRE(test.x == 7);
|
||||||
REQUIRE(test.y == 8);
|
REQUIRE(test.y == 8);
|
||||||
}
|
}
|
||||||
SECTION("subtraction") {
|
SECTION("subtraction")
|
||||||
Point test{5, 6};
|
{
|
||||||
Vector translation {1,1};
|
Point test {5, 6};
|
||||||
|
Vector translation {1, 1};
|
||||||
test = test - translation;
|
test = test - translation;
|
||||||
REQUIRE(test.x == 4);
|
REQUIRE(test.x == 4);
|
||||||
REQUIRE(test.y == 5);
|
REQUIRE(test.y == 5);
|
||||||
test = translation - test;
|
|
||||||
REQUIRE(test.x == 3);
|
|
||||||
REQUIRE(test.y == 4);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Vectors are created correctly", "[VECTOR]") {
|
TEST_CASE("Vectors are created correctly", "[VECTOR]")
|
||||||
SECTION("constructor") {
|
{
|
||||||
Vector test{5, 6};
|
SECTION("constructor")
|
||||||
|
{
|
||||||
|
Vector test {5, 6};
|
||||||
REQUIRE(test.x_ == 5);
|
REQUIRE(test.x_ == 5);
|
||||||
REQUIRE(test.y_ == 6);
|
REQUIRE(test.y_ == 6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Vector operations work correctly", "[VECTOR]")
|
||||||
TEST_CASE("Vector operations work correctly", "[VECTOR]") {
|
{
|
||||||
SECTION("multiply") {
|
SECTION("multiply")
|
||||||
Vector test{5, 6};
|
{
|
||||||
|
Vector test {5, 6};
|
||||||
const int scalar = 2;
|
const int scalar = 2;
|
||||||
test = test * scalar;
|
test = test * scalar;
|
||||||
REQUIRE(test.x_ == 10);
|
REQUIRE(test.x_ == 10);
|
||||||
@ -57,39 +61,43 @@ TEST_CASE("Vector operations work correctly", "[VECTOR]") {
|
|||||||
REQUIRE(test.y_ == 24);
|
REQUIRE(test.y_ == 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("addition") {
|
SECTION("addition")
|
||||||
Vector test{5, 6};
|
{
|
||||||
Vector test2{1,1};
|
Vector test {5, 6};
|
||||||
|
Vector test2 {1, 1};
|
||||||
test = test + test2;
|
test = test + test2;
|
||||||
REQUIRE(test.x_ == 6);
|
REQUIRE(test.x_ == 6);
|
||||||
REQUIRE(test.y_ == 7);
|
REQUIRE(test.y_ == 7);
|
||||||
}
|
}
|
||||||
SECTION("subtraction") {
|
SECTION("subtraction")
|
||||||
Vector test{5, 6};
|
{
|
||||||
Vector test2{1,1};
|
Vector test {5, 6};
|
||||||
|
Vector test2 {1, 1};
|
||||||
test = test - test2;
|
test = test - test2;
|
||||||
REQUIRE(test.x_ == 4);
|
REQUIRE(test.x_ == 4);
|
||||||
REQUIRE(test.y_ == 5);
|
REQUIRE(test.y_ == 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Vectors are created correctly from points", "[VECTOR][POINT]") {
|
TEST_CASE("Vectors are created correctly from points", "[VECTOR][POINT]")
|
||||||
SECTION("constructor") {
|
{
|
||||||
Point a {5,6};
|
SECTION("constructor")
|
||||||
Point b {2,5};
|
{
|
||||||
auto test {a-b};
|
Point a {5, 6};
|
||||||
|
Point b {2, 5};
|
||||||
|
auto test {a - b};
|
||||||
REQUIRE(test.x_ == 3);
|
REQUIRE(test.x_ == 3);
|
||||||
REQUIRE(test.y_ == 1);
|
REQUIRE(test.y_ == 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("rects are created correctly from points", "[RECTANGLE]")
|
||||||
|
{
|
||||||
TEST_CASE("rects are created correctly from points", "[RECTANGLE]") {
|
SECTION("constructor")
|
||||||
SECTION("constructor") {
|
{
|
||||||
Point a {5,6};
|
Point a {5, 6};
|
||||||
Point b {2,5};
|
Point b {2, 5};
|
||||||
Rect test {a,b};
|
Rect test {a, b};
|
||||||
REQUIRE(test.br.x == b.x);
|
REQUIRE(test.br.x == b.x);
|
||||||
REQUIRE(test.br.y == b.y);
|
REQUIRE(test.br.y == b.y);
|
||||||
REQUIRE(test.tl.x == a.x);
|
REQUIRE(test.tl.x == a.x);
|
||||||
@ -97,30 +105,32 @@ TEST_CASE("rects are created correctly from points", "[RECTANGLE]") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("rect operations", "[RECTANGLE]") {
|
TEST_CASE("rect operations", "[RECTANGLE]")
|
||||||
SECTION("MOVE") {
|
{
|
||||||
Point a {5,6};
|
SECTION("MOVE")
|
||||||
Point b {2,5};
|
{
|
||||||
Rect test {a,b};
|
Point a {5, 6};
|
||||||
|
Point b {2, 5};
|
||||||
|
Rect test {a, b};
|
||||||
const int scale = 2;
|
const int scale = 2;
|
||||||
Vector move {1,1};
|
Vector move {1, 1};
|
||||||
test.move(move);
|
test.move(move);
|
||||||
REQUIRE(test.br.x == b.x + 1);
|
REQUIRE(test.br.x == b.x + 1);
|
||||||
REQUIRE(test.br.y == b.y + 1);
|
REQUIRE(test.br.y == b.y + 1);
|
||||||
REQUIRE(test.tl.x == a.x+1);
|
REQUIRE(test.tl.x == a.x + 1);
|
||||||
REQUIRE(test.tl.y == a.y+1);
|
REQUIRE(test.tl.y == a.y + 1);
|
||||||
}
|
}
|
||||||
SECTION("SCALE") {
|
SECTION("SCALE")
|
||||||
Point a {5,6};
|
{
|
||||||
Point b {2,5};
|
Point a {5, 6};
|
||||||
Rect test {a,b};
|
Point b {2, 5};
|
||||||
|
Rect test {a, b};
|
||||||
|
Point newb = a + (b - a) * 2;
|
||||||
const int scale = 2;
|
const int scale = 2;
|
||||||
Vector move = (b-a) * 2;
|
test.scale(scale);
|
||||||
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.x == a.x);
|
||||||
REQUIRE(test.tl.y == a.y);
|
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