forked from tibbe/event
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,3 +1,12 @@ | |||
import Distribution.Simple | module Main (main) where | ||
|
|
||
main = defaultMain | import Distribution.Simple (defaultMainWithHooks, runTests, simpleUserHooks) | ||
import System.Cmd (system) | |||
|
|||
main :: IO () | |||
main = | |||
defaultMainWithHooks $ simpleUserHooks { runTests = runTests' } | |||
where | |||
runTests' _ _ _ _ = do | |||
system "runhaskell -i./src tests/Array.hs" | |||
return () |
This file contains 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
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,67 @@ | |||
import Control.Monad (when) | |||
import System.Exit (exitFailure) | |||
|
|||
import System.Event.Array (Array) | |||
import qualified System.Event.Array as A | |||
|
|||
import Test.HUnit (Counts(..), Test(..), (@=?), runTestTT) | |||
|
|||
main :: IO () | |||
main = do | |||
counts <- runTestTT tests | |||
when (errors counts + failures counts > 0) exitFailure | |||
where | |||
tests = TestList | |||
[ TestLabel "empty" testEmpty | |||
, TestLabel "new 0" (testNew 0 0) | |||
, TestLabel "new 1" (testNew 1 1) | |||
, TestLabel "new 50" (testNew 50 64) | |||
, TestLabel "new 100" (testNew 100 128) | |||
, TestLabel "new 128" (testNew 128 128) | |||
, TestLabel "ensureCapacity 0 on empty" (testEnsureCapacity A.empty 0 0) | |||
, TestLabel "ensureCapacity 0 on cap 4" (testEnsureCapacity (A.new 4) 0 4) | |||
, TestLabel "ensureCapacity 4 on cap 4" (testEnsureCapacity (A.new 4) 4 4) | |||
, TestLabel "ensureCapacity 5 on cap 4" (testEnsureCapacity (A.new 4) 5 8) | |||
, TestLabel "1 snoc on cap 0" (testSnoc 0 1 1) | |||
, TestLabel "5 snocs on cap 4" (testSnoc 4 5 8) | |||
] | |||
|
|||
testEmpty :: Test | |||
testEmpty = TestCase $ do | |||
arr <- A.empty | |||
lenA <- A.length arr | |||
capA <- A.capacity arr | |||
0 @=? lenA | |||
0 @=? capA | |||
|
|||
testNew :: Int -> Int -> Test | |||
testNew cI cC = TestCase $ do | |||
arr <- A.new cI :: IO (Array Int) | |||
lenA <- A.length arr | |||
capA <- A.capacity arr | |||
0 @=? lenA | |||
cC @=? capA | |||
|
|||
testEnsureCapacity :: IO (Array Int) -> Int -> Int -> Test | |||
testEnsureCapacity ioarr cI cC = TestCase $ do | |||
arr <- ioarr | |||
A.ensureCapacity arr cI | |||
lenA <- A.length arr | |||
capA <- A.capacity arr | |||
0 @=? lenA | |||
cC @=? capA | |||
|
|||
testSnoc :: Int -> Int -> Int -> Test | |||
testSnoc cI h capC = TestCase $ do | |||
arr <- A.new cI :: IO (Array Int) | |||
mapM_ (A.snoc arr) esC | |||
lenA <- A.length arr | |||
capA <- A.capacity arr | |||
esA <- mapM (A.unsafeRead arr) is | |||
lenC @=? lenA | |||
capC @=? capA | |||
esC @=? esA | |||
where | |||
lenC = h | |||
esC = [1..h] | |||
is = [0..pred h] |