Unit Tests

Now that some opcodes have been implemented and are working properly, it becomes more and more important to be able to test the whole system. Especially when new functions have been installed or a refactoring has taken place. That’s why I decided to test with ‘NUnit’. The corresponding tests are written for all methods of the CPU and for all opcodes.

Let’s have a look at how to test one of the opcodes i.e. LDA – 0xA9


        [TestCase(0xff, ExpectedResult = new object[] { false, true, 0xff })]
        [TestCase(0x00, ExpectedResult = new object[] { true, false, 0x00 })]
        public object[] Cmd_A9_Test(byte b)
        {
            object[] result = new object[3];

            cpu.WriteByteToMemory(b, 0x200);
            cpu.SetPC(0x200);
            cpu.Cmd_A9();

            result[0] = cpu.flags["Z"];
            result[1] = cpu.flags["N"];
            result[2] = cpu.A;

            return result;

        }

After writing tests for all existing methods, I will try to move to a ‘test driven development’ TDD. So for each method/function, a test is written first and then the actual method. Let’s see how it will be.

Leave a Reply

Your email address will not be published. Required fields are marked *