public static void RunSimpleDemo() { Source source = new Source(); Destination dest = new Destination(); Arrow <int, int> arr = new IDArrow <int>(); BindingsManager.CreateBinding(source.GetBindPoint("source"), arr, dest.GetBindPoint("result")); bool passed = true; Random rand = new Random(); for (int i = 0; i < 100; i++) { int next = rand.Next(); source.source = next; if (dest.result != source.source) { passed = false; } } if (passed) { Console.WriteLine("Works!"); } else { Console.WriteLine("Doesn't work D:"); } //BindingsManager.CreateBinding(source.GetBindPoint("source"), Op.Arr((int x) => x - 1), dest.GetBindPoint("result")); }
public static bool TestLaw2() { /* * Similar to law 1 but checking that Op.Arr(f).Combine(new IDArrow<T>()) = Op.Arr(f) */ Arrow <int, int> arrF = Op.Arr((int x) => (x * x) - 5); Arrow <int, int> id = new IDArrow <int>(); Arrow <int, int> combined = arrF.Combine(id); return(ArrowTestUtils.AssertArrowsGiveSameOutput(arrF, combined)); }
public static bool TestLaw2() { /* * Similar to law 1 but checking that Op.Arr(f).Combine(new IDArrow<T>()) = Op.Arr(f) */ Arrow<int, int> arrF = Op.Arr((int x) => (x * x) - 5); Arrow<int, int> id = new IDArrow<int>(); Arrow<int, int> combined = arrF.Combine(id); return ArrowTestUtils.AssertArrowsGiveSameOutput(arrF, combined); }
public static bool TestLaw1() { /* * Tests that IDArrow<T>.Combine(Op.Arr(f)) = Op.Arr(f) * That is, that the identity arrow combined with another arrow is exactly the same as * the other arrow on its own */ Arrow <int, int> arrF = Op.Arr((int x) => (x * x) - 5); Arrow <int, int> id = new IDArrow <int>(); Arrow <int, int> combined = id.Combine(arrF); return(ArrowTestUtils.AssertArrowsGiveSameOutput(arrF, combined)); }
public static bool TestLaw1() { /* * Tests that IDArrow<T>.Combine(Op.Arr(f)) = Op.Arr(f) * That is, that the identity arrow combined with another arrow is exactly the same as * the other arrow on its own */ Arrow<int, int> arrF = Op.Arr((int x) => (x*x) - 5); Arrow<int, int> id = new IDArrow<int>(); Arrow<int, int> combined = id.Combine(arrF); return ArrowTestUtils.AssertArrowsGiveSameOutput(arrF, combined); }
public static bool TestPipingCommutativity() { /* * If an identity is merged with a second function to form an arrow, attaching it to a * piped function must be commutative. In code: * arr (id *** g) >>> first f = first f >>> arr (id *** g) * This is tested by constructing the two arrows and checking their outputs match. */ Arrow <int, int> f = Op.Arr(ArrowTestUtils.GenerateFunc()); Arrow <int, int> g = Op.Arr(ArrowTestUtils.GenerateFunc()); Arrow <Tuple <int, int>, Tuple <int, int> > mergeFirst = new IDArrow <int>().And(g).Combine(f.First(default(int))); Arrow <Tuple <int, int>, Tuple <int, int> > firstMerge = f.First(default(int)).Combine(new IDArrow <int>().And(g)); return(ArrowTestUtils.AssertPairArrowsGiveSameOutput(mergeFirst, firstMerge)); }
private static Arrow<int, int> GetIdentityArrowChain(int length) { if (length == 0) return null; else { Arrow<int, int> result = new IDArrow<int>(); length--; while (length > 0) { result = result.Combine(new IDArrow<int>()); length--; } return result; } }
public void Run() { Arrow <int, int> id = new IDArrow <int>(); A a = new A(); B b = new B(); C c = new C(); BindingHandle aToB = BindingsManager.CreateBinding( a.GetBindPoint("Value"), id, b.GetBindPoint("Value")); BindingHandle bToA = BindingsManager.CreateBinding( b.GetBindPoint("Value"), id, a.GetBindPoint("Value")); BindingHandle bToC = BindingsManager.CreateBinding( b.GetBindPoint("Value"), id, c.GetBindPoint("Value") ); BindingHandle cToB = BindingsManager.CreateBinding( c.GetBindPoint("Value"), id, b.GetBindPoint("Value") ); try { BindingHandle cToA = BindingsManager.CreateBinding( c.GetBindPoint("Value"), id, a.GetBindPoint("Value") ); } catch (BindingConflictException) { Console.WriteLine("Cycle exception was thrown successfully!"); } }
public void Run() { Arrow<int, int> id = new IDArrow<int>(); A a = new A(); B b = new B(); C c = new C(); BindingHandle aToB = BindingsManager.CreateBinding( a.GetBindPoint("Value"), id, b.GetBindPoint("Value")); BindingHandle bToA = BindingsManager.CreateBinding( b.GetBindPoint("Value"), id, a.GetBindPoint("Value")); BindingHandle bToC = BindingsManager.CreateBinding( b.GetBindPoint("Value"), id, c.GetBindPoint("Value") ); BindingHandle cToB = BindingsManager.CreateBinding( c.GetBindPoint("Value"), id, b.GetBindPoint("Value") ); try { BindingHandle cToA = BindingsManager.CreateBinding( c.GetBindPoint("Value"), id, a.GetBindPoint("Value") ); } catch (BindingConflictException) { Console.WriteLine("Cycle exception was thrown successfully!"); } }
private static Arrow <int, int> GetIdentityArrowChain(int length) { if (length == 0) { return(null); } else { Arrow <int, int> result = new IDArrow <int>(); length--; while (length > 0) { result = result.Combine(new IDArrow <int>()); length--; } return(result); } }
public static void RunSimpleDemo() { Source source = new Source(); Destination dest = new Destination(); Arrow<int, int> arr = new IDArrow<int>(); BindingsManager.CreateBinding(source.GetBindPoint("source"), arr, dest.GetBindPoint("result")); bool passed = true; Random rand = new Random(); for (int i = 0; i < 100; i++) { int next = rand.Next(); source.source = next; if (dest.result != source.source) passed = false; } if (passed) Console.WriteLine("Works!"); else Console.WriteLine("Doesn't work D:"); //BindingsManager.CreateBinding(source.GetBindPoint("source"), Op.Arr((int x) => x - 1), dest.GetBindPoint("result")); }
public static bool TestPipingCommutativity() { /* * If an identity is merged with a second function to form an arrow, attaching it to a * piped function must be commutative. In code: * arr (id *** g) >>> first f = first f >>> arr (id *** g) * This is tested by constructing the two arrows and checking their outputs match. */ Arrow<int, int> f = Op.Arr(ArrowTestUtils.GenerateFunc()); Arrow<int, int> g = Op.Arr(ArrowTestUtils.GenerateFunc()); Arrow<Tuple<int, int>, Tuple<int, int>> mergeFirst = new IDArrow<int>().And(g).Combine(f.First(default(int))); Arrow<Tuple<int, int>, Tuple<int, int>> firstMerge = f.First(default(int)).Combine(new IDArrow<int>().And(g)); return ArrowTestUtils.AssertPairArrowsGiveSameOutput(mergeFirst, firstMerge); }