Bug 438

Summary: Abnormal return value of getDuration() from Plan class
Product: Group 3 Reporter: Xavier.edith.lee
Component: Personal Finance MangementAssignee: Hsu To-Liang <tlhsu2-c>
Status: CONFIRMED ---    
Severity: critical CC: Xavier.edith.lee
Priority: ---    
Version: unspecified   
Hardware: PC   
OS: Mac OS   
Attachments: Bug reproduced and located in Plan class as suggested

Description Xavier.edith.lee 2020-11-22 17:45:47 HKT
When calculateAverage() was called, the result computed obviously was wrong and inconsistent with the expected result from test case. 

After some investigation, it was discovered that the denominator i.e. number of days, was given a wrong value from getDuration() function. May consider studying the implementation of that first.
Comment 1 Xavier.edith.lee 2020-11-22 18:16:51 HKT
Created attachment 49 [details]
Bug reproduced and located in Plan class as suggested

The result after unit testing was indeed caused by the aforementioned function getDuration(). It is suspected that the fault arose from the use of Period class to calculate date difference. 

As discussion from online forum revealed, Period class returns date difference separately in terms of [year, month, day]. Suppose dateDifference = 93 days. Period.getDays() will return 3 days since it is [0 year, 3 months, 3 days].

Alternative method is suggested to replace such erroneous function.
Comment 2 Hsu To-Liang 2020-11-23 20:21:03 HKT
After switching to DAYS.between(startDate, endDate) from ChronoUnit Class. The computation was corrected.