Example #1
0
        public void TestDeepWalk()
        {
            var dict = new Dictionary <object, object>();
            var z    = new Var('z');
            var y    = new Var('y');
            var x    = new Var('x');

            dict.Add(z, 6);
            dict.Add(y, 5);
            var tuple = new Tuple <object, object>(y, z);

            dict.Add(x, tuple);

            object obj = LogicSharp.transitive_get(x, dict);

            Assert.True(obj.Equals(tuple));

            obj = LogicSharp.deep_transitive_get(x, dict);
            Assert.IsInstanceOf(typeof(Tuple <object, object>), obj);
            var result = obj as Tuple <object, object>;

            Assert.IsNotNull(result);
            Assert.True(5.Equals(result.Item1));
            Assert.True(6.Equals(result.Item2));
            //    Transitive get that propagates within tuples
            //    >>> d = {1: (2, 3), 2: 12, 3: 13}
            //    >>> transitive_get(1, d)
            //    (2, 3)
            //    >>> deep_transitive_get(1, d)
            //    (12, 13)

            dict  = new Dictionary <object, object>();
            tuple = new Tuple <object, object>(2, 3);
            dict.Add(1, tuple);
            dict.Add(2, 12);
            dict.Add(3, 13);
            obj = LogicSharp.deep_transitive_get(1, dict);
            Assert.IsInstanceOf(typeof(Tuple <object, object>), obj);
            result = obj as Tuple <object, object>;
            Assert.IsNotNull(result);
            Assert.True(12.Equals(result.Item1));
            Assert.True(13.Equals(result.Item2));
        }