Commit d5aed80
Changed files (1)
command.go
@@ -94,6 +94,28 @@ func init() {
commandArray = append(commandArray, helpCommand)
}
+// displayTests displays the previous tests to the user
+func displayTests(clientTests *[]ClientTest) {
+ hardRule := "--------------------------------------------------------"
+ fmt.Printf("\n%s\n%25s\n%s\n", hardRule, "Tests", hardRule)
+ fmt.Printf(" %3s | %7s | %9s | %3s | %7s | %9s |\n", "No.", "Score", "Questions",
+ "No.", "Score", "Questions")
+ fmt.Print(hardRule + "\n")
+ numQuestions, numCorrect := float32(0.0), float32(0.0)
+ for i := 0; i < len(*clientTests); i++ {
+ numQ := float32(len((*clientTests)[i].Records))
+ fmt.Printf(" %3d |%7.2f%% | %9.0f |", i, (*clientTests)[i].Score, numQ)
+ numCorrect += (*clientTests)[i].Score / 100.0 * numQ
+ numQuestions += numQ
+ if i%2 != 0 && i != 0 {
+ fmt.Print("\n")
+ }
+ }
+ fmt.Print("\n" + hardRule + "\n")
+ fmt.Printf("Average: %.2f%%\n%s\nQuestions Answered: %.0f\t Questions Correct: %.0f\n%s",
+ numCorrect/numQuestions*100, hardRule, numQuestions, numCorrect, hardRule)
+}
+
// getScoreFromServer retrieves the previous tests for this user
// from the server
func getScoreFromServer(command Command) error {
@@ -110,6 +132,7 @@ func getScoreFromServer(command Command) error {
return fmt.Errorf("Error while parsing request: %+v", err)
}
fmt.Printf("Pulled %d tests from server.", len(clientTests))
+ displayTests(&clientTests)
return nil
}