Perl solution. I still don't understand how the values are computed for zeroes, but it passes the tests :-)
#!/usr/bin/perlusewarnings;usestrict;usefeatureqw{ say };sub get_evolution_rate_message{my($before,$after)=@_;return'No evolution.'if$before==$after;returnsprintf'A %s evolution of %.0f%%.',qw(_ negative positive)[$before<=>$after],abs(($before-($after||($before+$before**2)))*100/($before||1))}useTest::Moretests=>5;isget_evolution_rate_message(11.29,45.79),'A positive evolution of 306%.';isget_evolution_rate_message(95.12,66.84),'A negative evolution of 30%.';isget_evolution_rate_message(0,27.35),'A positive evolution of 2735%.';isget_evolution_rate_message(41.26,0),'A negative evolution of 4126%.';isget_evolution_rate_message(1.26,1.26),'No evolution.';
Perl solution. I still don't understand how the values are computed for zeroes, but it passes the tests :-)
Imagine that instead of going from 0 to 27.35, you are going from 0.0000000001 to 27.35. I think you'll have your answer here. 😉