Skip to content

Instantly share code, notes, and snippets.

View adilw3nomad's full-sized avatar

adilw3nomad adilw3nomad

  • Somewhere
View GitHub Profile

29 May 2019 at 05:20

I started my morning with some cowboy coffee; which is coffee brewed in a saucepan, since I seem to have misplaced my aero press, as I listened to Go for beginners, and discovered Gophercises, a set of coding exercises in Go aimed at people who’ve done a few tutorials but have kinda lost steam. I felt like that described me, so I’ve decided to tackle these exercises while journalling my progress and learning in this blog.

/I have a peculiar writing style because I write in tandem with coding, so there’s a lot of tense switching, so apologies in advance. All comments and criticisms are encouraged, no matter how harsh or abrasive, as long as they are constructive!/

I’m going to tackle the first challenge, GitHub - gophercises/quiz: Ex 1 - Run timed quizzes via the command line.

So the first thing I need to do is make a new go pr

package main

import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
"strings"
go
package main
import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
"strings"
go
package main
import “testing”
func TestCompareAnswer(t *testing.T) {
got := CompareAnswer(“3”, “3”)
if got != true {
t.Errorf(“CompareAnswer = %v; want true”, got)
}
go
func TestCheckAnswer(t *testing.T) {
got := CheckAnswer(“3”, “3”)
if got != true {
t.Errorf(“CheckAnswer = %v; want true”, got)
}
}
go
func TestCheckAnswer(t *testing.T) {
gotCorrect := CheckAnswer(“3”, “3”)
if gotCorrect != “Correct! Well done” {
t.Errorf(“CheckAnswer = %v; want ‘Correct! Well Done’”, gotCorrect)
}
gotIncorrect := CheckAnswer(“3”, “2”)
if gotIncorrect != “WRONG! Answer is: 2” {
t.Errorf(“CheckAnswer = %v; want ‘WRONG! Answer is: 2’”, gotIncorrect)
}
go
package main
import “testing”
func TestCheckCorrectAnswer(t *testing.T) {
got := CheckAnswer(“3”, “3”)
if got != “Correct! Well done” {
t.Errorf(“CheckCorrectAnswer = %v; want ‘Correct! Well Done’”, got)
}
shell
06:24 $ go test
# github.com/adilw3nomad/GopherQuiz [github.com/adilw3nomad/GopherQuiz.test]
./main_test.go:6:9: undefined: CheckAnswer
./main_test.go:13:9: undefined: CheckAnswer
FAIL github.com/adilw3nomad/GopherQuiz [build failed]
shell
06:29 $ go test
# github.com/adilw3nomad/GopherQuiz [github.com/adilw3nomad/GopherQuiz.test]
./main_test.go:6:20: too many arguments in call to CheckAnswer
have (string, string)
want ()
./main_test.go:6:20: CheckAnswer("3", "3") used as value
./main_test.go:13:20: too many arguments in call to CheckAnswer
have (string, string)
want ()
go
func CheckAnswer() {
}