Skip to content

Instantly share code, notes, and snippets.

Avatar

adilw3nomad adilw3nomad

  • Somewhere
View GitHub Profile
View GopherGymPart1.6.go
package main
import (
"bufio"
"encoding/csv"
"fmt"
"io"
"log"
"os"
"strings"
View GopherGymPart1.5.go
package main
import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
"strings"
)
View GopherGymPart1.4.go
package main
import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
)
View GopherGymPart1.3.go
package main
import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
)
View GopherGymPart1.2.go
package main
import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
)
View GopherGymPart1.1.go
package main
import (
"encoding/csv"
"fmt"
"log"
"os"
)
func main() {
View blog.md

2 Jun 2019 at 01:52


We finished the last post with three tasks to tackle:

  • Adding tests
  • Keeping track of the score
  • Adding a flag that allows the CSV file to be customised.

The priority is to add tests, as I’m a firm believer in the benefits of Test Driven Development, often abbreviated as TDD. In a nutshell, you write a test of some behaviour you want to implement. You then run the test, see it fail, and make the smallest possible change to make it pass. Once your test is green, it’s time to refactor. Thus it becomes a cycle; red green, refactor.

View block18.
shell
06:56 $ go test
PASS
ok github.com/adilw3nomad/GopherQuiz 0.004s
View block17.go
func CheckAnswer(answer string, correctAnswer string) string {
if answer == correctAnswer {
returnCorrect! Well done
} else {
return (“WRONG! Answer is: “ + correctAnswer)
}
}
View block16.
shell
06:51 $ go test
--- FAIL: TestCheckIncorrectAnswer (0.00s)
main_test.go:15: CheckIncorrectAnswer = Correct! Well done; want 'WRONG! Answer is: 2'
FAIL
exit status 1
FAIL github.com/adilw3nomad/GopherQuiz 0.005s