Skip to content

Commit

Permalink
Merge pull request #580 from mbbsemu/neg-unit-tests
Browse files Browse the repository at this point in the history
Unit Tests for CPU `NEG` Opcode
  • Loading branch information
paladine authored Jul 18, 2023
2 parents 83268d3 + b663c54 commit 8630512
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions MBBSEmu.Tests/CPU/NEG_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Iced.Intel;
using Xunit;
using static Iced.Intel.AssemblerRegisters;

namespace MBBSEmu.Tests.CPU
{
public class NEG_Tests : CpuTestBase
{
//Unit Tests using xUnit to perform testing of the NEG opcode in CPUCore
[Theory]
[InlineData(0x00, 0x00, false, false)]
[InlineData(0x01, 0xFF, true, true)]
[InlineData(0x7F, 0x81, true, true)]
[InlineData(0x80, 0x80, true, true)]
[InlineData(0xFF, 0x01, false, true)]
[InlineData(0x81, 0x7F, false, true)]
public void NEG_8_Register_Test(byte input, byte expectedValue, bool expectedSF, bool expectedCF)
{
Reset();
mbbsEmuCpuRegisters.AL = input;

var instructions = new Assembler(16);
instructions.neg(al);
CreateCodeSegment(instructions);

mbbsEmuCpuCore.Tick();

Assert.Equal(expectedValue, mbbsEmuCpuRegisters.AL);
Assert.Equal(expectedSF, mbbsEmuCpuRegisters.SignFlag);
Assert.Equal(expectedCF, mbbsEmuCpuRegisters.CarryFlag);
}

//16bit Register Unit Tests for NEG
[Theory]
[InlineData(0x0000, 0x0000, false, false)]
[InlineData(0x0001, 0xFFFF, true, true)]
[InlineData(0x7FFF, 0x8001, true, true)]
[InlineData(0x8000, 0x8000, true, true)]
[InlineData(0xFFFF, 0x0001, false, true)]
[InlineData(0x8001, 0x7FFF, false, true)]
public void NEG_16_Register_Test(ushort input, ushort expectedValue, bool expectedSF, bool expectedCF)
{
Reset();
mbbsEmuCpuRegisters.AX = input;

var instructions = new Assembler(16);
instructions.neg(ax);
CreateCodeSegment(instructions);

mbbsEmuCpuCore.Tick();

Assert.Equal(expectedValue, mbbsEmuCpuRegisters.AX);
Assert.Equal(expectedSF, mbbsEmuCpuRegisters.SignFlag);
Assert.Equal(expectedCF, mbbsEmuCpuRegisters.CarryFlag);
}

}
}

0 comments on commit 8630512

Please sign in to comment.