Skip to content

Commit a8404c9

Browse files
copilot-core: Increase test coverage of Copilot.Core.Type.Array. Refs #502.
The test coverage of copilot-core is currently reported at 25% by Hackage. This commit includes tests for all top-level functions in Copilot.Core.Type.Array. We cannot generate random values of type-level literals, so any tests involving array types with specific lengths use hard-coded values.
1 parent 12a7ffe commit a8404c9

File tree

1 file changed

+19
-2
lines changed
  • copilot-core/tests/Test/Copilot/Core/Type

1 file changed

+19
-2
lines changed

copilot-core/tests/Test/Copilot/Core/Type/Array.hs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import Data.Proxy (Proxy (..))
99
import GHC.TypeNats (KnownNat, natVal)
1010
import Test.Framework (Test, testGroup)
1111
import Test.Framework.Providers.QuickCheck2 (testProperty)
12-
import Test.QuickCheck (Gen, Property, arbitrary, forAll,
13-
vectorOf)
12+
import Test.QuickCheck (Gen, Property, arbitrary,
13+
expectFailure, forAll, property,
14+
vector, vectorOf)
1415

1516
-- Internal imports: library modules being tested
1617
import Copilot.Core.Type.Array (Array, array, arrayElems)
@@ -25,6 +26,10 @@ tests =
2526
(testArrayElemsLeft (Proxy :: Proxy 5))
2627
, testProperty "arrayElems . array (identity; 200)"
2728
(testArrayElemsLeft (Proxy :: Proxy 200))
29+
, testProperty "array of incorrect length"
30+
testArrayElemsFail
31+
, testProperty "Show for arrays"
32+
testShowArray
2833
]
2934

3035
-- * Individual tests
@@ -43,3 +48,15 @@ testArrayElemsLeft len =
4348
-- Generator for lists of Int64 of known length.
4449
xsInt64 :: Gen [Int64]
4550
xsInt64 = vectorOf (fromIntegral (natVal len)) arbitrary
51+
52+
-- | Test that arrays cannot be properly evaluated if their length does not
53+
-- match their type.
54+
testArrayElemsFail :: Property
55+
testArrayElemsFail = expectFailure $ forAll (vector 3) $ \l ->
56+
let v = array l :: Array 4 Int64
57+
in arrayElems v == l
58+
59+
-- | Test show for arrays.
60+
testShowArray :: Property
61+
testShowArray = forAll (vector 3) $ \l -> property $
62+
show (array l :: Array 3 Int64) == show (l :: [Int64])

0 commit comments

Comments
 (0)