Added Item Tests file. Added a check to make sure item loadout slot is not blank when attempting to use the item loadout slot. 95/95 tests passing. Release Build 9944.
This commit is contained in:
@@ -99,6 +99,10 @@
|
||||
<ClCompile Include="..\Adventures in Lestoria\discord-files\user_manager.cpp" />
|
||||
<ClCompile Include="..\Adventures in Lestoria\discord-files\voice_manager.cpp" />
|
||||
<ClCompile Include="GeometryTests.cpp" />
|
||||
<ClCompile Include="ItemTests.cpp">
|
||||
<SubType>
|
||||
</SubType>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MonsterTests.cpp">
|
||||
<SubType>
|
||||
</SubType>
|
||||
|
||||
@@ -66,5 +66,8 @@
|
||||
<ClCompile Include="PlayerTests.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ItemTests.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,127 @@
|
||||
#pragma region License
|
||||
/*
|
||||
License (OLC-3)
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions or derivations of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions or derivative works in binary form must reproduce the above
|
||||
copyright notice. This list of conditions and the following disclaimer must be
|
||||
reproduced in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
Portions of this software are copyright © 2024 The FreeType
|
||||
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
||||
All rights reserved.
|
||||
*/
|
||||
#pragma endregion
|
||||
#include "CppUnitTest.h"
|
||||
#include "AdventuresInLestoria.h"
|
||||
#include "Tutorial.h"
|
||||
#include <random>
|
||||
#include <format>
|
||||
#include "ItemDrop.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
using namespace olc::utils;
|
||||
|
||||
INCLUDE_GFX
|
||||
INCLUDE_ITEM_DATA
|
||||
|
||||
extern std::mt19937 rng;
|
||||
|
||||
namespace ItemTests
|
||||
{
|
||||
TEST_CLASS(ItemTest)
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<AiL>testGame;
|
||||
InputGroup testKeyboardInput;
|
||||
Player*player;
|
||||
HWButton*testKey;
|
||||
TEST_METHOD_INITIALIZE(ItemInitialize){
|
||||
rng=std::mt19937{57189U};//Establish a fixed random seed on setup so the exact same results are generated every test run.
|
||||
testGame.reset(new AiL());
|
||||
testGame->olc_SetTestingMode(true);
|
||||
ItemAttribute::Initialize();
|
||||
ItemInfo::InitializeItems();
|
||||
testGame->InitializeGraphics();
|
||||
testGame->InitializeClasses();
|
||||
sig::Animation::InitializeAnimations();
|
||||
testGame->InitializeDefaultKeybinds();
|
||||
testGame->InitializePlayer();
|
||||
sig::Animation::SetupPlayerAnimations();
|
||||
Menu::InitializeMenus();
|
||||
Tutorial::Initialize();
|
||||
Stats::InitializeDamageReductionTable();
|
||||
|
||||
GameState::Initialize();
|
||||
GameState::STATE=GameState::states.at(States::State::GAME_RUN);
|
||||
|
||||
#pragma region Setup a fake test map and test monster
|
||||
game->MAP_DATA["CAMPAIGN_1_1"];
|
||||
ItemDrop::drops.clear();
|
||||
MonsterData testMonsterData{"TestName","Test Monster",1000,10,5,{MonsterDropData{"Health Potion",100.f,1,1}},200.f};
|
||||
MONSTER_DATA["TestName"]=testMonsterData;
|
||||
#pragma endregion
|
||||
|
||||
player=testGame->GetPlayer();
|
||||
//Setup key "0" as a test input
|
||||
testKeyboardInput.AddKeybind(Input{InputType::KEY,0});
|
||||
testKey=&testGame->pKeyboardState[0];
|
||||
testGame->olc_UpdateKeyFocus(true); //Force the game to be "focused" for tests. Required if we want keyboard inputs to work.
|
||||
Menu::themes.SetInitialized();
|
||||
GFX.SetInitialized();
|
||||
}
|
||||
TEST_METHOD_CLEANUP(CleanupTests){
|
||||
testGame->EndGame();
|
||||
}
|
||||
TEST_METHOD(ItemGiveTest){
|
||||
Inventory::AddItem("Health Potion"s,3);
|
||||
Assert::AreEqual(3U,Inventory::GetItemCount("Health Potion"s),L"Player has 3 Health Potions.");
|
||||
}
|
||||
TEST_METHOD(ItemRemoveTest){
|
||||
Inventory::AddItem("Health Potion"s,3);
|
||||
for(std::weak_ptr<Item>&item:Inventory::GetItem("Health Potion"s))Inventory::RemoveItem(item,3);
|
||||
Assert::AreEqual(0U,Inventory::GetItemCount("Health Potion"s),L"Player has no Health Potions.");
|
||||
}
|
||||
TEST_METHOD(ItemQuantityStackTest){
|
||||
Inventory::AddItem("Health Potion"s,3);
|
||||
Inventory::AddItem("Health Potion"s,3);
|
||||
Assert::AreEqual(6U,Inventory::GetItemCount("Health Potion"s),L"Player has 6 Health Potions.");
|
||||
}
|
||||
TEST_METHOD(EquipmentNoStackTest){
|
||||
Inventory::AddItem("Ring of the Slime King"s);
|
||||
Inventory::AddItem("Ring of the Slime King"s);
|
||||
Inventory::AddItem("Ring of the Slime King"s);
|
||||
int itemCounter{};
|
||||
for(std::weak_ptr<Item>&item:Inventory::GetItem("Ring of the Slime King"s))itemCounter++;
|
||||
Assert::AreEqual(3,itemCounter,L"3 separate item entries for Ring of the Slime King.");
|
||||
}
|
||||
TEST_METHOD(UsingBlankLoadoutItemDoesNothing){
|
||||
Assert::IsFalse(game->UseLoadoutItem(0),L"Using a blank loadout item slot (0) does not produce a result.");
|
||||
Assert::IsFalse(game->UseLoadoutItem(1),L"Using a blank loadout item slot (1) does not produce a result.");
|
||||
Assert::IsFalse(game->UseLoadoutItem(2),L"Using a blank loadout item slot (2) does not produce a result.");
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user