All this talk of evolution makes me want to Go play Pokemon again. Holy crap I haven't played that in a long time!
rate.go
packageevolutionimport"fmt"const(negativestring="A negative evolution of %.f%%."positivestring="A positive evolution of %.f%%."neutralstring="No evolution.")// Rate indicates the evolution percentage based on the before and after valuesfuncRate(beforefloat64,afterfloat64)string{ifbefore==0{returnfmt.Sprintf(positive,after*100)}ifafter==0{returnfmt.Sprintf(negative,before*100)}rate:=(after-before)/before*100ifrate>0{returnfmt.Sprintf(positive,rate)}ifrate<0{returnfmt.Sprintf(negative,rate*-1)}returnneutral}
rate_test.go
packageevolutionimport"testing"typetestCasestruct{descriptionstringinput[]float64expectedstring}funcTestRate(t*testing.T){testCases:=[]testCase{{"a positive evolution rate",[]float64{11.29,45.79},"A positive evolution of 306%.",},{"a negative evolution rate",[]float64{95.12,66.84},"A negative evolution of 30%.",},{"zero before value",[]float64{0,27.35},"A positive evolution of 2735%.",},{"zero after value",[]float64{41.26,0},"A negative evolution of 4126%.",},{"same before and after values",[]float64{1.26,1.26},"No evolution.",},}for_,test:=rangetestCases{ifresult:=Rate(test.input[0],test.input[1]);result!=test.expected{t.Fatalf("FAIL: %s - Rate(%+v): %s - expected: %s",test.description,test.input,result,test.expected)}t.Logf("PASS: %s",test.description)}}
All this talk of evolution makes me want to Go play Pokemon again. Holy crap I haven't played that in a long time!
rate.go
rate_test.go
I always love your take at these challenges in Go. I should get started soon. Looking sharp as always!
And yes, Pokemon is just timelessly good. I could play it all my life haha!
Ah shucks, I am humbled by the praise.
You should, Go is a very easy language to pick up and use.
Only part that may require a little more effort to understand is the concurrency related features of it but just pick those up as you need them.