Test case mainCalculateReturnsOldTrades is failing.I have spent a lot of time on this

I tried everything from sorting by extracting the values , then using comparable and making a custom function.Now i am using compareTo by creating a comparable object using lambda expression. I even tried using BigDecimal for accuracy. this one test case just doesnt pass!!! I have spent a lot of time to resolve this. The forum says the problem is with sorting. Is that the only thing to be taken care of ? can anyone from crio look into my code and help me out?
@Saurav_Crio.Do @ajay-crio @amanagar

Hey @AthuK you have to sort it according annualizedreturn and if you are facing issue then try to debug it because as you have said your function is correct but still you are facing that error so probably you are making some minor mistake or edge mistake which varies for person to person

debug it in what manner? we dont have the function OldTrades to run a debug . its hidden.

Try To debug it you will find out in which line or function you are making mistake.

ok wait looking into your code

Hey @AthuK looked into your code and got your mistake totalreturn which you are returning is not right you are using wrong method i have tried to debug your code and left some traces try to checkout where are you doing mistake.

Thank you so much. but the method of calculation on total returns is given in TODO, i.e totalReturns = (sellPrice - buyPrice) / buyPrice. thats exactly what im applying.

i tired returning totalreturn*1000 but even that failed.

That’s what you have to apply but as i have mentioned earlier learn to debug How TO Debug debugging is just not about VScode debugging, you are doing silly mistake related to datatype check datatype of your totalreturn and datatype that is defined in Annualizedreturn.java pojo for totalreturn still there are some mistake try to find them.

I know this might be really annoying,Really sorry for the trouble. I worked it out,passed the right datatypes,corrected my code, cross verified multiple times. the build still fails :man_facepalming:

Please look into it when you have the time . Thank you :slight_smile:

Hey @AthuK you have got your mistake right i have mentioned your possible mistakes previously now debug it by yourself that’s how you will learn and grow as we say at Crio Learning Is Doing & It’s Real :grinning: :smiley: :smile: :grin: :laughing: .

Happy Coding

check your return data type and check if it returns the correct value when the time difference is less than a year.
there are a lot of posts already on the 2nd issue.
try debugging the issue yourself. you’ll be proud of yourself when you resolve it yourself

Okay so as everyone stated that sorting might be the issue for high precision numbers so i wrote my own test function and passed doubles with high precision values like 4.000001,4.000002. That works too

Before Sort

before sort !

After Sort

after sort !

This works perfectly too. and as far as less than a year is concerned, there is already a test case given by crio to check this.

Have never been more stuck.

did you pass that less than a year test case?

Yes I did pass the less than a year test

in the formula instead of 1/year use 1.0(or whatever you’ve used change it to float)

I used the formula with respect to days. As in 365.00/ number of days. @robsteneha

yeah then i don’t know why it’s not working then. i can’t even ask to see your code to find mistakes cuz that would be a violation.
i guess just write the whole code again. maybe you’re missing something really silly

Hey @AthuK make sure you are following instructions and just mentioning have you consider the edge case when we are not parsing endDate in args then you have to consider endDate as latest date try this if this can help.