From b3d91307525ef92cf65982e5c1213cf11a64a49e Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 27 Aug 2022 16:42:42 +0000 Subject: [PATCH 1/2] Added a bunch of print statements for debugging purposes. --- src/entity.cpp | 3 +++ src/environment.cpp | 3 +++ src/grid.cpp | 5 ++++- src/location.cpp | 2 +- src/tests.cpp | 14 ++++++++++++-- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/entity.cpp b/src/entity.cpp index b1c9930..d24c5cb 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -1,6 +1,7 @@ #include "header/entity.h" #include +#include namespace envlibcpp { Entity::Entity(std::string entityName) { @@ -36,10 +37,12 @@ namespace envlibcpp { } void Entity::setEnvironmentId(int id) { + std::cout << "Entity::setEnvironmentId()" << std::endl; environmentId = id; } void Entity::setGridId(int id) { + std::cout << "Entity::setGridId()" << std::endl; gridId = id; } diff --git a/src/environment.cpp b/src/environment.cpp index 0520dfe..3fd9b59 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -1,5 +1,7 @@ #include "header/environment.h" +#include + namespace envlibcpp { Environment::Environment(std::string envName, int size) { id = rand() % 100 + 1; @@ -24,6 +26,7 @@ namespace envlibcpp { } void Environment::addEntity(Entity entity) { + std::cout << "Environment::addEntity()" << std::endl; entity.setEnvironmentId(id); grid.addEntity(entity); } diff --git a/src/grid.cpp b/src/grid.cpp index 63be070..57df294 100644 --- a/src/grid.cpp +++ b/src/grid.cpp @@ -24,6 +24,7 @@ namespace envlibcpp { } Location Grid::getFirstLocation() { + std::cout << "Grid::getFirstLocation()" << std::endl; return locations.front(); } @@ -69,8 +70,10 @@ namespace envlibcpp { } void Grid::addEntity(Entity entity) { + std::cout << "Grid::addEntity()" << std::endl; entity.setGridId(id); - getFirstLocation().addEntity(entity); + Location firstLocation = getFirstLocation(); + firstLocation.addEntity(entity); } void Grid::addEntityToLocation(Entity entity, Location location) { diff --git a/src/location.cpp b/src/location.cpp index fedbe8d..18f1e38 100644 --- a/src/location.cpp +++ b/src/location.cpp @@ -7,7 +7,6 @@ namespace envlibcpp { id = rand() % 100 + 1; x = xpos; y = ypos; - } int Location::getId() { @@ -27,6 +26,7 @@ namespace envlibcpp { } void Location::addEntity(Entity entity) { + std::cout << "Location::addEntity()" << std::endl; entity.setLocationId(getId()); entities.push_back(entity); } diff --git a/src/tests.cpp b/src/tests.cpp index 4403030..bda23ef 100644 --- a/src/tests.cpp +++ b/src/tests.cpp @@ -12,7 +12,9 @@ void testGridGeneration() { std::cout << "Test - Grid Generation" << std::endl; int size = 4; Environment environment("test environment", 4); - assert(environment.getGrid().getLocations().size() == size*size); + int numLocations = environment.getGrid().getLocations().size(); + int expectedNumLocations = size*size; + assert(numLocations == expectedNumLocations); std::cout << "Success" << std::endl; } @@ -21,8 +23,16 @@ void testEntityPlacement() { std::cout << "Test - Entity Placement" << std::endl; Entity entity("Daniel"); Environment environment("Earth", 2); + + Location firstLocation = environment.getGrid().getFirstLocation(); + std::cout << "before placement the first location (" << firstLocation.getId() << ") has " << firstLocation.getNumEntities() << " entities." << std::endl; + environment.addEntity(entity); - assert(environment.getNumEntities() > 0); + + std::cout << "after placement the first location (" << firstLocation.getId() << ") has " << firstLocation.getNumEntities() << " entities." << std::endl; + int numEntities = environment.getNumEntities(); + int expectedNumEntities = 1; + assert(numEntities == expectedNumEntities); std::cout << "Success" << std::endl; } From 8ef228ea7b145878f264bb2d169a7528a2772d6d Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sun, 28 Aug 2022 03:12:42 +0000 Subject: [PATCH 2/2] Modified entity placement test. --- .devcontainer/devcontainer.json | 4 +++- src/grid.cpp | 4 +--- src/tests.cpp | 8 +------- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f8584cd..3b5107a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -16,7 +16,9 @@ // Add the IDs of extensions you want installed when the container is created. "extensions": [ "ms-vscode.cpptools", - "ms-vscode.cmake-tools" + "ms-vscode.cmake-tools", + "ms-vscode.cpptools-extension-pack", + "franneck94.c-cpp-runner" ], // Use 'forwardPorts' to make a list of ports inside the container available locally. diff --git a/src/grid.cpp b/src/grid.cpp index 57df294..c7775c8 100644 --- a/src/grid.cpp +++ b/src/grid.cpp @@ -4,9 +4,7 @@ namespace envlibcpp { Grid::Grid() { - id = rand() % 100 + 1; - size = 4; - generateLocations(); + Grid(4); } Grid::Grid(int gridSize) { diff --git a/src/tests.cpp b/src/tests.cpp index bda23ef..f99cbaa 100644 --- a/src/tests.cpp +++ b/src/tests.cpp @@ -23,16 +23,10 @@ void testEntityPlacement() { std::cout << "Test - Entity Placement" << std::endl; Entity entity("Daniel"); Environment environment("Earth", 2); - - Location firstLocation = environment.getGrid().getFirstLocation(); - std::cout << "before placement the first location (" << firstLocation.getId() << ") has " << firstLocation.getNumEntities() << " entities." << std::endl; environment.addEntity(entity); - std::cout << "after placement the first location (" << firstLocation.getId() << ") has " << firstLocation.getNumEntities() << " entities." << std::endl; - int numEntities = environment.getNumEntities(); - int expectedNumEntities = 1; - assert(numEntities == expectedNumEntities); + assert(environment.isEntityPresent(entity) == true); std::cout << "Success" << std::endl; }