Esempio n. 1
0
        public void TestEqualList()
        {
            var v1 = new LogicVar();
            var v2 = new LogicVar();

            var goal  = MicroKanren.Equal(new [] { 5, 6 }, new[] { v1, v2 });
            var subst = goal(MicroKanren.GetEmptySubst()).SingleOrDefault();

            Assert.NotNull(subst);
            Assert.AreEqual(5, subst.GetValue(v1));
            Assert.AreEqual(6, subst.GetValue(v2));

            goal  = MicroKanren.Equal(new object[] { 5, 5, v1 }, new[] { v1, v1, v2 });
            subst = goal(MicroKanren.GetEmptySubst()).SingleOrDefault();

            Assert.NotNull(subst);
            Assert.AreEqual(5, subst.GetValue(v1));
            Assert.AreEqual(5, subst.GetValue(v2));

            goal = MicroKanren.Equal(new[] { 5, 6, 7 }, new[] { v1, v2 });
            Assert.IsNull(goal(MicroKanren.GetEmptySubst()));

            var v3 = new LogicVar();

            goal = MicroKanren.Equal(new[] { 5, 6 }, new[] { v1, v2, v3 });
            Assert.IsNull(goal(MicroKanren.GetEmptySubst()));
        }
Esempio n. 2
0
        public void TestConjunctionDifferent()
        {
            var v1 = new LogicVar();
            var v2 = new LogicVar();

            var goal1 = MicroKanren.Equal(v1, 5);
            var goal2 = MicroKanren.Equal(v2, "6");
            var goal3 = MicroKanren.Equal(v2, v1);

            var conjGoal = MicroKanren.Conjunction(goal3, MicroKanren.Conjunction(goal1, goal2));

            var subst = conjGoal(MicroKanren.GetEmptySubst());

            Assert.IsNull(subst);
        }
Esempio n. 3
0
        public void TestEqualSame()
        {
            var v1 = new LogicVar();
            var v2 = new LogicVar();

            var goal1 = MicroKanren.Equal(v1, 5);
            var goal2 = MicroKanren.Equal(v2, 5);
            var goal3 = MicroKanren.Equal(v2, v1);

            var subst1 = goal1(MicroKanren.GetEmptySubst()).Single();
            var subst2 = goal2(subst1).Single();
            var subst3 = goal3(subst2).SingleOrDefault();

            Assert.NotNull(subst3);
            Assert.AreEqual(5, subst3.GetValue(v1));
            Assert.AreEqual(5, subst3.GetValue(v2));
        }
Esempio n. 4
0
        public void TestEqualDifferent()
        {
            var v1 = new LogicVar();
            var v2 = new LogicVar();

            var goal1 = MicroKanren.Equal(v1, 5);
            var goal2 = MicroKanren.Equal(v2, "5");

            var subst1 = goal1(MicroKanren.GetEmptySubst()).SingleOrDefault();

            Assert.IsNull(MicroKanren.Equal(6, v1)(subst1));

            var subst2 = goal2(subst1).SingleOrDefault();

            Assert.NotNull(subst2);
            Assert.AreEqual(5, subst2.GetValue(v1));
            Assert.AreEqual("5", subst2.GetValue(v2));

            Assert.IsNull(MicroKanren.Equal(v2, v1)(subst2));
        }
Esempio n. 5
0
        public void TestRecursiveConjunction()
        {
            var v1 = new LogicVar();
            var v2 = new LogicVar();
            var v3 = new LogicVar();

            var goal1 = MicroKanren.Equal(v1, 5);
            var goal2 = MicroKanren.Equal(v2, v1);
            var goal3 = MicroKanren.Equal(v3, v2);

            var conjGoal = MicroKanren.Conjunction(goal3, MicroKanren.Conjunction(goal1, goal2));

            var subst = conjGoal(MicroKanren.GetEmptySubst()).SingleOrDefault();

            Assert.NotNull(subst);

            Assert.AreEqual(5, subst.GetValue(v1));
            Assert.AreEqual(5, subst.GetValue(v2));
            Assert.AreEqual(5, subst.GetValue(v3));
        }
Esempio n. 6
0
        public void TestDisjunction()
        {
            var v1 = new LogicVar();
            var v2 = new LogicVar();

            var goal0 = MicroKanren.Equal(v1, v2);
            var goal1 = MicroKanren.Equal(v1, 5);
            var goal2 = MicroKanren.Equal(v2, 6);

            var conjGoal = MicroKanren.Conjunction(goal0, MicroKanren.Disjunction(goal1, goal2));

            var subst = conjGoal(MicroKanren.GetEmptySubst());

            Assert.NotNull(subst);

            var substList = subst.ToList();

            Assert.AreEqual(5, substList[0].GetValue(v1));
            Assert.AreEqual(5, substList[0].GetValue(v2));
            Assert.AreEqual(6, substList[1].GetValue(v1));
            Assert.AreEqual(6, substList[1].GetValue(v2));
        }