Skip to content

Switch amount measurement from floating point to integers #102

@IsaacCheng9

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);
      });
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions