Skip to content

Instantly share code, notes, and snippets.

@3v0k4
Last active December 21, 2019 00:17
Show Gist options
  • Save 3v0k4/486643c291ccd28977af3282bfb22495 to your computer and use it in GitHub Desktop.
Save 3v0k4/486643c291ccd28977af3282bfb22495 to your computer and use it in GitHub Desktop.
main :: Effect Unit
main = do
testDeposit
testWithdraw
testPrintStatementNoTransactions
testPrintStatementWithTransactions
testDeposit :: Effect Unit
testDeposit = do
timestamp <- nowDateTime
let amount = 1
expected = Identity [ Deposit { amount: amount, timestamp: timestamp } ]
actual = execStateT (deposit (Identity timestamp) amount) []
assertEqual { actual: actual, expected: expected }
testWithdraw :: Effect Unit
testWithdraw = do
timestamp <- nowDateTime
let amount = 1
expected = Identity [ Withdraw { amount: amount, timestamp: timestamp } ]
actual = execStateT (withdraw (Identity timestamp) amount) []
assertEqual { actual: actual, expected: expected }
testPrintStatementNoTransactions :: Effect Unit
testPrintStatementNoTransactions = do
let expected = ""
actual = execWriter (evalStateT (printStatement \s -> tell s) [])
assertEqual { actual: actual, expected: expected }
testPrintStatementWithTransactions :: Effect Unit
testPrintStatementWithTransactions = do
timestamp <- nowDateTime
let d = Deposit { amount: 500, timestamp: timestamp }
w = Withdraw { amount: 100, timestamp: timestamp }
state = [ d, w ]
expected = "expected string"
actual = execWriter (evalStateT (printStatement \s -> tell s) state)
assertEqual { actual: actual, expected: expected }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment