//public static int NumOfPersistentEntries()
            //{
            //	return MemoryData().Count(d =>
            //		d.Arguments.Length > 2 && (bool) d.Arguments[2]
            //		);
            //}

            public static KB PopulatedTestMemory()
            {
                KB kb = new KB((Name)"Me");

                foreach (var t in MemoryData())
                {
                    Name           property = (Name)t.Arguments[0];
                    PrimitiveValue value    = PrimitiveValue.Cast(t.Arguments[1]);
                    try
                    {
                        //if(t.Arguments.Length>2)
                        //	kb.Tell((Name)t.Arguments[0], PrimitiveValue.Cast(t.Arguments[1]),(bool)t.Arguments[2]);
                        //else
                        kb.Tell(property, value);
                    }
                    catch (Exception e)
                    {
                        if (t.Arguments.Length > 2)
                        {
                            Assert.AreEqual(e.GetType(), t.Arguments[2]);
                        }
                        else
                        {
                            Assert.Fail($"An exception was thrown unexpectedly while evaluating {property} = {value}: {e}");
                        }
                    }
                }
                return(kb);
            }
        public void Test_PrimitiveValuesAsk(string str, object expect)
        {
            Name v     = (Name)str;
            KB   kb    = new KB((Name)"Me");
            var  value = kb.AskProperty(v);

            Assert.NotNull(value);

            var v1 = PrimitiveValue.Cast(value);
            var v2 = PrimitiveValue.Cast(expect);

            Assert.AreEqual(v1, v2);
        }
Exemple #3
0
        public static Name BuildName(object value)
        {
            if (value == null)
            {
                return(NIL_SYMBOL);
            }

            var str = value as string;

            if (str != null)
            {
                if (string.IsNullOrEmpty(str))
                {
                    throw new ArgumentException("Invalid symbol \"\"");
                }

                str = str.Trim();
                return(ParseName(str));
            }
            return(new PrimitiveSymbol(PrimitiveValue.Cast(value)));
        }
        public void Test_Simple_Tell_Invalid(Name name, object value, Type expectedException)
        {
            var kb = new KB((Name)"Me");

            Assert.Throws(expectedException, () => kb.Tell(name, PrimitiveValue.Cast(value)));
        }
        public void Test_Simple_Tell_Valid(Name name, object value)
        {
            var kb = new KB((Name)"Me");

            kb.Tell(name, PrimitiveValue.Cast(value));
        }