diff --git a/README.md b/README.md index ce442d5e..20ec5812 100644 --- a/README.md +++ b/README.md @@ -90,14 +90,14 @@ If you have already installed **MinGW-w64** or **Visual Studio 2019**, all you n #### 1. Install dependent libraries in the project root ```bash - $ ./scripts/setup_libs.bat [-mingw/-msvc] [32/64] + $ ./scripts/setup_libs.bat [-mingw/-msvc] [32/64] [-update (optional)] ``` #### 2. Build this project with cmake and execute it ##### Automatically (Recommended) ```bash - $ ./build.bat [-debug/-release] [-mingw/-msvc] [32/64] [-update (optional)] + $ ./build.bat [-debug/-release] [-mingw/-msvc] [32/64] $ ./debug/win-vind.exe ``` diff --git a/build.bat b/build.bat index 7bfff8b5..8a8d1d63 100644 --- a/build.bat +++ b/build.bat @@ -1,6 +1,10 @@ @chcp 65001 @echo Usage: build.bat [-debug/-release] [-msvc/-mingw] [32/64] +@if %1 == -help ( + exit +) + @if "%1" == "" ( @set build_type=-debug ) else ( diff --git a/core/include/util/box_2d.hpp b/core/include/util/box_2d.hpp index 22222b28..95419c4f 100644 --- a/core/include/util/box_2d.hpp +++ b/core/include/util/box_2d.hpp @@ -30,10 +30,6 @@ namespace vind static_cast(bottom)) {} - explicit Box2D( - const POINT& center, - LONG width, - LONG height) ; explicit Box2D( const Point2D& center, LONG width, @@ -47,11 +43,11 @@ namespace vind Box2D(const Box2D&) ; Box2D& operator=(const Box2D&) ; - Box2D& operator=(const RECT&) ; - Box2D(Box2D&&) ; Box2D& operator=(Box2D&&) ; + Box2D& operator=(const RECT&) ; + LONG left() const noexcept ; LONG right() const noexcept ; LONG top() const noexcept ; diff --git a/scripts/setup_libs.bat b/scripts/setup_libs.bat index 2cbcf67d..8e0dfb00 100644 --- a/scripts/setup_libs.bat +++ b/scripts/setup_libs.bat @@ -1,17 +1,22 @@ +@chcp 65001 +@echo Usage: setup_libs.bat [-msvc/-mingw] [32/64] [-update (optional)] + +@if %1 == -help ( + @exit +) + @if not defined NUMBER_OF_PROCESSORS ( @echo Error: This script will not work with powershell. - exit + @exit ) @if "%1" == "" ( @echo. @echo Error: Please pass your compiler type -mingw or -msvc as the first argument. @echo. - exit + @exit ) -@chcp 65001 - @echo The number of processors is %NUMBER_OF_PROCESSORS%. @if not exist libs ( diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c20a4ca5..a2b9c6f6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -48,6 +48,8 @@ add_executable(core-test core/parser_rcparser_test.cpp core/mode_test.cpp + core/g_maps_test.cpp + core/g_params_test.cpp ) target_link_libraries(core-test doctest) add_test( diff --git a/test/core/g_maps_test.cpp b/test/core/g_maps_test.cpp new file mode 100644 index 00000000..e69de29b diff --git a/test/core/g_params_test.cpp b/test/core/g_params_test.cpp new file mode 100644 index 00000000..e69de29b diff --git a/test/core/util_box2d_test.cpp b/test/core/util_box2d_test.cpp index aa6bbe37..e2cc10a4 100644 --- a/test/core/util_box2d_test.cpp +++ b/test/core/util_box2d_test.cpp @@ -1,5 +1,173 @@ #include -#include "util/box_2d.hpp" +#include "util/box_2d.cpp" using namespace vind ; + + +TEST_CASE("(Box2D) Constructor test") { + LONG left = 200, top = 550, right = 400, bottom = 650 ; + + Box2D b0(left, top, right, bottom) ; + Box2D b1(left, top, right, bottom) ; + + Point2D center(300, 600) ; + LONG width = 200, height = 100 ; + Box2D b2(center, width, height) ; + + RECT rect{left, top, right, bottom} ; + Box2D b3(rect) ; + + RECT temp ; + util::copy(temp, rect) ; + Box2D b4(std::move(temp)) ; + + Box2D b5(10, 20, 234, 234) ; + + const Box2D b6(left, top, right, bottom) ; + + SUBCASE("Equel") { + CHECK(b0 == b1) ; + CHECK(b0 != b5) ; + } + + SUBCASE("Basic") { + CHECK(b1 == b2) ; + CHECK(b1 == b3) ; + CHECK(b1 == b4) ; + CHECK(b2 == b3) ; + CHECK(b2 == b4) ; + CHECK(b3 == b4) ; + } + + SUBCASE("Copy") { + Box2D c(b1) ; + CHECK(b1 == c) ; + + c = b5 ; + CHECK(c == b5) ; + } + + SUBCASE("Move") { + Box2D b5_copy(b5) ; + Box2D c(std::move(b5_copy)) ; + CHECK(b5 == c) ; + + Box2D b0_copy(b0) ; + c = std::move(b0_copy) ; + CHECK(c == b1) ; + } + + SUBCASE("Getter") { + CHECK_EQ(b0.left(), left) ; + CHECK_EQ(b0.top(), top) ; + CHECK_EQ(b0.right(), right) ; + CHECK_EQ(b0.bottom(), bottom) ; + + CHECK_EQ(b6.left(), left) ; + CHECK_EQ(b6.top(), top) ; + CHECK_EQ(b6.right(), right) ; + CHECK_EQ(b6.bottom(), bottom) ; + + CHECK(b2.center() == center) ; + CHECK_EQ(b2.center_x(), center.x()) ; + CHECK_EQ(b2.center_y(), center.y()) ; + + CHECK_EQ(b2.width(), width) ; + CHECK_EQ(b2.height(), height) ; + CHECK_EQ(b2.area(), width * height) ; + + CHECK(util::is_equel(b3, rect)) ; + CHECK(util::is_equel(b3.data(), rect)) ; + } +} + +TEST_CASE("(Box2D) operator value-based comparison") { + Box2D b0(0, 20, 30, 40) ; + Box2D b1(10, 20, 30, 40) ; + Box2D b2(10, 30, 30, 40) ; + Box2D b3(10, 30, 40, 40) ; + Box2D b4(10, 30, 40, 50) ; + + CHECK(b0 < b1) ; + CHECK(b0 < b2) ; + CHECK(b0 < b3) ; + CHECK(b0 < b4) ; + CHECK(b1 < b2) ; + CHECK(b1 < b3) ; + CHECK(b1 < b4) ; + CHECK(b2 < b3) ; + CHECK(b2 < b4) ; + CHECK(b3 < b4) ; + + CHECK(b0 <= b0) ; + CHECK(b0 <= b2) ; + CHECK(b0 <= b3) ; + CHECK(b0 <= b4) ; + CHECK(b1 <= b2) ; + CHECK(b1 <= b3) ; + CHECK(b1 <= b4) ; + CHECK(b2 <= b3) ; + CHECK(b2 <= b4) ; + CHECK(b3 <= b4) ; + + CHECK(b1 < b4) ; + CHECK(b2 < b4) ; + CHECK(b3 < b4) ; + CHECK(b2 < b3) ; + CHECK(b1 < b3) ; + CHECK(b1 < b2) ; + CHECK(b0 < b4) ; + CHECK(b0 < b3) ; + CHECK(b0 < b2) ; + CHECK(b0 < b1) ; + + CHECK(b1 <= b1) ; + CHECK(b1 <= b4) ; + CHECK(b2 <= b4) ; + CHECK(b3 <= b4) ; + CHECK(b2 <= b3) ; + CHECK(b1 <= b3) ; + CHECK(b1 <= b2) ; + CHECK(b0 <= b4) ; + CHECK(b0 <= b3) ; + CHECK(b0 <= b2) ; + CHECK(b0 <= b1) ; +} + +TEST_CASE("(Box2D) size-based comparison is_same()") { + Box2D b1(Point2D(20, 40), 400, 500) ; + Box2D b2(Point2D(40, 50), 400, 500) ; + CHECK(b1.is_same(b2)) ; + CHECK(b2.is_same(b1)) ; +} + +TEST_CASE("(Box2D) size-based comparison is_not_same()") { + Box2D b1(Point2D(20, 40), 400, 600) ; + Box2D b2(Point2D(40, 50), 300, 600) ; + Box2D b3(Point2D(40, 50), 400, 500) ; + CHECK(b1.is_not_same(b2)) ; + CHECK(b1.is_not_same(b3)) ; + CHECK(b2.is_not_same(b3)) ; +} + +TEST_CASE("(Box2D) size-based comparison") { + Box2D b1(Point2D(20, 40), 400, 500) ; + Box2D b2(Point2D(40, 50), 500, 600) ; + Box2D b3(Point2D(40, 50), 300, 700) ; + Box2D b4(Point2D(40, 50), 200, 700) ; + + CHECK(b2.is_bigger_than(b1)) ; + CHECK(b3.is_bigger_than(b1)) ; + + CHECK(b1.is_smaller_than(b2)) ; + CHECK_FALSE(b3.is_smaller_than(b1)) ; + + CHECK(b2.is_bigger_equel(b1)) ; + CHECK(b3.is_bigger_equel(b4)) ; + CHECK(b3.is_bigger_equel(b1)) ; + + CHECK(b1.is_smaller_equel(b2)) ; + CHECK(b4.is_smaller_equel(b3)) ; + CHECK_FALSE(b3.is_smaller_equel(b1)) ; +} diff --git a/test/core/util_point2d_test.cpp b/test/core/util_point2d_test.cpp index 58f248d8..c20bb0ef 100644 --- a/test/core/util_point2d_test.cpp +++ b/test/core/util_point2d_test.cpp @@ -6,7 +6,7 @@ using namespace vind ; -TEST_CASE("(util::Point2D) constructor and equel test") { +TEST_CASE("(Point2D) constructor and equel test") { Point2D p1(static_cast(20), static_cast(50)) ; Point2D p2(static_cast(20), static_cast(50)) ; @@ -23,7 +23,7 @@ TEST_CASE("(util::Point2D) constructor and equel test") { CHECK(p3 == p4) ; } -TEST_CASE("(util::Point2D) not equel") { +TEST_CASE("(Point2D) not equel") { Point2D p1(40, 50) ; Point2D p2(40, 52) ; @@ -31,7 +31,7 @@ TEST_CASE("(util::Point2D) not equel") { CHECK_FALSE(p1 == p2) ; } -TEST_CASE("(util::Point2D) getter test") { +TEST_CASE("(Point2D) getter test") { Point2D p(40, 50) ; POINT tp{40, 50} ; @@ -51,7 +51,7 @@ TEST_CASE("(util::Point2D) getter test") { CHECK_EQ(pp.y, tp.y) ; } -TEST_CASE("(util::Point2D) compare test") { +TEST_CASE("(Point2D) compare test") { Point2D p1(40, 50) ; Point2D p2(30, 60) ; Point2D p3(20, 50) ;