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
| String.prototype.reverse = function() { | |
| return this.split("").reverse().join(""); | |
| } |
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
| function fib_recursive(n) { | |
| return n <= 1 ? n : fib_recursive(n-1) + fib_recursive(n-2); | |
| } |
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
| function fib_iterative(n) { | |
| var a = 0; | |
| var b = 1; | |
| var c = 0; | |
| for (i = 0; i < n; i++) { | |
| c = a + b; | |
| a = b; | |
| b = c; | |
| } | |
| this.result = a; |
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
| module Board.TestBoard where | |
| import Board.Board | |
| import Board.Mark | |
| import HUnit.HUnit | |
| testBoard = [empty, o, empty, empty, empty, empty, empty, empty, empty] | |
| testIsEmpty = TestCase (assertEqual "should return true if the given index on board is marked empty," True (isEmpty testBoard 0)) | |
| testIsNotEmpty = TestCase (assertEqual "should return false if the given index on board is not marked empty," False (isEmpty testBoard 1)) |
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
| suite = [ TestLabel "Given Index is Empty" testIsEmpty, | |
| TestLabel "Given Index is Not Empty" testIsNotEmpty ] | |
| main = runTestTT (TestList suite) | |
| -- Test Results : | |
| -- Case 2 Tried 0 Errors: 0 Failures: 0 | |
| -- Case 2 Tried 1 Errors: 0 Failures: 0 | |
| -- Counts {cases = 2, tried = 2, errors = 0, failures = 0} |
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
| module AllTests where | |
| import HUnit.Hunit | |
| import qualified Board.TestBoard as TestBoard (suite) | |
| import qualified Board.TestMark as TestMark (suite) | |
| allTests = TestList | |
| ( TestBoard.suite | |
| ++ TestMark.suite ) |
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
| module TestHelper where | |
| import HUnit.HUnit | |
| assertTrue description expression = assertEqual description True expression | |
| assertFalse description expression = assertEqual description False expression |
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
| module UI.Menu (putBoard) where | |
| -- putBoard format board = putStr $ format board | |
| putBoard puts format board = puts $ format board | |
| -- askMove = return =<< getLine | |
| askMove gets = return =<< gets |
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
| module UI.TestMenu where | |
| import TestHelper | |
| import HUnit.HUnit | |
| import UI.Menu as Menu | |
| mockBoard = "+++++++++" | |
| mockFormatBoard board = board | |
| testPrint expected actual = expected == actual |
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
| module UI.TestMenu where | |
| import TestHelper | |
| import HUnit.HUnit | |
| import UI.Menu as Menu | |
| gets move = return move | |
| testAskMove = TestCase (do move <- askMove $ gets 0 | |
| assertEqual "should return 0," 0 move) |