Skip to content

Commit

Permalink
Route to question on start
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Maccabe authored and Gary Maccabe committed Feb 20, 2021
1 parent aabe4e9 commit bac6b9d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
Binary file not shown.
12 changes: 9 additions & 3 deletions QuizGameEngine/GameFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@

import Foundation

protocol Router {}
protocol Router {
func routeTo(question: String)
}

class GameFlow {
let router: Router
let questions: [String]

init(router: Router) {
init(questions: [String], router: Router) {
self.questions = questions
self.router = router
}

func start() {

if(!questions.isEmpty) {
router.routeTo(question: "")
}
}
}
22 changes: 19 additions & 3 deletions QuizGameEngineTests/GameFlowTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
//
// Created by Gary Maccabe on 20/02/2021.
//
// Goal: To test the routing system and game flow
// Goal: To test the game routing system and flow

import Foundation
import XCTest
@testable import QuizGameEngine

class GameFlowTest: XCTestCase {

func test_start_with_no_questions(){
func test_start_with_no_questions_does_not_route_to_question(){
//arange
let router = RouterSpy()
let sysut = GameFlow(router: router)
let sysut = GameFlow(questions: [], router: router)

//act
sysut.start()
Expand All @@ -24,7 +24,23 @@ class GameFlowTest: XCTestCase {
XCTAssertEqual(router.routedQuestionCount, 0)
}

func test_start_with_one_question_routes_to_question(){
//arange
let router = RouterSpy()
let sysut = GameFlow(questions: ["Question 1"], router: router)

//act
sysut.start()

//assert
XCTAssertEqual(router.routedQuestionCount, 1)
}

class RouterSpy: Router {
var routedQuestionCount = 0

func routeTo(question: String) {
routedQuestionCount += 1
}
}
}

0 comments on commit bac6b9d

Please sign in to comment.