public void AddChoice() { var state = new RumorState(); var wrong = false; var count = 0; state.OnSetDialog += (obj, str) => wrong = true; state.OnAddDialog += (obj, str) => wrong = true; state.OnAddChoice += (index, str) => count++; state.OnRemoveChoice += (index, str) => wrong = true; state.OnClear += (type) => wrong = true; // First use state.AddChoice("a", null); Assert.AreEqual(1, state.Choices.Count); Assert.True(state.Choices[0] == "a"); Assert.AreEqual(1, state.Consequences.Count); Assert.True(state.Consequences[0].Count == 0); // Second use state.AddChoice("b", null); Assert.AreEqual(2, state.Choices.Count); Assert.True(state.Choices[0] == "a"); Assert.True(state.Choices[1] == "b"); Assert.AreEqual(2, state.Consequences.Count); Assert.True(state.Consequences[0].Count == 0); Assert.True(state.Consequences[1].Count == 0); // Check callback Assert.AreEqual(2, count); Assert.IsFalse(wrong); }
public void RemoveChoice() { var state = new RumorState(); var wrong = false; var addCount = 0; var removeCount = 0; state.OnSetDialog += (obj, str) => wrong = true; state.OnAddDialog += (obj, str) => wrong = true; state.OnAddChoice += (index, str) => addCount++; state.OnRemoveChoice += (index, str) => removeCount++; state.OnClear += (type) => wrong = true; // Add choices state.AddChoice("a", null); state.AddChoice("b", null); state.AddChoice("c", null); Assert.AreEqual(3, state.Choices.Count); Assert.True(state.Choices[0] == "a"); Assert.True(state.Choices[1] == "b"); Assert.True(state.Choices[2] == "c"); Assert.AreEqual(3, state.Consequences.Count); Assert.True(state.Consequences[0].Count == 0); Assert.True(state.Consequences[1].Count == 0); Assert.True(state.Consequences[2].Count == 0); state.RemoveChoice(1); Assert.AreEqual(2, state.Choices.Count); Assert.True(state.Choices[0] == "a"); Assert.True(state.Choices[1] == "c"); Assert.AreEqual(2, state.Consequences.Count); Assert.True(state.Consequences[0].Count == 0); Assert.True(state.Consequences[1].Count == 0); state.RemoveChoice(0); Assert.AreEqual(1, state.Choices.Count); Assert.True(state.Choices[0] == "c"); Assert.AreEqual(1, state.Consequences.Count); Assert.True(state.Consequences[0].Count == 0); state.RemoveChoice(0); Assert.AreEqual(0, state.Choices.Count); Assert.AreEqual(0, state.Consequences.Count); // Check callback Assert.AreEqual(3, addCount); Assert.AreEqual(3, removeCount); Assert.IsFalse(wrong); }
public void SerializeRumorStateChoice() { var rumor = new Rumor.Engine.Rumor("return"); var a = new RumorState(); a.AddChoice("choice", new List <Node>() { new Say("say"), }); var b = Reserialize(a); Assert.AreEqual(1, a.Choices.Count); Assert.AreEqual(a.Choices.Count, b.Choices.Count); Assert.AreEqual(a.Choices[0], b.Choices[0]); Assert.AreEqual(1, a.Consequences.Count); Assert.AreEqual(a.Consequences.Count, b.Consequences.Count); Assert.AreEqual(1, a.Consequences[0].Count); Assert.AreEqual(a.Consequences[0].Count, b.Consequences[0].Count); Assert.AreEqual( (a.Consequences[0][0] as Say).EvaluateText(rumor), (b.Consequences[0][0] as Say).EvaluateText(rumor)); }
public void ClearChoices() { var state = new RumorState(); var wrong = false; var count = 0; ClearType?type = null; state.OnRemoveChoice += (index, str) => wrong = true; state.OnClear += (t) => type = t; // Test Clear All state.AddChoice("a", null); state.AddChoice("b", null); state.Clear(); Assert.AreEqual(0, state.Choices.Count); Assert.AreEqual(0, state.Consequences.Count); Assert.AreEqual(ClearType.ALL, type); // Test Clear Dialog state.AddChoice("a", null); state.AddChoice("b", null); state.ClearDialog(); Assert.AreEqual(2, state.Choices.Count); Assert.True(state.Choices[0] == "a"); Assert.True(state.Choices[1] == "b"); Assert.AreEqual(2, state.Consequences.Count); Assert.True(state.Consequences[0].Count == 0); Assert.True(state.Consequences[1].Count == 0); Assert.AreEqual(ClearType.DIALOG, type); // Test Clear Choices state.AddChoice("a", null); state.AddChoice("b", null); state.ClearChoices(); Assert.AreEqual(0, state.Choices.Count); Assert.AreEqual(0, state.Consequences.Count); Assert.AreEqual(ClearType.CHOICES, type); // Check callback Assert.AreEqual(0, count); Assert.IsFalse(wrong); }