Created
October 20, 2014 18:53
-
-
Save pragmaticlogic/3671aed051494f4eec0e to your computer and use it in GitHub Desktop.
Swift Tower Test Interactive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func checkTower(dest:Stack<Int>, numberOfDisks:Int) -> Bool { | |
| var match = true | |
| var index = 1 | |
| while match && dest.size() > 0 && index <= numberOfDisks { | |
| match = dest.pop() == index | |
| index++ | |
| } | |
| return match | |
| } | |
| func testInteractiveTowerOfHanoi() { | |
| let towerStacks: [Tower: Stack<Int>] = [.Tower1: Stack<Int>(), .Tower2: Stack<Int>(), .Tower3: Stack<Int>()] | |
| let numberOfDisks = 4 | |
| for var index = numberOfDisks; index > 0; index-- { | |
| towerStacks[.Tower1]?.push(index) | |
| } | |
| towerInteractive(numberOfDisks, towerStacks) //results in tower 2 as the destination | |
| XCTAssert(checkTower(towerStacks[.Tower2]!, numberOfDisks: numberOfDisks), "Pass") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment