Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Array.hs tests

  • Loading branch information...
commit 78788dac3f552f2f949c0e1c70b145c4fbda4281 1 parent 28321d4
@bsl bsl authored
Showing with 79 additions and 3 deletions.
  1. +11 −2 Setup.hs
  2. +1 −1  event.cabal
  3. +67 −0 tests/Array.hs
View
13 Setup.hs
@@ -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 ()
View
2  event.cabal
@@ -10,7 +10,7 @@ author: Bryan O'Sullivan <bos@serpentine.com>
maintainer: Johan Tibell <johan.tibell@gmail.com>
category: System
-build-type: Simple
+build-type: Custom
cabal-version: >= 1.6
library
View
67 tests/Array.hs
@@ -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]
Please sign in to comment.
Something went wrong with that request. Please try again.