Example #1
0
        public void TestLogicAny()
        {
            var x     = new Var('x');
            var goal1 = new EqGoal(x, 2);

            var lst = new List <Goal>();

            lst.Add(goal1);
            var    dict   = new Dictionary <object, object>();
            object result = LogicSharp.logic_Any(lst, dict);

            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(IEnumerable <KeyValuePair <object, object> >), result);
            Assert.IsInstanceOf(typeof(Dictionary <object, object>), result);
            var resultDict = result as Dictionary <object, object>;

            Assert.IsTrue(resultDict.Count == 1);
            Assert.True(dict.ContainsKey(x));

            //assert len(tuple(lany(eq(x, 2), eq(x, 3))({}))) == 2
            //assert len(tuple(lany((eq, x, 2), (eq, x, 3))({}))) == 2

            var goal2 = new EqGoal(x, 3);

            lst = new List <Goal>();
            lst.Add(goal1);
            lst.Add(goal2);
            dict   = new Dictionary <object, object>();
            result = LogicSharp.logic_Any(lst, dict);
            Assert.IsInstanceOf(typeof(IEnumerable <KeyValuePair <object, object> >), result);
            Assert.IsInstanceOf(typeof(HashSet <KeyValuePair <object, object> >), result);
            var myHashSet = result as HashSet <KeyValuePair <object, object> >;

            Assert.NotNull(myHashSet);
            Assert.True(myHashSet.Count == 2);

            //assert len(tuple(lany(eq(x, 2), eq(x, 3))({x:2}))) == 1
            lst = new List <Goal>();
            lst.Add(goal1);
            lst.Add(goal2);
            dict = new Dictionary <object, object>();
            dict.Add(x, 2);
            result = LogicSharp.logic_Any(lst, dict);
            Assert.IsNull(result);
        }