示例#1
0
 public void ThingBase9()
 {
     Facts.AddThing(new Thing("thing1"));
     Facts.AddThing(new Thing("thing2"));
     Facts.ClearThings();
     Assert.AreEqual(0, Facts.ThingCount());
 }
示例#2
0
 public void ThingBase3()
 {
     Facts.ClearThings();
     Facts.AddThing("thing1");
     Facts.AddThing("thing1");
     Assert.AreEqual(1, Facts.ThingCount());
 }
示例#3
0
        public void ThingBase10()
        {
            Facts.ClearThings();
            Thing t = null;

            Facts.AddThing(t);
            Assert.AreEqual(0, Facts.ThingCount());
        }
示例#4
0
        /// <summary>
        /// Asserts a given fact (of the proper Tvar type)
        /// </summary>
        private static void AssertFact(Factoid f)
        {
            // Instantiate relevant Things
            Thing t1 = f.Arg1.ToString() != "" ? Facts.AddThing(f.Arg1.ToString()) : null;
            Thing t2 = f.Arg2.ToString() != "" ? Facts.AddThing(f.Arg2.ToString()) : null;
            Thing t3 = f.Arg3.ToString() != "" ? Facts.AddThing(f.Arg3.ToString()) : null;

            // Sometimes I have my doubts about static typing...
            if (f.FactType == "Tbool")
            {
                Tbool val = new Tbool();
                foreach (TemporalValue v in f.Timeline)
                {
                    val.AddState(v.Date, new Hval(v.Value));
                }
                Facts.Assert(t1, f.Relationship, t2, t3, val);
            }
            else if (f.FactType == "Tnum")
            {
                Tnum val = new Tnum();
                foreach (TemporalValue v in f.Timeline)
                {
                    val.AddState(v.Date, new Hval(v.Value));
                }
                Facts.Assert(t1, f.Relationship, t2, t3, val);
            }
            else if (f.FactType == "Tstr")
            {
                Tstr val = new Tstr();
                foreach (TemporalValue v in f.Timeline)
                {
                    val.AddState(v.Date, new Hval(v.Value));
                }
                Facts.Assert(t1, f.Relationship, t2, t3, val);
            }
            else if (f.FactType == "Tdate")
            {
                Tdate val = new Tdate();
                foreach (TemporalValue v in f.Timeline)
                {
                    val.AddState(v.Date, new Hval(v.Value));
                }
                Facts.Assert(t1, f.Relationship, t2, t3, val);
            }
            else if (f.FactType == "Tset")
            {
                Tset val = new Tset();
                foreach (TemporalValue v in f.Timeline)
                {
                    val.AddState(v.Date, new Hval(v.Value));
                }
                Facts.Assert(t1, f.Relationship, t2, t3, val);
            }
        }
示例#5
0
        /// <summary>
        /// Asserts a fact.
        /// </summary>
        public static void AssertAnswer(Engine.Response response, string val)
        {
            // Get the data pertaining to the current question
            Thing  subj  = (Thing)response.NextFact.Arg1;
            Thing  obj   = (Thing)response.NextFact.Arg2;
            string rel   = response.NextFact.Relationship;
            string qType = Templates.GetQ(rel).questionType;

            // Create the fact/relationship text for the .akk unit test
            if (qType != "Tset")
            {
                AkkTest.testStr += AkkTest.assertedRelationship;
            }

            // Assert the fact (converted to the proper type of Tvar)
            if (qType == "Tbool")
            {
                // Asserts the fact (handling uncertainty)
                // Also, creates part of the .akk unit test string
                if (val == "?")
                {
                    Facts.Assert(subj, rel, obj, new Tbool(Hstate.Uncertain));
                    AkkTest.testStr += "Tbool(?)\r\n";
                }
                else
                {
                    Facts.Assert(subj, rel, obj, TboolFromTemporalString(val));
                    AkkTest.testStr += val + "\r\n";
                }
            }
            else if (qType == "Tstr")
            {
                if (val == "?")
                {
                    Facts.Assert(subj, rel, obj, new Tstr(Hstate.Uncertain));
                    AkkTest.testStr += "Tstr(?)\r\n";
                }
                else
                {
                    Facts.Assert(subj, rel, obj, TstrFromTemporalString(val));
                    AkkTest.testStr += "\"" + val + "\"\r\n";
                }
            }
            else if (qType == "Tnum")
            {
                if (val == "?")
                {
                    Facts.Assert(subj, rel, obj, new Tnum(Hstate.Uncertain));
                    AkkTest.testStr += "Tnum(?)\r\n";
                }
                else
                {
                    Facts.Assert(subj, rel, obj, TnumFromTemporalString(val));
                    AkkTest.testStr += val + "\r\n";
                }
            }
            else if (qType == "Tdate")
            {
                if (val == "?")
                {
                    Facts.Assert(subj, rel, obj, new Tdate(Hstate.Uncertain));
                    AkkTest.testStr += "Tdate(?)\r\n";
                }
                else
                {
                    Facts.Assert(subj, rel, obj, TdateFromTemporalString(val));
                    AkkTest.testStr += val + "\r\n";
                }
            }
            else if (qType == "Tset")
            {
                if (val == "?")
                {
                    Facts.Assert(subj, rel, obj, new Tset(Hstate.Uncertain));
                    AkkTest.testStr += "Tset(?)\r\n";
                }
                else
                {
                    // Assert an empty set
                    if (val == "[]")
                    {
                        Tset result = new Tset();
                        result.SetEternally();
                        Facts.Assert(subj, rel, obj, result);
                    }
                    else
                    {
                        // Create a list of Things
                        string[]     items     = val.Split(new char[] { ';' });
                        List <Thing> list      = new List <Thing>();
                        string       thingList = ""; // for .akk unit tests
                        foreach (string i in items)
                        {
                            string name = i.Trim();
                            list.Add(Facts.AddThing(name));
                            thingList += name + ",";
                        }

                        // Assert the Tset
                        Facts.Assert(subj, rel, obj, new Tset(list));

                        // Build the .akk unit test string
                        AkkTest.testStr += "- Things " + thingList.TrimEnd(',') + "\r\n";
                        AkkTest.testStr += AkkTest.assertedRelationship;
                        AkkTest.testStr += "[[" + val.Replace(";", ",") + "]]\r\n";
                    }
                }
            }
        }