Skip to content

Commit

Permalink
feat(TransactionArchive): Implement TODO countDistinctWeeks() and cor…
Browse files Browse the repository at this point in the history
…responding tests.
  • Loading branch information
pawelsa committed Mar 25, 2026
1 parent 4c6750c commit d1ae6ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ public List<Sale> getSales(int week) {
*
* @return
*/
public int countDistinctWeeks() { // TODO: HERE
return -1;
public int countDistinctWeeks() {
return (int) transactions.stream()
.map(Transaction::getWeek)
.distinct()
.count();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,18 @@ void PTgetTransactions() {

}

/**
* Tests for countDistinctWeeks().
*/
@Test
void PTcountDistinctWeeks() {
assertEquals(2, transactionArchive.countDistinctWeeks());
}

@Test
void NTcountDistinctWeeks() {
TransactionArchive tArchive = new TransactionArchive();
assertEquals(0, tArchive.countDistinctWeeks());
}

}

0 comments on commit d1ae6ae

Please sign in to comment.