From 4d8cbc4085c5fab3fe56979c4667c853aa9e5d3a Mon Sep 17 00:00:00 2001 From: Michele Santullo Date: Mon, 17 Aug 2015 13:36:47 +0200 Subject: [PATCH] Fix test names, fix build in tilecoordinates. I'm not sure the functions will still return the correct screen coordinates. For now it builds, I will add tests in the next commits. --- .../doorkeeper/helpers/tilecoordinates.hpp | 2 +- include/doorkeeper/implem/tilecoordinates.inl | 11 +++-- test/unit/asciimapsource.cpp | 45 +++++++++++++------ test/unit/asciimapsource.hpp | 26 +++++++++++ test/unit/tilecoords.cpp | 8 ++-- test/unit/tileiterator.cpp | 2 +- test/unit/vector.cpp | 2 +- 7 files changed, 70 insertions(+), 26 deletions(-) create mode 100644 test/unit/asciimapsource.hpp diff --git a/include/doorkeeper/helpers/tilecoordinates.hpp b/include/doorkeeper/helpers/tilecoordinates.hpp index 84bfbf3..3e0d605 100644 --- a/include/doorkeeper/helpers/tilecoordinates.hpp +++ b/include/doorkeeper/helpers/tilecoordinates.hpp @@ -10,7 +10,7 @@ namespace dkh { template dk::Vector<2> get_half_diamond_coordinates ( const dk::TileIterator& parIterator, const dk::Vector<2>& parSize ); - template + template dk::Vector get_square_coordinates ( const dk::TileIterator& parIterator, const dk::Vector& parSize ); template diff --git a/include/doorkeeper/implem/tilecoordinates.inl b/include/doorkeeper/implem/tilecoordinates.inl index 23a4d3b..0dca325 100644 --- a/include/doorkeeper/implem/tilecoordinates.inl +++ b/include/doorkeeper/implem/tilecoordinates.inl @@ -4,11 +4,10 @@ namespace dkh { dk::Vector<2> get_diamond_coordinates (const dk::TileIterator& parIterator, const dk::Vector<2>& parSize) { typedef dk::Vector<2> vec; - const auto abspos(parIterator.abs_position()); - const auto from(dk::implem::get_from_from_iterator(parIterator)); - const dk::CoordinateScalarType xoffs = abspos.y() % 2; + const auto from(parIterator.position()); + const dk::CoordinateScalarType xoffs = from.y() % 2; - return (abspos - from) * parSize + vec(xoffs * parSize.x() / 2, 0); + return from * parSize + vec(xoffs * parSize.x() / 2, 0); } template @@ -18,10 +17,10 @@ namespace dkh { return get_diamond_coordinates(parIterator, parSize / vec(1, 2)); } - template + template inline dk::Vector get_square_coordinates (const dk::TileIterator& parIterator, const dk::Vector& parSize) { - return (parIterator.abs_position() - dk::implem::get_from_from_iterator(parIterator)) * parSize; + return parIterator.position() * parSize; } //template diff --git a/test/unit/asciimapsource.cpp b/test/unit/asciimapsource.cpp index d2f399f..0189ed6 100644 --- a/test/unit/asciimapsource.cpp +++ b/test/unit/asciimapsource.cpp @@ -1,25 +1,32 @@ #include #include "doorkeeper/helpers/asciimapsource.hpp" #include "doorkeeper/doorkeeper.hpp" +#include "doorkeeper/helpers/tilecoordinates.hpp" +#include "asciimapsource.hpp" #include #include -TEST(load, asciimapsource) { - typedef dk::Tyler<2>::coords coords2; - typedef std::unique_ptr AsciiMapSourceUPtr; - - const char map_data[] = - "1101111001\n1101111001\n1110111100\n1110111000\n" - "1111011011\n1111010111\n1111101111\n1111111111\n"; - const dk::CoordinateScalarType tile_size = 64; - const dk::CoordinateScalarType map_width = 10; - const dk::CoordinateScalarType map_height = 8; +const char asciimapsource::map_data[] = + "1101111001\n1101111001\n1110111100\n1110111000\n" + "1111011011\n1111010111\n1111101111\n1111111111\n"; +const dk::CoordinateScalarType asciimapsource::tile_size = 64; +const dk::CoordinateScalarType asciimapsource::map_width = 10; +const dk::CoordinateScalarType asciimapsource::map_height = 8; +asciimapsource::asciimapsource() : + tiler(coords2(tile_size)), + layer(nullptr) +{ std::istringstream iss((std::string(map_data))); - dk::Tyler<2> tiler((coords2(tile_size))); - AsciiMapSourceUPtr loader(new dkh::AsciiMapSource(iss, coords2(map_width, map_height), dk::MapType_Isometric, coords2(tile_size))); - auto layer = &tiler.push_layer(loader.get(), 0); + loader.reset(new dkh::AsciiMapSource(iss, coords2(map_width, map_height), dk::MapType_Isometric, coords2(tile_size))); + layer = &tiler.push_layer(loader.get(), 0); +} +void asciimapsource::SetUp() { + ASSERT_NE(nullptr, layer); +} + +TEST_F(asciimapsource, load) { dk::Viewport<2> full_view(tiler, coords2(map_width, map_height), coords2(0)); EXPECT_EQ(coords2(map_width, map_height), tiler.map_size()); @@ -41,3 +48,15 @@ TEST(load, asciimapsource) { } EXPECT_EQ(map_width * map_height, index); } + +TEST_F(asciimapsource, coordinates) { + const coords2 tile_size(32); + dk::Viewport<2> full_view(tiler, coords2(map_width, map_height), coords2(0)); + + full_view.setFrom(coords2(0)); + for (auto itTile = full_view.begin(*layer), itTileEND = full_view.end(*layer); itTile != itTileEND; ++itTile) { + const coords2 expected_coords(tile_size * itTile.position()); + const auto returned_coords(dkh::get_square_coordinates<2>(itTile, tile_size)); + EXPECT_EQ(expected_coords, returned_coords); + } +} diff --git a/test/unit/asciimapsource.hpp b/test/unit/asciimapsource.hpp new file mode 100644 index 0000000..6e97522 --- /dev/null +++ b/test/unit/asciimapsource.hpp @@ -0,0 +1,26 @@ +#ifndef idB5DCDE44F8E148AA8DD1CBD12649EFCD +#define idB5DCDE44F8E148AA8DD1CBD12649EFCD + +#include +#include "doorkeeper/doorkeeper.hpp" + +class asciimapsource : public ::testing::Test { +protected: + typedef dk::Tyler<2>::coords coords2; + typedef std::unique_ptr AsciiMapSourceUPtr; + + asciimapsource ( void ); + virtual ~asciimapsource ( void ) noexcept = default; + virtual void SetUp ( void ); + + static const char map_data[]; + static const dk::CoordinateScalarType tile_size; + static const dk::CoordinateScalarType map_width; + static const dk::CoordinateScalarType map_height; + + dk::Tyler<2> tiler; + dk::Layer* layer; + AsciiMapSourceUPtr loader; +}; + +#endif diff --git a/test/unit/tilecoords.cpp b/test/unit/tilecoords.cpp index c496da3..1573af0 100644 --- a/test/unit/tilecoords.cpp +++ b/test/unit/tilecoords.cpp @@ -2,7 +2,7 @@ #include "doorkeeper/components/tilecoords.hpp" #include -TEST(increment, tilecoords) { +TEST(tilecoords, increment) { typedef dk::TileCoords<2> tcoords2; typedef dk::TileCoords<2>::coords coords2; typedef dk::TileCoords<5> tcoords5; @@ -32,7 +32,7 @@ TEST(increment, tilecoords) { } } -TEST(advance, tilecoords) { +TEST(tilecoords, advance) { typedef dk::TileCoords<4> tcoords4; typedef dk::TileCoords<4>::coords coords4; @@ -92,7 +92,7 @@ TEST(advance, tilecoords) { } } -TEST(back_forward, tilecoords) { +TEST(tilecoords, back_forward) { typedef dk::TileCoords<4> tcoords4; typedef dk::TileCoords<4>::coords coords4; @@ -141,7 +141,7 @@ TEST(back_forward, tilecoords) { } } -TEST(to_index, tilecoords) { +TEST(tilecoords, to_index) { typedef dk::TileCoords<2> tcoords2; typedef dk::TileCoords<2>::coords coords2; diff --git a/test/unit/tileiterator.cpp b/test/unit/tileiterator.cpp index d9fd96c..b330d7e 100644 --- a/test/unit/tileiterator.cpp +++ b/test/unit/tileiterator.cpp @@ -4,7 +4,7 @@ #include #include -TEST(increment, tileiterator) { +TEST(tileiterator, increment) { typedef dk::TileIterator tileit7; typedef dk::Vector<7> coords7; diff --git a/test/unit/vector.cpp b/test/unit/vector.cpp index 7cc5898..cd573c8 100644 --- a/test/unit/vector.cpp +++ b/test/unit/vector.cpp @@ -1,7 +1,7 @@ #include #include "doorkeeper/primitivetypes.hpp" -TEST(misc, vector) { +TEST(vector, misc) { typedef dk::Vector<2> coords2; typedef dk::Vector<3> coords3; typedef dk::Vector<8> coords8;