Skip to content

Instantly share code, notes, and snippets.

View adilw3nomad's full-sized avatar

adilw3nomad adilw3nomad

  • Somewhere
View GitHub Profile
package main
import (
"bufio"
"encoding/csv"
"fmt"
"io"
"log"
"os"
"strings"
package main
import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
"strings"
)
package main
import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
)
package main
import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
)
package main
import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
)
package main
import (
"encoding/csv"
"fmt"
"log"
"os"
)
func main() {

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.

shell
06:56 $ go test
PASS
ok github.com/adilw3nomad/GopherQuiz 0.004s
func CheckAnswer(answer string, correctAnswer string) string {
if answer == correctAnswer {
return “Correct! Well done”
} else {
return (“WRONG! Answer is: “ + correctAnswer)
}
}
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