Skip to content

Switch amount measurement from floating point to integers #102

Description

@IsaacCheng9

Summary

  • The unit test for settling debt is currently non-deterministic, likely due to floating point arithmetic issues
    • Avoid floating point arithmetic by measuring currency amounts in integers instead of floating points
    • Switch the unit from pounds (GBP) to pence (GBX)
  • See example of non-deterministic test runs here (screenshot below):
image
Test Code
  // Check whether we can settle a debt between two users.
  test("POST /debts/settle", async () => {
    const server = supertest(app);
    await server
      .post("/debts/settle")
      .send({
        from: "testuser456",
        to: "testuser123",
        amount: 50,
      })
      .expect(200);

    // Check whether the debt was successfully reduced by 50.
    await debtModel
      .findOne({
        from: "testuser123",
        to: "testuser456",
      })
      .then((debt) => {
        expect(debt.amount).toBe(50);
      });
  });

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

    backendRequires attention on the backendbugSomething isn't workingdatabaseRequires a database modificationhigh priorityRequires immediate attention

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions