diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-05-20 13:12:31 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-05-20 13:12:31 +0300 |
| commit | a4e2f6753c6c2612444847fd12f1e973a86a4aa4 (patch) | |
| tree | 8f97d4ded431e366d8ec5e65172e2f80441dd53f /MundusTests/ServiceTests | |
| parent | 09d14d1f330d71bc69a4e9fedace680f9c69de3b (diff) | |
| download | Mundus-a4e2f6753c6c2612444847fd12f1e973a86a4aa4.tar Mundus-a4e2f6753c6c2612444847fd12f1e973a86a4aa4.tar.gz Mundus-a4e2f6753c6c2612444847fd12f1e973a86a4aa4.zip | |
Fixed test SetUps and TearDowns. Did tests for Inventory and MobTile (Service/Mobs). Did some minor changes to the program.
Diffstat (limited to 'MundusTests/ServiceTests')
6 files changed, 316 insertions, 51 deletions
diff --git a/MundusTests/ServiceTests/SuperLayers/HeightControllerTests.cs b/MundusTests/ServiceTests/SuperLayers/HeightControllerTests.cs index 70a2d02..88aa4aa 100644 --- a/MundusTests/ServiceTests/SuperLayers/HeightControllerTests.cs +++ b/MundusTests/ServiceTests/SuperLayers/HeightControllerTests.cs @@ -6,24 +6,19 @@ [TestFixture] public static class HeightControllerTests
- {
- [OneTimeSetUp]
- public static void SetUp() { - DataBaseContexts.CreateInstances();
- } - + { [Test] public static void GetsCorrectSuperLayerUnderneath()
{
Assert.AreEqual(DataBaseContexts.LContext, HeightController.GetSuperLayerUnderneath(DataBaseContexts.SContext), "GetSuperLayerUnderneath doesn't return that land is below sky");
Assert.AreEqual(DataBaseContexts.UContext, HeightController.GetSuperLayerUnderneath(DataBaseContexts.LContext), "GetSuperLayerUnderneath doesn't return that underground is below land");
- Assert.AreEqual(null, HeightController.GetSuperLayerUnderneath(DataBaseContexts.UContext), "GetSuperLayerUnderneath doesn't return that there is nothing (null) below underground");
+ Assert.IsNull(HeightController.GetSuperLayerUnderneath(DataBaseContexts.UContext), "GetSuperLayerUnderneath doesn't return that there is nothing (null) below underground");
}
[Test]
public static void GetsCorrectSuperLayerAbove()
{ - Assert.AreEqual(null, HeightController.GetSuperLayerAbove(DataBaseContexts.SContext), "GetSuperLayerUnderneath doesn't return that there is nothing (null) above sky");
+ Assert.IsNull(HeightController.GetSuperLayerAbove(DataBaseContexts.SContext), "GetSuperLayerUnderneath doesn't return that there is nothing (null) above sky");
Assert.AreEqual(DataBaseContexts.SContext, HeightController.GetSuperLayerAbove(DataBaseContexts.LContext), "GetSuperLayerUnderneath doesn't return that sky is above land");
Assert.AreEqual(DataBaseContexts.LContext, HeightController.GetSuperLayerAbove(DataBaseContexts.UContext), "GetSuperLayerUnderneath doesn't return that land is above underground"); } diff --git a/MundusTests/ServiceTests/SuperLayers/ImageControllerTests.cs b/MundusTests/ServiceTests/SuperLayers/ImageControllerTests.cs index c8d8e06..9ab6418 100644 --- a/MundusTests/ServiceTests/SuperLayers/ImageControllerTests.cs +++ b/MundusTests/ServiceTests/SuperLayers/ImageControllerTests.cs @@ -12,25 +12,11 @@ [TestFixture] public static class ImageControllerTests { - [OneTimeSetUp] - public static void SetUp() - { - Application.Init(); - DataBaseContexts.CreateInstances(); - WI.CreateInstances(); - WI.WNewGame.OnBtnGenerateClicked(null, null); - } - - [OneTimeTearDown] - public static void TearDown() - { - Application.Quit(); - } [Test] [TestCase(1, 5)] [TestCase(2, 2)] - [TestCase(8, 11)] + [TestCase(8, 10)] public static void GetsCorrectGroundImage(int yPos, int xPos) { Image img = null; diff --git a/MundusTests/ServiceTests/Tiles/Crafting/CraftingControllerTests.cs b/MundusTests/ServiceTests/Tiles/Crafting/CraftingControllerTests.cs index 1594f03..e0cd66d 100644 --- a/MundusTests/ServiceTests/Tiles/Crafting/CraftingControllerTests.cs +++ b/MundusTests/ServiceTests/Tiles/Crafting/CraftingControllerTests.cs @@ -12,21 +12,6 @@ [TestFixture] public static class CraftingControllerTests { - [OneTimeSetUp] - public static void SetUp() - { - Application.Init(); - DataBaseContexts.CreateInstances(); - WI.CreateInstances(); - WI.WNewGame.OnBtnGenerateClicked(null, null); - } - - [OneTimeTearDown] - public static void TearDown() - { - Application.Quit(); - } - [Test] public static void PlayerSuccessfullyCrafts() { diff --git a/MundusTests/ServiceTests/Tiles/Items/ItemControllerTests.cs b/MundusTests/ServiceTests/Tiles/Items/ItemControllerTests.cs index 1ccc228..497ccf3 100644 --- a/MundusTests/ServiceTests/Tiles/Items/ItemControllerTests.cs +++ b/MundusTests/ServiceTests/Tiles/Items/ItemControllerTests.cs @@ -10,19 +10,6 @@ using Mundus.Service.Tiles.Mobs; namespace MundusTests.ServiceTests.Tiles.Items { [TestFixture] public static class ItemControllerTests { - [OneTimeSetUp] - public static void SetUp() { - Application.Init(); - DataBaseContexts.CreateInstances(); - WI.CreateInstances(); - WI.WNewGame.OnBtnGenerateClicked(null, null); - } - - [OneTimeTearDown] - public static void TearDown() { - Application.Quit(); - } - [Test] [TestCase(InventoryPlace.Accessories, 1)] [TestCase(InventoryPlace.Hotbar, 4)] diff --git a/MundusTests/ServiceTests/Tiles/Mobs/InventoryTests.cs b/MundusTests/ServiceTests/Tiles/Mobs/InventoryTests.cs new file mode 100644 index 0000000..9f0d687 --- /dev/null +++ b/MundusTests/ServiceTests/Tiles/Mobs/InventoryTests.cs @@ -0,0 +1,252 @@ +using System; +using Mundus.Service.Tiles.Items; +using Mundus.Service.Tiles.Items.Types; +using Mundus.Service.Tiles.Mobs; +using NUnit.Framework; + +namespace MundusTests.ServiceTests.Tiles.Mobs { + [TestFixture] + public static class InventoryTests { + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AddsToHotbar(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToHotbar(new Material(stock_id1), 2); + inv.AddToHotbar(new Material(stock_id2), 4); + + Assert.AreEqual(stock_id1, inv.Hotbar[2].stock_id, "Add to hotbar doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Hotbar[4].stock_id, "Add to hotbar doesn't work as expected"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AddsToItems(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToItems(new Material(stock_id1), 2); + inv.AddToItems(new Material(stock_id2), 4); + + Assert.AreEqual(stock_id1, inv.Items[2].stock_id, "Add to items doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Items[4].stock_id, "Add to items doesn't work as expected"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AddsToAccessories(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToAccessories(new Gear(stock_id1), 2); + inv.AddToAccessories(new Gear(stock_id2), 4); + + Assert.AreEqual(stock_id1, inv.Accessories[2].stock_id, "Add to accessories doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Accessories[4].stock_id, "Add to accessories doesn't work as expected"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AddsToGear(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToGear(new Gear(stock_id1), 2); + inv.AddToGear(new Gear(stock_id2), 4); + + Assert.AreEqual(stock_id1, inv.Gear[2].stock_id, "Add to gear doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Gear[4].stock_id, "Add to gear doesn't work as expected"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AppendsToHotbar(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AppendToHotbar(new Material(stock_id1)); + inv.AppendToHotbar(new Material(stock_id2)); + + Assert.AreEqual(stock_id1, inv.Hotbar[0].stock_id, "Append to hotbar doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Hotbar[1].stock_id, "Append to hotbar doesn't work as expected"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AppendsToItems(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AppendToItems(new Material(stock_id1)); + inv.AppendToItems(new Material(stock_id2)); + + Assert.AreEqual(stock_id1, inv.Items[0].stock_id, "Append to items doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Items[1].stock_id, "Append to items doesn't work as expected"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AppendsToAccessories(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AppendToAccessories(new Gear(stock_id1)); + inv.AppendToAccessories(new Gear(stock_id2)); + + Assert.AreEqual(stock_id1, inv.Accessories[0].stock_id, "Append to accessories doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Accessories[1].stock_id, "Append to accessories doesn't work as expected"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AppendsToGear(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AppendToGear(new Gear(stock_id1)); + inv.AppendToGear(new Gear(stock_id2)); + + Assert.AreEqual(stock_id1, inv.Gear[0].stock_id, "Append to gear doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Gear[1].stock_id, "Append to gear doesn't work as expected"); + } + + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void DeletesFromHotbar(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToHotbar(new Gear(stock_id1), 2); + inv.AddToHotbar(new Gear(stock_id2), 4); + + inv.DeleteFromHotbar(2); + inv.DeleteFromHotbar(4); + + Assert.IsNull(inv.Hotbar[2], "Doesn't delete item properly from hotbar"); + Assert.IsNull(inv.Hotbar[4], "Doesn't delete item properly from hotbar"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void DeletesFromItems(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToItems(new Gear(stock_id1), 2); + inv.AddToItems(new Gear(stock_id2), 4); + + inv.DeleteFromItems(2); + inv.DeleteFromItems(4); + + Assert.IsNull(inv.Items[2], "Doesn't delete item properly from items"); + Assert.IsNull(inv.Items[4], "Doesn't delete item properly from items"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void DeletesFromAccessories(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToAccessories(new Gear(stock_id1), 2); + inv.AddToAccessories(new Gear(stock_id2), 4); + + inv.DeleteFromAccessories(2); + inv.DeleteFromAccessories(4); + + Assert.IsNull(inv.Accessories[2], "Doesn't delete item properly from accessories"); + Assert.IsNull(inv.Accessories[4], "Doesn't delete item properly from accessories"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void DeletesFromGear(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToGear(new Gear(stock_id1), 2); + inv.AddToGear(new Gear(stock_id2), 4); + + inv.DeleteFromGear(2); + inv.DeleteFromGear(4); + + Assert.IsNull(inv.Gear[2], "Doesn't delete item properly from gear"); + Assert.IsNull(inv.Gear[4], "Doesn't delete item properly from gear"); + } + + [Test] + [TestCase(1)] + [TestCase(5)] + [TestCase(10)] + public static void InstantiatesProperly(int size) { + Inventory inv = new Inventory(size); + + Assert.AreEqual(size, inv.Hotbar.Length, "Hotbar has incorrect size"); + Assert.AreEqual(size * size, inv.Items.Length, "Items has incorrect size"); + Assert.AreEqual(size * 2, inv.Accessories.Length, "Accessories has incorrect size"); + Assert.AreEqual(size, inv.Gear.Length, "Gear has incorrect size"); + } + + [Test] + [TestCase("one", 3)] + [TestCase(null, 1)] + [TestCase("", 4)] + public static void GetsProperHotbarItemTile(string stock_id, int index) { + Inventory inv = new Inventory(5); + + inv.AddToHotbar(new Material(stock_id), index); + + Assert.AreEqual(stock_id, inv.GetItemTile(Inventory.InventoryPlace.Hotbar, index).stock_id); + } + + [Test] + [TestCase("one", 3)] + [TestCase(null, 1)] + [TestCase("", 4)] + public static void GetsProperItemsItemTile(string stock_id, int index) { + Inventory inv = new Inventory(5); + + inv.AddToItems(new Material(stock_id), index); + + Assert.AreEqual(stock_id, inv.GetItemTile(Inventory.InventoryPlace.Items, index).stock_id); + } + + [Test] + [TestCase("one", 3)] + [TestCase(null, 1)] + [TestCase("", 4)] + public static void GetsProperAccessoriesItemTile(string stock_id, int index) { + Inventory inv = new Inventory(5); + + inv.AddToAccessories(new Gear(stock_id), index); + + Assert.AreEqual(stock_id, inv.GetItemTile(Inventory.InventoryPlace.Accessories, index).stock_id); + } + + [Test] + [TestCase("one", 3)] + [TestCase(null, 1)] + [TestCase("", 4)] + public static void GetsProperGearItemTile(string stock_id, int index) { + Inventory inv = new Inventory(5); + + inv.AddToGear(new Gear(stock_id), index); + + Assert.AreEqual(stock_id, inv.GetItemTile(Inventory.InventoryPlace.Gear, index).stock_id); + } + } +} diff --git a/MundusTests/ServiceTests/Tiles/Mobs/MobTileTests.cs b/MundusTests/ServiceTests/Tiles/Mobs/MobTileTests.cs new file mode 100644 index 0000000..b91877c --- /dev/null +++ b/MundusTests/ServiceTests/Tiles/Mobs/MobTileTests.cs @@ -0,0 +1,60 @@ +using System; +using Mundus.Data; +using Mundus.Data.Windows; +using Mundus.Service.Tiles.Items.Types; +using Mundus.Service.Tiles.Mobs; +using NUnit.Framework; + +namespace MundusTests.ServiceTests.Tiles.Mobs { + [TestFixture] + public static class MobTileTests { + [Test] + public static void InstantiatesProperly() { + MobTile mob = new MobTile("test", 10, 3, DataBaseContexts.SContext, 7, new Material("test_material"), 9); + + Assert.AreEqual("test", mob.stock_id); + Assert.AreEqual(10, mob.Health); + Assert.AreEqual(3, mob.Defense); + Assert.AreEqual(DataBaseContexts.SContext, mob.CurrSuperLayer); + Assert.AreEqual(7, mob.Inventory.Hotbar.Length); + Assert.AreEqual("test_material", mob.DroppedUponDeath.stock_id); + Assert.AreEqual(9, mob.RndMovementRate); + } + + [Test] + [TestCase(10, 3)] + [TestCase(19, 11)] + public static void AliveAfterTakingSmallDamage(int health, int damage) { + MobTile mob = new MobTile("test", health, 3, DataBaseContexts.SContext); + + Assert.IsTrue(mob.TakeDamage(damage)); + } + + [Test] + [TestCase(10, 10)] + [TestCase(13, 20)] + public static void DeadAfterTakingBigDamage(int health, int damage) { + MobTile mob = new MobTile("test", health, 3, DataBaseContexts.SContext); + + Assert.IsFalse(mob.TakeDamage(damage)); + } + + [Test] + [TestCase(10, 10)] + [TestCase(13, 20)] + public static void HealsProperly(int health, int healByPoints) { + MobTile mob = new MobTile("test", health, 3, DataBaseContexts.SContext); + + mob.Heal(healByPoints); + + if (health + healByPoints > WI.SelWin.Size * 4) { + Assert.AreEqual(WI.SelWin.Size, mob.Health); + } + else { + + Assert.AreEqual(health + healByPoints, mob.Health); + } + + } + } +} |
