Skip to content

[Bug]: <short description> #3

Description

@jkeresman01

Add missing // GIVEN, // WHEN, // THEN to unit tests

Summary

Some of the existing unit tests for the 6502 CPU instructionslack the // GIVEN, // WHEN, // THEN structure that improves readability and consistency across the test suite. Adding these comments will make the intent of each test clearer and align them with the project’s test documentation standards.

Steps to Reproduce

  1. Open the CPU6502DEYTests file.
  2. Review the tests:
    • WillDEYDecrementYCorrectly
    • WillDEYSetZeroFlag
    • WillDEYSetNegativeFlag
  3. Notice that the code lacks explicit // GIVEN, // WHEN, // THEN sections.
  4. Observe the inconsistency with other tests that already use this format.

Actual Behavior

The current tests do not have clear section comments describing the setup, action, and verification phases. This can make them harder to follow at a glance.

Expected Behavior

Each test should clearly separate its setup, execution, and verification phases using the // GIVEN, // WHEN, and // THEN comment format.

Example:

TEST_F(CPU6502DEYTests, WillDEYDecrementYCorrectly)
{
    // GIVEN: A Y register set to 0x43 and a DEY instruction in memory
    cpu.SetRegisterY(0x43);
    Memory::Write(0x8000, 0x88); // DEY

    // WHEN: The CPU executes one instruction
    cpu.Step();

    // THEN: The Y register should decrement by one and flags updated correctly
    EXPECT_EQ(cpu.GetRegisterY(), 0x42);
    EXPECT_FALSE(cpu.GetStatusFlags().Z);
    EXPECT_FALSE(cpu.GetStatusFlags().N);
}

Proposed Solution (high level)

Add // GIVEN, // WHEN, and // THEN comments to each test suite that misses it.

Environment

  • OS: n/a
  • Other relevant information: Unit tests, CPU emulation test suite

Acceptance Criteria

  • All CPU6502 Tests contain // GIVEN, // WHEN, // THEN comments.
  • Comment phrasing matches the style of existing instruction tests.
  • Tests remain functionally identical and continue to pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions