public void NestedComparisonTest() { var wrapperA = new FloatClassWrapper <Vector2> .FloatWrapperA <Tuple <string, string>, float>(2); FloatWrapperB wrapperB = new FloatWrapperB(2); Dictionary <string, object> objDictionary = new Dictionary <string, object>(); objDictionary.Add("floatWrapper_a", wrapperA); objDictionary.Add("floatWrapper_b", wrapperB); var schema = FloatComparisonNestedSchemata(); var condGate = new ConditionFactory(objDictionary).Build(schema); Assert.True(condGate.Met()); schema.conditionType = ConditionType.And; condGate = new ConditionFactory(objDictionary).Build(schema); Assert.False(condGate.Met()); wrapperB.f = 1; Assert.True(condGate.Met()); Stopwatch watch = new Stopwatch(); condGate.Met(); // clearing for cache and JiT watch.Start(); for (int i = 0; i < 1000000; i++) { condGate.Met(); } watch.Stop(); Console.WriteLine("Elapsed milliseconds for dynamically compiled method: " + watch.ElapsedMilliseconds); ICondition hardCodedConditionGate = new ConditionsGate(ConditionType.And, new ConditionAtom(() => wrapperA.f >= 2, false), new ConditionAtom(() => wrapperB.f < 2, false)); watch.Reset(); hardCodedConditionGate.Met(); // clearing cache and JiT watch.Start(); for (int i = 0; i < 1000000; i++) { hardCodedConditionGate.Met(); } watch.Stop(); Console.WriteLine("Elapsed milliseconds for hard-coded delegate: " + watch.ElapsedMilliseconds); dynamic dyn_wrapperA = wrapperA; dynamic dyn_wrapperB = wrapperB; ICondition dynamicConditionGate = new ConditionsGate(ConditionType.And, new ConditionAtom(() => dyn_wrapperA.f >= 2, false), new ConditionAtom(() => dyn_wrapperB.f < 2, false)); watch.Reset(); dynamicConditionGate.Met(); // clearing cache and JiT watch.Start(); for (int i = 0; i < 1000000; i++) { dynamicConditionGate.Met(); } watch.Stop(); Console.WriteLine("Elapsed milliseconds for dynamically-typed, hard-coded delegate: " + watch.ElapsedMilliseconds); }
public void TestVectorRangeBuilt() { string comparisonMethodName = "Contains"; Type rootType = typeof(VectorRange); Type argType = typeof(Vector2); VectorWrapper wrapper = new VectorWrapper(new Vector2(1, 1)); VectorRangeWrapperWrapper rangeWrapper = new VectorRangeWrapperWrapper(new VectorRangeWrapper(VectorRange.Any)); var condAtom2 = new ConditionAtom(() => rangeWrapper.wrapper.range.Contains(wrapper.vec), false); dynamic rangeWrapper_dyn = rangeWrapper; dynamic wrapper_dyn = wrapper; var condAtom3 = new ConditionAtom(() => rangeWrapper_dyn.wrapper.range.Contains(wrapper_dyn.vec), false); Console.WriteLine(typeof(Vector2).Name); var schema = GetWrapperConditionSchema(); Dictionary <string, object> objDictionary = new Dictionary <string, object>(); objDictionary.Add("wrapper", rangeWrapper); objDictionary.Add("vecWrapper", wrapper); var condAtom = new ConditionFactory(objDictionary).Build(schema); Assert.True(condAtom.Met()); condAtom2.Met(); condAtom3.Met(); Stopwatch watch = new Stopwatch(); watch.Start(); for (int i = 0; i < 1000000; i++) { condAtom.Met(); } watch.Stop(); Console.WriteLine("Elapsed milliseconds for dynamically compiled method: " + watch.ElapsedMilliseconds); watch.Reset(); watch.Start(); for (int i = 0; i < 1000000; i++) { condAtom2.Met(); } watch.Stop(); Console.WriteLine("Elapsed milliseconds for hard-coded delegate: " + watch.ElapsedMilliseconds); watch.Reset(); watch.Start(); for (int i = 0; i < 1000000; i++) { condAtom3.Met(); } watch.Stop(); Console.WriteLine("Elapsed milliseconds for dynamically-typed, hard-coded delegate: " + watch.ElapsedMilliseconds); }
public void TestDoubleDuplicateMethods() { var wrapperA = new FloatWrapperB(2); var wrapperB = new FloatWrapperB(2); var schema = FloatComparisonNestedSchemata(); schema.children[0].targetSchema.propertyTypeName = (typeof(FloatWrapperB).AssemblyQualifiedName); schema.children[0].comparisonType = ComparisonType.Equal; schema.children[1].comparisonType = ComparisonType.Equal; Dictionary <string, object> objDictionary = new Dictionary <string, object>(); objDictionary.Add("floatWrapper_a", wrapperA); objDictionary.Add("floatWrapper_b", wrapperB); ICondition cond = new ConditionFactory(objDictionary).Build(schema); Assert.True(cond.Met()); wrapperA.f = 1; Assert.True(cond.Met()); wrapperB.f = 3; Assert.False(cond.Met()); }