packageingotsconst(lavaDurationint=800blazeRodDurationint=120coalDurationint=80woodDurationint=15)// Requirements represents the differents types of fuel and in what amounts needed to complete the smelting jobtypeRequirementsstruct{LavaintBlazeRodintCoalintWoodintStickint}// Fuel determines the fuel requirements to smelt the given number of ingotsfuncFuel(ingotsint)Requirements{ifingots<=0{returnRequirements{0,0,0,0,0}}duration:=ingots*11returnRequirements{Lava:duration/lavaDuration+1,BlazeRod:duration/blazeRodDuration+1,Coal:duration/coalDuration+1,Wood:duration/woodDuration+1,Stick:duration,}}
ingots_test.go
packageingotsimport"testing"funcTestFuel(t*testing.T){testCases:=[]struct{descriptionstringinputintexpectedRequirements}{{"a few ingots",2,Requirements{1,1,1,2,22},},{"wow that is alot of ingots",500,Requirements{7,46,69,367,5500},},{"negative amount of ingots",-5,Requirements{0,0,0,0,0},},{"no ingots",0,Requirements{0,0,0,0,0},},}for_,test:=rangetestCases{ifresult:=Fuel(test.input);result!=test.expected{t.Fatalf("FAIL: %s - Fuel(%d): %+v - expected: %+v",test.description,test.input,result,test.expected)}t.Logf("PASS: %s",test.description)}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Time to Go smelting!
ingots.go
ingots_test.go