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 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)); }
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); }
public void ShouldPauseOnPauseIfCondition() { // PauseIf mem 0x0002 == 1 // Mem 0x0003 >= 5, Hit 100 FakeConsoleRam ram = new FakeConsoleRam(0xFF); ram.Data[0x0002] = 0; ram.Data[0x0003] = 6; ReadMemoryValue pauseMemoryValue = new ReadMemoryValue { Address = 0x0002, Kind = MemoryAddressKind.Int8 }; ReadMemoryValue otherMemoryValue = new ReadMemoryValue { Address = 0x0003, Kind = MemoryAddressKind.Int8 }; PauseIfConditionInstruction pauseIfCondition1 = new PauseIfConditionInstruction() { CompareInstruction = new CompareInstruction() { Left = pauseMemoryValue, Right = new ConstValue(1), Operation = ConditionCompare.Equals } }; ConditionInstruction condition2 = new ConditionInstruction() { CompareInstruction = new CompareInstruction() { Left = otherMemoryValue, Right = new ConstValue(5), Operation = ConditionCompare.GreaterEquals }, TargetHitCount = 10 }; AchievementInstruction achivement = new AchievementInstruction { Core = new ConditionGroupInstruction(new[] { pauseIfCondition1, condition2 }) }; achivement.Evaluate(ram); achivement.Evaluate(ram); Assert.Equal(2, condition2.CurrentHitCount); ram.Data[0x0002] = 1; achivement.Evaluate(ram); Assert.Equal(2, condition2.CurrentHitCount); achivement.Evaluate(ram); Assert.Equal(2, condition2.CurrentHitCount); }
public void ResetIfShouldResetHitCount() { FakeConsoleRam ram = new FakeConsoleRam(0xFF); ram.Data[4] = 0; ReadMemoryValue levelMemoryValue = new ReadMemoryValue { Address = 0x0004, Kind = MemoryAddressKind.Int8 }; ConstValue value = new ConstValue(8); ConditionInstruction condition1 = new ConditionInstruction { CompareInstruction = new CompareInstruction() { Left = levelMemoryValue, Right = value, Operation = ConditionCompare.Equals } }; ConditionInstruction condition2 = new ConditionInstruction { CompareInstruction = new CompareInstruction() { Left = levelMemoryValue, Right = new DeltaValue(levelMemoryValue), Operation = ConditionCompare.Greater, }, TargetHitCount = 8 }; ResetIfConditionInstruction resetIfCondition3 = new ResetIfConditionInstruction { CompareInstruction = new CompareInstruction() { Left = levelMemoryValue, Right = new DeltaValue(levelMemoryValue), Operation = ConditionCompare.Less } }; AchievementInstruction achievementInstruction = new AchievementInstruction { Core = new ConditionGroupInstruction(new[] { condition1, condition2, resetIfCondition3 } ) }; Assert.False(achievementInstruction.Evaluate(ram)); ram.Data[4] = 1; Assert.False(achievementInstruction.Evaluate(ram)); Assert.Equal(1, condition2.CurrentHitCount); ram.Data[4] = 2; achievementInstruction.Evaluate(ram); Assert.Equal(2, condition2.CurrentHitCount); ram.Data[4] = 3; achievementInstruction.Evaluate(ram); Assert.Equal(3, condition2.CurrentHitCount); ram.Data[4] = 1; achievementInstruction.Evaluate(ram); Assert.Equal(0, condition2.CurrentHitCount); }