Two test cases are failing

Two test case testCalculateAnnualizedReturnGoogle and mainCalculateAnnualReturn are failing. Stuck here for a while. I have sorted list using comparable interface. Can someone guide me? Where i might be going wrong?

Hi @manmodesanket, you’ll get a report with the error trace if you run the tests from the Test window incontrast to the gradle command

Yes I know that. I am not getting what to do.

Ok, please post what error you are getting

There might be a calculation mistake in calculateAnnualizedReturns. That’s why these 2 test cases are failing. Check the output of your code. And verify it with expected output.

This really helps;

I made some changes in calculateAnnualizedReturns function. Now only mainCalculateAnnualReturn is failing.

Which class have you used for conversion of dates to days or years?
ChronoUnit or Period?

ChronoUnit is better. Its also available during the pull so I guess the team also suggests its use only.

1 Like

And while sorting I have used comparable interface. But it is not sorting. I have override compareTo function. Any suggessions

I don’t think the tests would fail because of that, because we had the option of using comparable and comparator both. Try switching if you think that’s the case.

Yes test is failing because of that
INFO: [{“symbol”:“GOOGL”,“annualizedReturn”:0.3347747199150335,“totalReturns”:0.3127823208722741},{“symbol”:“MSFT”,“annualizedReturn”:0.580399107054
This is the result i am getting.

The error in test is

org.opentest4j.AssertionFailedError: expected: <0.814> but was: <0.3347747199150335>

Look at that last element in json it is 0.81367… which is 0.814

Now i am passing all the local test cases but mainCalculateReturnsVaryingDateRanges() and mainCalculateReturnsOldTrades() is failing
Can you look at my code

btw I used ChronoUnit

can u help me resolve this error , i am getting same error expected: <0.814> but was: <0.3339674495466278>

I have resolved it. You are making error with calculation. Use ChronoUnit class. Calculate only days and convert it into years.

1 Like