Skip to content

Instantly share code, notes, and snippets.

Avatar

adilw3nomad adilw3nomad

  • Somewhere
View GitHub Profile
View blog.md

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

View code.md
package main

import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
"strings"
View block1.
go
package main
import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
"strings"
View block2.
go
package main
import “testing”
func TestCompareAnswer(t *testing.T) {
got := CompareAnswer(“3”, “3”)
if got != true {
t.Errorf(“CompareAnswer = %v; want true”, got)
}
View block3.
go
func TestCheckAnswer(t *testing.T) {
got := CheckAnswer(“3”, “3”)
if got != true {
t.Errorf(“CheckAnswer = %v; want true”, got)
}
}
View block4.
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)
}
View block5.
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)
}
View block6.
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]
View block8.
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 ()