initial commit
[COMP345---Clone.git] / TestLevelMapBuilder.cpp
blobcd053c1e80ee51ca7428caba57a965dd0b7d2ad1
1 //! @file
2 //! @brief File containing the Test Class and the Test Methods for the LevelMapBuilder
3 //!
5 #include <iostream>
6 #include <cppunit/TestCase.h>
7 #include <cppunit/TestFixture.h>
8 #include <cppunit/ui/text/TextTestRunner.h>
9 #include <cppunit/extensions/HelperMacros.h>
10 #include <cppunit/extensions/TestFactoryRegistry.h>
11 #include <cppunit/TestResult.h>
12 #include <cppunit/TestResultCollector.h>
13 #include <cppunit/TestRunner.h>
14 #include <cppunit/BriefTestProgressListener.h>
15 #include <cppunit/CompilerOutputter.h>
16 #include <cppunit/XmlOutputter.h>
17 #include <cppunit/ui/text/TestRunner.h>
18 #include "LevelMapBuilder.h"
19 #include "MapDirector.h"
20 #include "Equipment.h"
21 using namespace CppUnit;
22 using namespace std;
25 //! Test Class for the LevelMapBuilder class
26 //! It must be a subclass of CppUnit::TestFixture
27 //! It then uses CPPUNIT_TEST_SUITE() to create the test suite, and CPPUNIT_TEST() to include the test methods in the test suite.
28 //! CPPUNIT_TEST_SUITE_REGISTRATION() is then used to register the test class in the test registry.
30 //! Test Class for the LevelMapBuilder class
31 class TestLevelMapBuilder : public CppUnit::TestFixture
33 CPPUNIT_TEST_SUITE(TestLevelMapBuilder);
34 CPPUNIT_TEST(testValidMonstersLMB);
35 CPPUNIT_TEST(testValidTreasuresLMB);
36 CPPUNIT_TEST(testValidMonsterLevel);
37 CPPUNIT_TEST(testValidTreasureLevel);
38 CPPUNIT_TEST_SUITE_END();
39 protected:
40 void testValidMonstersLMB(void);
41 void testValidTreasuresLMB(void);
42 void testValidMonsterLevel(void);
43 void testValidTreasureLevel(void);
46 //!Register for running the test
47 CPPUNIT_TEST_SUITE_REGISTRATION(TestLevelMapBuilder);//most important
49 //! Tests the Builder pattern creation of a map from a saved file using the LevelMapBuilder
50 //! This method tests whether or not the correct amount of monsters are created
51 //! A monster is denoted by an 'm' on the map. There are three 'm's so we expect 3 monsters to be created.
52 void TestLevelMapBuilder::testValidMonstersLMB(void)
54 MapDirector mapDirector;
55 LevelMapBuilder* lmb = new LevelMapBuilder(5);
56 mapDirector.setMapBuilder(lmb);
57 mapDirector.constructMap("map.txt");
58 Map* map = lmb->getMap();
59 vector<Monster>* monsters = lmb->getMonsters();
60 // There are 3 'm's in the example.txt so we expect two monsters to be made
61 CPPUNIT_ASSERT(monsters->size() == 3);
64 //! Tests the Builder pattern creation of a map from a saved file using the LevelMapBuilder
65 //! Treasure is a container for items
66 //! This method tests whether or not the correct amount of treasures are created
67 //! A treasure is denoted by an 't' on the map. There are two 't's so we expect 2 treasures to be created.
68 void TestLevelMapBuilder::testValidTreasuresLMB(void)
70 MapDirector mapDirector;
71 LevelMapBuilder* lmb = new LevelMapBuilder(5);
72 mapDirector.setMapBuilder(lmb);
73 mapDirector.constructMap("map.txt");
74 Map* map = lmb->getMap();
75 vector<vector<Item>>* treasureList = lmb->getTreasure();
76 // There are 2 't's in the example.txt so we expect two treasures to be made
77 CPPUNIT_ASSERT(treasureList->size() == 2);
80 //! Tests if the monster's level is appropriate
81 //! Each monster's level should be 5 because that is the level set for the map
82 void TestLevelMapBuilder::testValidMonsterLevel(void)
84 bool valid = true;
85 MapDirector mapDirector;
86 LevelMapBuilder* lmb = new LevelMapBuilder(5);
87 mapDirector.setMapBuilder(lmb);
88 mapDirector.constructMap("map.txt");
89 Map* map = lmb->getMap();
90 vector<Monster>* monsters = lmb->getMonsters();
91 for each (Monster monster in *monsters)
93 if (monster.getLevel() != 5)
94 valid = false;
96 // Assert that each monster is level 5
97 CPPUNIT_ASSERT(valid == true);
101 //! Tests if the treasure's level is appropriate
102 //! Each treasure's level should be 5 because that is the level set for the map
103 void TestLevelMapBuilder::testValidTreasureLevel(void)
105 bool valid = true;
106 MapDirector mapDirector;
107 LevelMapBuilder* lmb = new LevelMapBuilder(5);
108 mapDirector.setMapBuilder(lmb);
109 mapDirector.constructMap("map.txt");
110 Map* map = lmb->getMap();
111 // List containing treasures
112 vector<vector<Item>>* treasureList = lmb->getTreasure();
113 for each (vector<Item> itemVec in *treasureList)
115 // List containing items
116 for each (Item item in itemVec)
118 if (static_cast<Equipment&>(item).getLevel() != 5)
119 valid = false;
122 // Assert that each item in the treasure is level 5
123 CPPUNIT_ASSERT(valid == true);