Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Clean up of TODOs, adding tests to DialogEngineTests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercanuis committed Nov 10, 2019
1 parent 23fe7aa commit 9879728
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 23 deletions.
4 changes: 2 additions & 2 deletions DialogEngine/DialogGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ private void GenerateDialogMap()
{
printerType = DialogConstants.GetPrinterType(line);
}
catch(UtilErrors err)
catch (UtilityException err)
{
Console.WriteLine("Error Occurred during type retrival: " + err.Message);
Console.WriteLine("Error Occurred during type retrival: " + err.Message);
printerType = DialogConstants.GENERAL_PRINTER;
}

Expand Down
2 changes: 1 addition & 1 deletion DialogEngine/DialogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public IDialogPrinter GetForScript(string filePath)
printer = new RepeatingPrinter(gen.GetLines());
break;
case BATTLE:
printer = new BattlePrinter(gen.GetLines());
printer = new CustomPrinter(gen.GetLines());
break;
}
}
Expand Down
3 changes: 1 addition & 2 deletions DialogEngine/Printers/AbstractDialogPrinter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace DialogEngine.Printers
{
//TODO: Should this be public or internal
public abstract class AbstractDialogPrinter : IDialogPrinter
internal abstract class AbstractDialogPrinter : IDialogPrinter
{
public virtual string GetDialogLine()
{
Expand Down
3 changes: 2 additions & 1 deletion DialogEngine/Printers/Custom/BattlePrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace DialogEngine.Printers.Custom
{
public class BattlePrinter : CustomPrinter
//TODO: need to determine how to best use this. Right now this is only an extension of the CustomPrinter. Does this need to be moved to the BattleEngine?
class BattlePrinter : CustomPrinter
{
const int DAMAGE_TAKEN_TEXT = 0;
const int DAMAGE_DEALT_TEXT = 1;
Expand Down
2 changes: 1 addition & 1 deletion DialogEngine/Printers/Custom/CustomPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace DialogEngine.Printers.Custom
/// and then use specified dialog to format the parameters correctly.
/// </para>
/// </summary>
public class CustomPrinter : AbstractDialogPrinter
class CustomPrinter : AbstractDialogPrinter
{
private readonly Dictionary<int, string> dialogMap;

Expand Down
4 changes: 2 additions & 2 deletions DialogEngine/Utilities/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Utilities

}

class DialogConstants
public class DialogConstants
{
public const string GENERAL_PRINTER = "General";
public const string REPEATING_PRINTER = "Repeating";
Expand All @@ -28,7 +28,7 @@ public static string GetPrinterType(string fileLine)
return BATTLE_PRINTER;
}

throw new UtilErrors("File type was not found");
throw new UtilityException("File type was not found");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using DialogEngine.Printers;
using DialogEngine.Printers.Custom;
using DialogEngine.Utilities;
using Errors;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
Expand All @@ -9,13 +9,17 @@
namespace DialogEngine
{
[TestClass]
public class DialogGeneratorTest
public class DialogEngineTests
{
private readonly string FILEPATH = Path.Combine(Environment.CurrentDirectory, @"TestData\", "GeneralPrintFile.txt");
private readonly string BAD_FILEPATH = Path.Combine(Environment.CurrentDirectory, @"TestData\", "BAD.txt");
private readonly string REPEATING_FILEPATH = Path.Combine(Environment.CurrentDirectory, @"TestData\", "RepeatingPrintFile.txt");
private readonly string BATTLE_FILEPATH = Path.Combine(Environment.CurrentDirectory, @"TestData\", "BattleText.txt");

private readonly string BAD_FILEPATH = Path.Combine(Environment.CurrentDirectory, @"TestData\", "BAD.txt");
private readonly string INVALID_FILE_PATH = Path.Combine(Environment.CurrentDirectory, @"TestData\", "Invalidfile.txt");



[TestMethod]
public void TestGenerator_BadFilePath()
{
Expand Down Expand Up @@ -81,20 +85,30 @@ public void TestRepeatingPrinter()
public void TestBattlePrinter()
{
DialogManager mgmr = new DialogManager();
BattlePrinter underTest = (BattlePrinter)mgmr.GetForScript(BATTLE_FILEPATH);
IDialogPrinter underTest = mgmr.GetForScript(BATTLE_FILEPATH);

string[] dmgTakenParams = new string[] { "Terra", "25" };
Assert.AreEqual("Terra takes 25 points of damage.", underTest.GetDamageTaken(dmgTakenParams));
Assert.AreEqual("Terra takes 25 points of damage.", string.Format(underTest.GetDialogLine(0), dmgTakenParams));

string[] dmgDealtParams = new string[] { "Setzer", "Goblin", "12" };
Assert.AreEqual("Setzer hits the Goblin for 12 points of damage.", underTest.GetDamageDealt(dmgDealtParams));
Assert.AreEqual("Setzer hits the Goblin for 12 points of damage.", string.Format(underTest.GetDialogLine(1), dmgDealtParams));

string[] magDealtParams = new string[] { "Celes", "Ice", "Magitec Armor MkII", "150" };
Assert.AreEqual("Celes casts Ice! The Magitec Armor MkII takes 150 points of damage.", underTest.GetMagicDamageDealt(magDealtParams));
Assert.AreEqual("Celes casts Ice! The Magitec Armor MkII takes 150 points of damage.", string.Format(underTest.GetDialogLine(2), magDealtParams));

//Check to see if extra parameters are ignored, in case they're accidentially sent
string[] dmgTakenParams2 = new string[] { "Terra", "25", "35" };
Assert.AreEqual("Terra takes 25 points of damage.", underTest.GetDamageTaken(dmgTakenParams2));
Assert.AreEqual("Terra takes 25 points of damage.", string.Format(underTest.GetDialogLine(0), dmgTakenParams2));
}

[TestMethod]
public void TestInvalidType()
{
DialogManager mgmr = new DialogManager();
IDialogPrinter underTest = mgmr.GetForScript(INVALID_FILE_PATH);
Assert.AreEqual("This should be findable, but exception was thrown", underTest.GetDialogLine());
Assert.AreEqual("____END____", underTest.GetDialogLine());

}
}
}
3 changes: 3 additions & 0 deletions DialogEngineTests/DialogEngineTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<None Update="TestData\GeneralPrintFile.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestData\InvalidFile.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestData\RepeatingPrintFile.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
2 changes: 2 additions & 0 deletions DialogEngineTests/TestData/InvalidFile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DIALOG_TYPE=Invalid
This should be findable, but exception was thrown
File renamed without changes.
10 changes: 4 additions & 6 deletions Errors/UtilErrors.cs → Errors/UtilityException.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Errors
{
public class UtilErrors : Exception
public class UtilityException : Exception
{
private const string ERROR_MSG = "UtilityException";

/// <summary>
/// Generic Constructor for UtilError
/// </summary>
public UtilErrors()
public UtilityException()
{
}

public UtilErrors(string message)
public UtilityException(string message)
: base(String.Format("{0}: {1}", ERROR_MSG, message))
{
{
}
}
}

0 comments on commit 9879728

Please sign in to comment.