public void SearchWithHardConstraint() { string[] lines = { "CHAT CORE_Shake {type=shake, stage=CORE}", "SAY Core shake!", "CHAT CORE_Tap {type=tap, stage=CORE}", "SAY Core tap!", "CHAT CORE_Stale_Fast {type=critic, stage=CORE}", "SAY Core critic!", "CHAT NV_Shake {type=shake, stage=NV}", "SAY NV shake!", "CHAT NV_Tap {type=tap, stage=NV}", "SAY NV tap!", "CHAT NV_Stale_Fast {type=critic, stage=NV}", "SAY NV critic!", }; string contents = String.Join("\n", lines); ChatRuntime rt = new ChatRuntime(AppConfig.TAC); rt.ParseText(contents); var finder = new Find().Init("{!!type=tap,!stage=CORE}"); var chat = rt.DoFind((Dialogic.Find)finder); Assert.That(chat.text, Is.EqualTo("CORE_Tap")); }
public void FindWithRelaxation() { string[] lines = { "CHAT c0", "FIND {dev>1,!day=fri}", "CHAT c1 {dev=2,day=wed}", "CHAT c2 {dev=3,day=wed}", "CHAT c3 {}" }; string contents = String.Join("\n", lines); List <Chat> chats = ChatParser.ParseText(contents, NO_VALIDATORS); //chats.ForEach((ch) => Console.WriteLine(ch.ToTree())); Command finder = chats[0].commands[0]; finder.Resolve(null); Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Find))); ChatRuntime rt = new ChatRuntime(chats); var chat = rt.DoFind((Find)finder, null); Assert.That(chat, Is.Not.Null); Assert.That(chat.text, Is.EqualTo("c3")); lines = new[] { "CHAT c0 {dev=1}", "FIND {!dev>1,!day=fri}", "CHAT c1 {dev=0,day=wed}", "CHAT c2 {day=wed}", "CHAT c3 {}" }; contents = String.Join("\n", lines); chats = ChatParser.ParseText(contents, NO_VALIDATORS); //chats.ForEach((ch) => Console.WriteLine(ch.ToTree())); finder = chats[0].commands[0]; finder.Resolve(null); Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Find))); rt = new ChatRuntime(chats); chat = rt.DoFind((Find)finder, null); Assert.That(chat, Is.Not.Null); Assert.That(chat.text, Is.EqualTo("c3")); lines = new[] { "CHAT c0 {dev=1}", "FIND {!dev>1,!day=fri}", "CHAT c1 {dev=0,day=wed}", "CHAT c2 {day=wed}", }; chats = ChatParser.ParseText(String.Join("\n", lines), NO_VALIDATORS); finder = chats[0].commands[0]; finder.Resolve(null); rt = new ChatRuntime(chats); chat = rt.DoFind((Find)finder, null); Assert.That(chat, Is.Null); Chat c; chats = new List <Chat>(); chats.Add(c = Chat.Create("c1")); c.SetMeta("dev", "hello"); chats.Add(c = Chat.Create("c2")); c.SetMeta("dev", "2"); chats.Add(c = Chat.Create("c3")); rt = new ChatRuntime(chats); chat = rt.DoFind(null, new Constraint("dev", "1", ConstraintType.Hard)); Assert.That(chat.text, Is.EqualTo("c3")); // success }