Skip to content

Commit

Permalink
add test of Box2D
Browse files Browse the repository at this point in the history
  • Loading branch information
pit-ray committed Jul 24, 2021
1 parent 492eef0 commit 80fc2f1
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
4 changes: 4 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
8 changes: 2 additions & 6 deletions core/include/util/box_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ namespace vind
static_cast<LONG>(bottom))
{}

explicit Box2D(
const POINT& center,
LONG width,
LONG height) ;
explicit Box2D(
const Point2D& center,
LONG width,
Expand All @@ -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 ;
Expand Down
13 changes: 9 additions & 4 deletions scripts/setup_libs.bat
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Empty file added test/core/g_maps_test.cpp
Empty file.
Empty file added test/core/g_params_test.cpp
Empty file.
170 changes: 169 additions & 1 deletion test/core/util_box2d_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,173 @@
#include <doctest.h>

#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)) ;
}
8 changes: 4 additions & 4 deletions test/core/util_point2d_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<LONG>(20), static_cast<LONG>(50)) ;

Point2D p2(static_cast<int>(20), static_cast<int>(50)) ;
Expand All @@ -23,15 +23,15 @@ 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) ;

CHECK(p1 != p2) ;
CHECK_FALSE(p1 == p2) ;
}

TEST_CASE("(util::Point2D) getter test") {
TEST_CASE("(Point2D) getter test") {
Point2D p(40, 50) ;
POINT tp{40, 50} ;

Expand All @@ -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) ;
Expand Down

0 comments on commit 80fc2f1

Please sign in to comment.