ConditionalGameActionTests.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using NUnit.Framework;
  4. using UnityEngine;
  5. using UnityEngine.TestTools;
  6. using KairoEngine.Core;
  7. using KairoEngine.Core.GameActions;
  8. namespace KairoEngine.Core.EditorTests.GameActions
  9. {
  10. public class ConditionalGameActionTests
  11. {
  12. private GameActionsController controller;
  13. private ConditionalGameAction conditional;
  14. private GameActionContextString stringVariable;
  15. private CompareStringsGameActionCondition compareStrings;
  16. private DebugLogGameAction debugAction1;
  17. private DebugLogGameAction debugAction2;
  18. [SetUp]
  19. public void Setup()
  20. {
  21. controller = new GameActionsController();
  22. // Create conditional action
  23. conditional = new ConditionalGameAction(controller);
  24. // Create string variable
  25. stringVariable = new GameActionContextString();
  26. stringVariable.name = "stringVariable";
  27. stringVariable.value = "test";
  28. controller.context.variables.Add(stringVariable);
  29. // Create compare strings condition
  30. compareStrings = new CompareStringsGameActionCondition();
  31. compareStrings.variable = "stringVariable";
  32. compareStrings.stringValue = "test";
  33. compareStrings.equals = true;
  34. compareStrings.controller = controller;
  35. conditional.conditions.Add(compareStrings);
  36. // Create debug action for true condition
  37. debugAction1 = new DebugLogGameAction(conditional.ifController);
  38. debugAction1.message ="if path";
  39. conditional.ifController.actions.Add(debugAction1);
  40. // Create debug action for false condition
  41. debugAction2 = new DebugLogGameAction(conditional.ifController);
  42. debugAction2.message ="else path";
  43. conditional.elseController.actions.Add(debugAction2);
  44. // Add conditional to controller and start
  45. controller.actions.Add(conditional);
  46. }
  47. [TearDown]
  48. public void TearDown()
  49. {
  50. controller = null;
  51. conditional = null;
  52. stringVariable = null;
  53. compareStrings = null;
  54. debugAction1 = null;
  55. debugAction2 = null;
  56. }
  57. [UnityTest]
  58. public IEnumerator ConditionalGameAction_IfPathIntegrationTest()
  59. {
  60. LogAssert.Expect(LogType.Log, "if path");
  61. controller.Start();
  62. yield return null;
  63. yield return null;
  64. yield return null;
  65. yield return null;
  66. yield return null;
  67. }
  68. [UnityTest]
  69. public IEnumerator ConditionalGameAction_ElsePathIntegrationTest()
  70. {
  71. compareStrings.equals = false;
  72. LogAssert.Expect(LogType.Log, "else path");
  73. controller.Start();
  74. yield return null;
  75. yield return null;
  76. yield return null;
  77. yield return null;
  78. yield return null;
  79. }
  80. [UnityTest]
  81. public IEnumerator ConditionalGameAction_DuplicationTest()
  82. {
  83. GameActionsController newController = controller.Duplicate();
  84. LogAssert.Expect(LogType.Log, "if path");
  85. newController.Start();
  86. yield return null;
  87. yield return null;
  88. yield return null;
  89. yield return null;
  90. yield return null;
  91. }
  92. }
  93. }