Last active
May 17, 2019 17:30
-
-
Save j3speaks/24bf56ef3e2f21813890ff7d11adfdc1 to your computer and use it in GitHub Desktop.
Bridge and Torch Logic Puzzle (written in Go)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"sort" | |
"testing" | |
) | |
func TestNumberOfParticipants(t *testing.T) { | |
// Initialize our Participants array | |
participants := GetJSONFileStuffInStruct("input.json") | |
if len(participants.Participants) != 0 { | |
// Get the number of participants in the jsonFile | |
numberOfParticipants := len(participants.Participants) | |
wantValue := 4 | |
errorWant := fmt.Sprintf("numberOfParticipants was not %d, ", wantValue) | |
if numberOfParticipants != wantValue { | |
t.Errorf(errorWant+"got: %d, want: %d.", numberOfParticipants, wantValue) | |
} | |
} | |
} | |
func TestSlowestPartcipant(t *testing.T) { | |
// Initialize our Participants array | |
participants := GetJSONFileStuffInStruct("input.json") | |
if len(participants.Participants) != 0 { | |
// Sort the list of participant by speed in descending order | |
sort.Slice(participants.Participants, func(i, j int) bool { | |
return participants.Participants[i].Speed < participants.Participants[j].Speed | |
}) | |
wantName := "Shiv" | |
wantValue := 8 | |
errorWant := fmt.Sprintf("Slowest Participant is not '{%s %d}', ", wantName, wantValue) | |
if participants.Participants[(len(participants.Participants)-1)] != (Participant{Name: wantName, Speed: wantValue}) { | |
t.Errorf(errorWant+"got: %v, want: %v.", participants.Participants[(len(participants.Participants)-1)], (Participant{Name: wantName, Speed: wantValue})) | |
} | |
} | |
} | |
func TestFastestPartcipant(t *testing.T) { | |
// Initialize our Participants array | |
participants := GetJSONFileStuffInStruct("input.json") | |
if len(participants.Participants) != 0 { | |
// Sort the list of participant by speed in descending order | |
sort.Slice(participants.Participants, func(i, j int) bool { | |
return participants.Participants[i].Speed < participants.Participants[j].Speed | |
}) | |
wantName := "Mouna" | |
wantValue := 1 | |
errorWant := fmt.Sprintf("Fastest Participant is not '{%s %d}', ", wantName, wantValue) | |
if participants.Participants[0] != (Participant{Name: wantName, Speed: wantValue}) { | |
t.Errorf(errorWant+"got: %v, want: %v.", participants.Participants[0], (Participant{Name: wantName, Speed: wantValue})) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment