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.
This commit is contained in:
Michele Santullo 2015-08-17 13:36:47 +02:00
parent 981ec02afd
commit 4d8cbc4085
7 changed files with 70 additions and 26 deletions

View file

@ -10,7 +10,7 @@ namespace dkh {
template <typename T, typename T1>
dk::Vector<2> get_half_diamond_coordinates ( const dk::TileIterator<T, 2, T1>& parIterator, const dk::Vector<2>& parSize );
template <typename T, uint32_t D, typename T1>
template <uint32_t D, typename T, typename T1>
dk::Vector<D> get_square_coordinates ( const dk::TileIterator<T, D, T1>& parIterator, const dk::Vector<D>& parSize );
template <typename T, typename T1>

View file

@ -4,11 +4,10 @@ namespace dkh {
dk::Vector<2> get_diamond_coordinates (const dk::TileIterator<T, 2, T1>& 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 <typename T, typename T1>
@ -18,10 +17,10 @@ namespace dkh {
return get_diamond_coordinates(parIterator, parSize / vec(1, 2));
}
template <typename T, uint32_t D, typename T1>
template <uint32_t D, typename T, typename T1>
inline
dk::Vector<D> get_square_coordinates (const dk::TileIterator<T, D, T1>& parIterator, const dk::Vector<D>& parSize) {
return (parIterator.abs_position() - dk::implem::get_from_from_iterator(parIterator)) * parSize;
return parIterator.position() * parSize;
}
//template <typename T, typename T1>

View file

@ -1,25 +1,32 @@
#include <gtest/gtest.h>
#include "doorkeeper/helpers/asciimapsource.hpp"
#include "doorkeeper/doorkeeper.hpp"
#include "doorkeeper/helpers/tilecoordinates.hpp"
#include "asciimapsource.hpp"
#include <sstream>
#include <memory>
TEST(load, asciimapsource) {
typedef dk::Tyler<2>::coords coords2;
typedef std::unique_ptr<dkh::AsciiMapSource> 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<dkh::AsciiMapSource::MapTileType>(loader.get(), 0);
loader.reset(new dkh::AsciiMapSource(iss, coords2(map_width, map_height), dk::MapType_Isometric, coords2(tile_size)));
layer = &tiler.push_layer<dkh::AsciiMapSource::MapTileType>(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);
}
}

View file

@ -0,0 +1,26 @@
#ifndef idB5DCDE44F8E148AA8DD1CBD12649EFCD
#define idB5DCDE44F8E148AA8DD1CBD12649EFCD
#include <gtest/gtest.h>
#include "doorkeeper/doorkeeper.hpp"
class asciimapsource : public ::testing::Test {
protected:
typedef dk::Tyler<2>::coords coords2;
typedef std::unique_ptr<dkh::AsciiMapSource> 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<dkh::AsciiMapSource::MapTileType, 2>* layer;
AsciiMapSourceUPtr loader;
};
#endif

View file

@ -2,7 +2,7 @@
#include "doorkeeper/components/tilecoords.hpp"
#include <limits>
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;

View file

@ -4,7 +4,7 @@
#include <boost/iterator/counting_iterator.hpp>
#include <limits>
TEST(increment, tileiterator) {
TEST(tileiterator, increment) {
typedef dk::TileIterator<int, 7> tileit7;
typedef dk::Vector<7> coords7;

View file

@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#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;