ICT290 / test / roomTest.cpp
roomTest.cpp
Raw
#include "../src/scene/theArchanist/map/gameRoom.h"
#include "gtest/gtest.h"

std::shared_ptr<gameRoom> makeRoom(int x, int z, int xOrigin, int zOrigin) {
    auto emptyModel = std::make_shared<Model>();
    gameRoom::RoomModels models{};
    models.walls.push_back(emptyModel);
    models.floors.push_back(emptyModel);
    models.debugSphere = emptyModel;
    models.debugCube = emptyModel;
    std::vector<std::pair<int, int>> doors;

    return std::make_shared<gameRoom>(x,
                                      z,
                                      5,
                                      5,
                                      xOrigin,
                                      zOrigin,
                                      models,
                                      0,
                                      doors);
}

void testRoom(int x,
              int z,
              int xOrigin,
              int zOrigin,
              std::shared_ptr<gameRoom>& test) {
    auto wallPoints{test->getWallPoints()};
    auto boundingSpheres{test->getBoundingSpheres()};

    // There must be 4 wall points
    ASSERT_TRUE(wallPoints.size() == 4);
    // Check each sub vector has it's first point, second point, and normal
    for (auto& wall : wallPoints) {
        ASSERT_TRUE(wall.size() == 3);
    }

    // Check all 8 points (ROOMS WITH NO DOORS ONLY)
    // Wall 1
    // P1
    ASSERT_TRUE(wallPoints[0][0].x == xOrigin + GR_OBJ_SCALE);
    ASSERT_TRUE(wallPoints[0][0].z == zOrigin + GR_OBJ_SCALE);
    // P2
    ASSERT_TRUE(wallPoints[0][1].x == x + xOrigin + GR_OBJ_SCALE);
    ASSERT_TRUE(wallPoints[0][1].z == zOrigin + GR_OBJ_SCALE);
    // Normal
    ASSERT_TRUE(wallPoints[0][2].x == 0);
    ASSERT_TRUE(wallPoints[0][2].z == 1);

    // Wall 2
    // P1
    ASSERT_TRUE(wallPoints[1][0].x == xOrigin + GR_OBJ_SCALE);
    ASSERT_TRUE(wallPoints[1][0].z == z + zOrigin + GR_OBJ_SCALE);
    // P2
    ASSERT_TRUE(wallPoints[1][1].x == x + xOrigin + GR_OBJ_SCALE);
    ASSERT_TRUE(wallPoints[1][1].z == z + zOrigin + GR_OBJ_SCALE);
    // Normal
    ASSERT_TRUE(wallPoints[1][2].x == 0);
    ASSERT_TRUE(wallPoints[1][2].z == -1);

    // Wall 3
    // P1
    ASSERT_TRUE(wallPoints[2][0].x == xOrigin + GR_OBJ_SCALE);
    ASSERT_TRUE(wallPoints[2][0].z == zOrigin + GR_OBJ_SCALE);
    // P2
    ASSERT_TRUE(wallPoints[2][1].x == xOrigin + GR_OBJ_SCALE);
    ASSERT_TRUE(wallPoints[2][1].z == z + zOrigin + GR_OBJ_SCALE);
    // Normal
    ASSERT_TRUE(wallPoints[2][2].x == 1);
    ASSERT_TRUE(wallPoints[2][2].z == 0);

    // Wall 4
    // P1
    ASSERT_TRUE(wallPoints[3][0].x == x + xOrigin + GR_OBJ_SCALE);
    ASSERT_TRUE(wallPoints[3][0].z == zOrigin + GR_OBJ_SCALE);
    // P2
    ASSERT_TRUE(wallPoints[3][1].x == x + xOrigin + GR_OBJ_SCALE);
    ASSERT_TRUE(wallPoints[3][1].z == z + zOrigin + GR_OBJ_SCALE);
    // Normal
    ASSERT_TRUE(wallPoints[3][2].x == -1);
    ASSERT_TRUE(wallPoints[3][2].z == 0);

    // No decorations added
    ASSERT_TRUE(boundingSpheres.empty());
}

TEST(RoomGenerationTest, TestWallPoints_xGreater) {
    int x{3}, z{77}, xOrigin{-45}, zOrigin{99};
    auto room = makeRoom(x, z, xOrigin, zOrigin);
    testRoom(x, z, xOrigin, zOrigin, room);
}

TEST(RoomGenerationTest, TestWallPoints_zGreater) {
    int x{50}, z{4}, xOrigin{55}, zOrigin{0};
    auto room = makeRoom(x, z, xOrigin, zOrigin);
    testRoom(x, z, xOrigin, zOrigin, room);
}

TEST(RoomGenerationTest, TestWallPoints_zOne) {
    int x{5}, z{1}, xOrigin{25}, zOrigin{66};
    auto room = makeRoom(x, z, xOrigin, zOrigin);
    testRoom(x, z, xOrigin, zOrigin, room);
}

TEST(RoomGenerationTest, TestWallPoints_xOne) {
    int x{1}, z{5}, xOrigin{0}, zOrigin{0};
    auto room = makeRoom(x, z, xOrigin, zOrigin);
    testRoom(x, z, xOrigin, zOrigin, room);
}

TEST(RoomGenerationTest, TestWallPoints_square) {
    int x{10}, z{10}, xOrigin{55}, zOrigin{0};
    auto room = makeRoom(x, z, xOrigin, zOrigin);
    testRoom(x, z, xOrigin, zOrigin, room);
}

TEST(RoomGenerationTest, TestWallPoints_square1x1) {
    int x{1}, z{1}, xOrigin{0}, zOrigin{0};
    auto room = makeRoom(x, z, xOrigin, zOrigin);
    testRoom(x, z, xOrigin, zOrigin, room);
}

TEST(RoomGenerationTest, TestWallPoints_squareLarge) {
    int x{100}, z{100}, xOrigin{0}, zOrigin{0};
    auto room = makeRoom(x, z, xOrigin, zOrigin);
    testRoom(x, z, xOrigin, zOrigin, room);
}