Skip to content

Instantly share code, notes, and snippets.

String.prototype.reverse = function() {
return this.split("").reverse().join("");
}
function fib_recursive(n) {
return n <= 1 ? n : fib_recursive(n-1) + fib_recursive(n-2);
}
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;
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))
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}
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 )
module TestHelper where
import HUnit.HUnit
assertTrue description expression = assertEqual description True expression
assertFalse description expression = assertEqual description False expression
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
module UI.TestMenu where
import TestHelper
import HUnit.HUnit
import UI.Menu as Menu
mockBoard = "+++++++++"
mockFormatBoard board = board
testPrint expected actual = expected == actual
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)