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){
|
||||||
|
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
|
#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};
|
{
|
||||||
REQUIRE(test.x == 5);
|
Point test {5, 6};
|
||||||
REQUIRE(test.y == 6);
|
REQUIRE(test.x == 5);
|
||||||
}
|
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};
|
{
|
||||||
test = test + translation;
|
Point test {5, 6};
|
||||||
REQUIRE(test.x == 6);
|
Vector translation {1, 1};
|
||||||
REQUIRE(test.y == 7);
|
test = test + translation;
|
||||||
test = translation + test;
|
REQUIRE(test.x == 6);
|
||||||
REQUIRE(test.x == 7);
|
REQUIRE(test.y == 7);
|
||||||
REQUIRE(test.y == 8);
|
test = translation + test;
|
||||||
}
|
REQUIRE(test.x == 7);
|
||||||
SECTION("subtraction") {
|
REQUIRE(test.y == 8);
|
||||||
Point test{5, 6};
|
}
|
||||||
Vector translation {1,1};
|
SECTION("subtraction")
|
||||||
test = test - translation;
|
{
|
||||||
REQUIRE(test.x == 4);
|
Point test {5, 6};
|
||||||
REQUIRE(test.y == 5);
|
Vector translation {1, 1};
|
||||||
test = translation - test;
|
test = test - translation;
|
||||||
REQUIRE(test.x == 3);
|
REQUIRE(test.x == 4);
|
||||||
REQUIRE(test.y == 4);
|
REQUIRE(test.y == 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Vectors are created correctly", "[VECTOR]") {
|
TEST_CASE("Vectors are created correctly", "[VECTOR]")
|
||||||
SECTION("constructor") {
|
{
|
||||||
Vector test{5, 6};
|
SECTION("constructor")
|
||||||
REQUIRE(test.x_ == 5);
|
{
|
||||||
REQUIRE(test.y_ == 6);
|
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("addition")
|
||||||
SECTION("multiply") {
|
{
|
||||||
Vector test{5, 6};
|
Vector test {5, 6};
|
||||||
const int scalar = 2;
|
Vector test2 {1, 1};
|
||||||
test = test * scalar;
|
test = test + test2;
|
||||||
REQUIRE(test.x_ == 10);
|
REQUIRE(test.x_ == 6);
|
||||||
REQUIRE(test.y_ == 12);
|
REQUIRE(test.y_ == 7);
|
||||||
test = scalar * test;
|
}
|
||||||
REQUIRE(test.x_ == 20);
|
SECTION("subtraction")
|
||||||
REQUIRE(test.y_ == 24);
|
{
|
||||||
}
|
Vector test {5, 6};
|
||||||
|
Vector test2 {1, 1};
|
||||||
SECTION("addition") {
|
test = test - test2;
|
||||||
Vector test{5, 6};
|
REQUIRE(test.x_ == 4);
|
||||||
Vector test2{1,1};
|
REQUIRE(test.y_ == 5);
|
||||||
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]") {
|
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};
|
||||||
REQUIRE(test.x_ == 3);
|
Point b {2, 5};
|
||||||
REQUIRE(test.y_ == 1);
|
auto test {a - b};
|
||||||
}
|
REQUIRE(test.x_ == 3);
|
||||||
|
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);
|
||||||
REQUIRE(test.tl.y == a.y);
|
REQUIRE(test.tl.y == a.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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};
|
||||||
const int scale = 2;
|
Point b {2, 5};
|
||||||
Vector move {1,1};
|
Rect test {a, b};
|
||||||
test.move(move);
|
const int scale = 2;
|
||||||
REQUIRE(test.br.x == b.x + 1);
|
Vector move {1, 1};
|
||||||
REQUIRE(test.br.y == b.y + 1);
|
test.move(move);
|
||||||
REQUIRE(test.tl.x == a.x+1);
|
REQUIRE(test.br.x == b.x + 1);
|
||||||
REQUIRE(test.tl.y == a.y+1);
|
REQUIRE(test.br.y == b.y + 1);
|
||||||
}
|
REQUIRE(test.tl.x == a.x + 1);
|
||||||
SECTION("SCALE") {
|
REQUIRE(test.tl.y == a.y + 1);
|
||||||
Point a {5,6};
|
}
|
||||||
Point b {2,5};
|
SECTION("SCALE")
|
||||||
Rect test {a,b};
|
{
|
||||||
const int scale = 2;
|
Point a {5, 6};
|
||||||
Vector move = (b-a) * 2;
|
Point b {2, 5};
|
||||||
Point newpoint = a + move;
|
Rect test {a, b};
|
||||||
test.move(move);
|
Point newb = a + (b - a) * 2;
|
||||||
REQUIRE(test.br.x == newpoint.x);
|
const int scale = 2;
|
||||||
REQUIRE(test.br.y == newpoint.y);
|
test.scale(scale);
|
||||||
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