cub-sdt-104-2024 / tasks

This repository hosts a task tracker for all projects.
1 stars 0 forks source link

Function to summarize debts #7

Closed dbarashev-jetbrains closed 1 month ago

dbarashev-jetbrains commented 1 month ago

Suppose that we have a list of ExpenseItem objects from issue #3. Now, we need to process it and build a summary of how much money every event participant owes other participants. For instance, if we have three records:

1:30:USD:john,paul,mick
2:60:USD:john,paul
3:20:USD:jose,mick
4:10:USD:jose,john

then paul owes john 30/3 + 60/2 = 40 USD, mick owes 30/3 =10 USD to john and 20/2=10 USD to jose, and john owes jose 5 USD.

john expects to receive 50 USD from his friends, and jose expects 15 USD.

The task is:

  1. Design a data structure DebtSummary, built from tuples, lists, dicts and atomic types, that would allow for storing the person's debts. It must store the following data:
    • the person id, e.g. john
    • the debt balance, that is, the difference between the total sum of the person's debts and the total sum of money he/she paid for others. In the example above, the john's balance is 45, because he owes 5 and other participants owe him 50.
    • a map of debts, where a participant id is mapped to a sum that this person owes to him/her.
  2. Write a function buildDebtSummaries(records: list[ExpenseItem]): list[DebtSummary] that builds the debt summaries.

Please write unit tests, make sure that they are passing (it is also a good idea to see them failing at least once), create a pull request with the changes, assign @dbarashev-jetbrains as a reviewer and wait until the end of the code review.

dbarashev-jetbrains commented 1 month ago

@DanLyss @whylot this is the second task for the first phase

DanLyss commented 1 month ago

Is currency fixed inside the records list, or it may differs from one record to another?

dbarashev-jetbrains commented 1 month ago

@DanLyss for now you may think that the currency is the same, however, it would be nice to be able to add currency conversion in the future without any significant changes in the code