Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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;
 }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 9
0
 public object Evaluate(EvaluatorContext evaluationContext)
 {
     try
     {
         this.contexts.SetValue(evaluatorCore, new[] {evaluationContext});
         return Accept(filterCriteria);
     }
     finally
     {
         this.contexts.SetValue(evaluatorCore, null);
     }
 }
Exemplo n.º 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()));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 15
0
 private bool Fit(EvaluatorContext evaluationContext)
 {
     return (bool) Evaluate(evaluationContext);
 }
Exemplo n.º 16
0
 public abstract override decimal?Invoke(EvaluatorContext context);
Exemplo n.º 17
0
 public ProblemRepository(EvaluatorContext context) : base(context)
 {
 }
Exemplo n.º 18
0
 public ProgresStatusRepository(EvaluatorContext db) : base(db)
 {
 }
 public UserInformationRepository(EvaluatorContext repoContext) : base(repoContext)
 {
 }
Exemplo n.º 20
0
 public override decimal?Invoke(EvaluatorContext context)
 {
     return(context.GetParameter(Name));
 }
Exemplo n.º 21
0
 public RepositoryBase(EvaluatorContext repoContext)
 {
     RepositoryContext = repoContext;
 }
Exemplo n.º 22
0
 public SubmisionContestRepository(EvaluatorContext db) : base(db)
 {
 }
Exemplo n.º 23
0
 public abstract decimal?Invoke(EvaluatorContext context);
Exemplo n.º 24
0
 public ContestRepository(EvaluatorContext db) : base(db)
 {
 }
Exemplo n.º 25
0
 public AnnouncementRepository(EvaluatorContext db) : base(db)
 {
 }
Exemplo n.º 26
0
 public SolutionRepository(EvaluatorContext db) : base(db)
 {
 }
Exemplo n.º 27
0
 public TestsRepository(EvaluatorContext db) : base(db)
 {
 }
 public override decimal?Invoke(EvaluatorContext context)
 {
     return(Value);
 }