예제 #1
0
        public void ShouldEvalEqualsMemoryWithConstValue()
        {
            EvaluatorContext context = new EvaluatorContext();

            FakeConsoleRam ram = new FakeConsoleRam(0xFF);

            ram.Data[4] = 42;

            // 0xH0004 == 42
            ReadMemoryValue readMemory = new ReadMemoryValue
            {
                Address = 0x0004,
                Kind    = MemoryAddressKind.Int8
            };

            ConstValue constValue = new ConstValue(42);

            CompareInstruction compareInst = new CompareInstruction
            {
                Left      = readMemory,
                Right     = constValue,
                Operation = ConditionCompare.Equals
            };

            var result = compareInst.Evaluate(ram, context);

            Assert.True(result);
        }
예제 #2
0
        public void ShouldEvaluateDeltaValue()
        {
            EvaluatorContext context = new EvaluatorContext();

            FakeConsoleRam ram = new FakeConsoleRam(0xFF);

            ram.Data[4] = 4;

            // 0xH0004 < d0xH004
            ReadMemoryValue readMemory = new ReadMemoryValue
            {
                Address = 0x0004,
                Kind    = MemoryAddressKind.Int8
            };

            DeltaValue deltaValue = new DeltaValue(readMemory);

            CompareInstruction compareInst = new CompareInstruction
            {
                Left      = readMemory,
                Right     = deltaValue,
                Operation = ConditionCompare.Less
            };

            Assert.False(compareInst.Evaluate(ram, context));

            ram.Data[4] = 2;

            Assert.True(compareInst.Evaluate(ram, context));
            Assert.False(compareInst.Evaluate(ram, context));
        }
        public override decimal?Invoke(EvaluatorContext context)
        {
            var leftValue  = Left.Invoke(context);
            var rightValue = Right.Invoke(context);

            return(leftValue + rightValue);
        }
예제 #4
0
        public void ShouldOnlyReturnTrueWhenHitCountIsReached()
        {
            EvaluatorContext context = new EvaluatorContext();

            FakeConsoleRam ram = new FakeConsoleRam(0xFF);

            ram.Data[4] = 42;

            // 0xH0004 == 42
            ReadMemoryValue readMemory = new ReadMemoryValue
            {
                Address = 0x0004,
                Kind    = MemoryAddressKind.Int8
            };

            ConstValue constValue = new ConstValue(42);

            CompareInstruction compareInst = new CompareInstruction
            {
                Left      = readMemory,
                Right     = constValue,
                Operation = ConditionCompare.Equals
            };

            ConditionInstruction condition = new ConditionInstruction
            {
                TargetHitCount     = 2,
                CompareInstruction = compareInst
            };

            Assert.False(condition.Evaluate(ram, context));
            Assert.True(condition.Evaluate(ram, context));
        }
예제 #5
0
 public RunningTaskImpl(EvaluatorManager evaluatorManager, string taskId, EvaluatorContext evaluatorContext)
 {
     LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "INIT: TaskRuntime id [{0}] on evaluator id [{1}]", taskId, evaluatorManager.Id));
     _id = taskId;
     _evaluatorManager = evaluatorManager;
     _evaluatorContext = evaluatorContext;
 }
예제 #6
0
        public static void TestJValueCommonInvalidScenarios(
            JObject dataJObj,
            string dataJPath,
            JObject resourceJObj,
            string resourceJPath)
        {
            var context = new EvaluatorContext(dataJObj, dataJPath, resourceJObj, resourceJPath, Direction.ContextToResource);

            Assert.False(new DummyValusEvaluator().Evaluate(context));
        }
예제 #7
0
        public void GreaterThanEvaluatorPositiveBehavior(
            JObject dataJObj,
            string dataJPath,
            JObject resourceJObj,
            string resourceJPath)
        {
            var evaluator = new GreaterThanEvaluator();
            var context   = new EvaluatorContext(dataJObj, dataJPath, resourceJObj, resourceJPath, Direction.ContextToResource);

            Assert.True(evaluator.Evaluate(context));
        }
예제 #8
0
        public void ContainsEvaluatorNegativeBehavior(
            JObject dataJObj,
            string dataJPath,
            JObject resourceJObj,
            string resourceJPath)
        {
            var evaluator = new ContainsEvaluator();
            var context   = new EvaluatorContext(dataJObj, dataJPath, resourceJObj, resourceJPath, Direction.ContextToResource);

            Assert.False(evaluator.Evaluate(context));
        }
예제 #9
0
 public object Evaluate(EvaluatorContext evaluationContext)
 {
     try
     {
         this.contexts.SetValue(evaluatorCore, new[] {evaluationContext});
         return Accept(filterCriteria);
     }
     finally
     {
         this.contexts.SetValue(evaluatorCore, null);
     }
 }
예제 #10
0
        public override decimal?Invoke(EvaluatorContext context)
        {
            var leftValue  = Left.Invoke(context);
            var rightValue = Right.Invoke(context);

            if (leftValue == null || rightValue == null)
            {
                return(null);
            }

            return((decimal)Math.Pow((double)leftValue.Value, (double)rightValue.Value));
        }
        public override decimal?Invoke(EvaluatorContext context)
        {
            var values = new List <decimal?>();

            foreach (var p in Parameters)
            {
                values.Add(p.Invoke(context));
            }

            var func = context.GetFunction(Name);

            return(func?.Invoke(values.ToArray()));
        }
예제 #12
0
        public override decimal?Invoke(EvaluatorContext context)
        {
            var leftValue  = Left.Invoke(context);
            var rightValue = Right.Invoke(context);

            // Don't throw a divide by zero exception, return 0
            // Buuuutttt, if the left value is null then let's return null rather.
            if (rightValue == 0)
            {
                return(leftValue == null ? (decimal?)null : 0M);
            }

            return(leftValue / rightValue);
        }
예제 #13
0
        public void InitializesLeftAndRightOperandsCorrectly()
        {
            var context = new EvaluatorContext(dataObj, dataJPath, resourceObj, resourceJPath, Direction.ContextToResource);

            Assert.Same(context.LeftJObject, dataObj);
            Assert.Same(context.LeftJPath, dataJPath);
            Assert.Same(context.RightJObject, resourceObj);
            Assert.Same(context.RightJPath, resourceJPath);

            context = new EvaluatorContext(dataObj, dataJPath, resourceObj, resourceJPath, Direction.ResourceToContext);
            Assert.Same(context.LeftJObject, resourceObj);
            Assert.Same(context.LeftJPath, resourceJPath);
            Assert.Same(context.RightJObject, dataObj);
            Assert.Same(context.RightJPath, dataJPath);
        }
        public override decimal?Invoke(EvaluatorContext context)
        {
            var value = Expression.Invoke(context);

            return(value * -1);
        }
예제 #15
0
 private bool Fit(EvaluatorContext evaluationContext)
 {
     return (bool) Evaluate(evaluationContext);
 }
예제 #16
0
 public abstract override decimal?Invoke(EvaluatorContext context);
예제 #17
0
 public ProblemRepository(EvaluatorContext context) : base(context)
 {
 }
예제 #18
0
 public ProgresStatusRepository(EvaluatorContext db) : base(db)
 {
 }
 public UserInformationRepository(EvaluatorContext repoContext) : base(repoContext)
 {
 }
예제 #20
0
 public override decimal?Invoke(EvaluatorContext context)
 {
     return(context.GetParameter(Name));
 }
예제 #21
0
 public RepositoryBase(EvaluatorContext repoContext)
 {
     RepositoryContext = repoContext;
 }
예제 #22
0
 public SubmisionContestRepository(EvaluatorContext db) : base(db)
 {
 }
예제 #23
0
 public abstract decimal?Invoke(EvaluatorContext context);
예제 #24
0
 public ContestRepository(EvaluatorContext db) : base(db)
 {
 }
예제 #25
0
 public AnnouncementRepository(EvaluatorContext db) : base(db)
 {
 }
예제 #26
0
 public SolutionRepository(EvaluatorContext db) : base(db)
 {
 }
예제 #27
0
 public TestsRepository(EvaluatorContext db) : base(db)
 {
 }
 public override decimal?Invoke(EvaluatorContext context)
 {
     return(Value);
 }