Skip to content

[Bug]: Accuracy can become negative after repeated corrections #1

Description

@Siddhesh100711

Hi @bilalmlkdev ! I'm Siddhesh, and I'm currently contributing to RhythmKey as part of my ROSPL open-source project.

While testing the typing engine locally, I came across this accuracy calculation issue and was able to reproduce it consistently.

What happened?

Accuracy can become negative when incorrect characters are repeatedly typed and then deleted with Backspace.

The Accuracy formula is documented as:

((Total Characters - Mistakes) / Total Characters) * 100

When a wrong character is typed, the mistake counter increases. Pressing Backspace removes the character from the current input, but the mistake count is not reduced. Repeating this process can therefore make the number of mistakes greater than the number of characters currently in the input.

For example, I was able to reproduce an Accuracy of approximately -780%.

This also appears to affect the accuracy values used in the performance graph/statistics.

Steps to reproduce

  1. Go to /app/taketypingtest.
  2. Start a typing test.
  3. Type an incorrect character.
  4. Press Backspace to remove it.
  5. Repeat the incorrect character → Backspace sequence multiple times during the same test.
  6. Finish the test.
  7. Open the results screen and check the Accuracy value.
  8. Observe that Accuracy can become negative.

What did you expect to happen?

Accuracy should remain within a valid percentage range (0-100) and should not become negative.

Incorrect attempts and corrected characters should also be handled consistently when calculating the final Accuracy.

Browser

Google Chrome 153

Theme

None

Screenshots or additional context

Image Image

Additional context:

The issue was reproduced locally using the development build.

The documented Accuracy formula is:

((Total Characters - Mistakes) / Total Characters) * 100

The current implementation uses the current userInput.length as Total Characters. A wrong printable key increments mistakes, while Backspace removes the character from userInput without decrementing mistakes.

As a result, repeated corrections can cause mistakes to exceed the current number of characters, producing negative Accuracy values.

Examples observed during testing:

  • Accuracy: -66%
  • Accuracy: -4300%

No files were modified while investigating this issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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