packageeducationimport"testing"typebaseTestCasestruct{descriptionstring}varbob=Student{"Bob",4,0,0}varmary=Student{"Mary",0,2,0}varjohn=Student{"John",0,0,1}vargoat=Student{"Goat",0,0,0}varrichie=Student{"Richie",10,20,100}funcTestTrip_Richest(t*testing.T){testCases:=[]struct{baseTestCaseinputTripexpectedstring}{{baseTestCase{"no students"},Trip{},"none",},{baseTestCase{"one student"},Trip{[]Student{mary}},mary.Name,},{baseTestCase{"many students with same amount of funds"},Trip{[]Student{mary,bob,john}},"all",},{baseTestCase{"many students with one having more"},Trip{[]Student{mary,bob,goat,richie}},richie.Name,},}for_,test:=rangetestCases{ifresult:=test.input.Richest();result!=test.expected{t.Fatalf("FAIL: %s - %+v.Funds(): '%s' - expected: '%s'",test.baseTestCase.description,test.input,result,test.expected)}t.Logf("PASS: %s",test.baseTestCase.description)}}funcTestStudent_Funds(t*testing.T){testCases:=[]struct{baseTestCaseinputStudentexpectedint}{{baseTestCase{"no moniez"},goat,0,},{baseTestCase{"only fives"},bob,20,},{baseTestCase{"only tens"},mary,20,},{baseTestCase{"only twenties"},john,20,},{baseTestCase{"all the moniez"},richie,2250,},}for_,test:=rangetestCases{ifresult:=test.input.Funds();result!=test.expected{t.Fatalf("FAIL: %s - %+v.Funds(): %d - expected: %d",test.baseTestCase.description,test.input,result,test.expected)}t.Logf("PASS: %s",test.baseTestCase.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.
I put myself in here as a test case as a joke because I didn't get an allowance as a kid 😂
education.go
education_test.go