public void TestWalk() { /* * s = {1: 2, 2: 3} * assert walk(2, s) == 3 * assert walk(1, s) == 3 * assert walk(4, s) == 4 * Utils.transitive_get() */ var dict = new Dictionary <object, object>(); dict.Add(1, 2); dict.Add(2, 3); object obj = LogicSharp.transitive_get(2, dict); Assert.True(3.Equals(obj)); obj = LogicSharp.transitive_get(1, dict); Assert.True(3.Equals(obj)); obj = LogicSharp.transitive_get(4, dict); Assert.True(4.Equals(obj)); }
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)); }