@@ -47,24 +47,13 @@ arrayTests = testGroup "Array Tests"
4747--------------------------------------------------------------------------------
4848testMakeArray :: TestTree
4949testMakeArray = testGroup " MakeArray Tests"
50- [ caseTests
51- -- TODO: property tests should work for mutable backends too (?)
52- #ifndef MUTABLE_ARRAYS
53- , propertyTests
54- #endif
55- , invalidOperationTests
56- ] where
50+ [ caseTests, propertyTests , invalidOperationTests ] where
5751
5852 -- The case tests for the MakeArray function.
5953 -- Tests that arrays of size 0 and 1 have the proper size and elements.
6054 caseTests :: TestTree
6155 caseTests = testGroup " MakeArray Case Tests"
62- [ testEmptyArray
63- -- TODO: the below should work for mutable backends too (?)
64- #ifndef MUTABLE_ARRAYS
65- , testSizeOneArray
66- #endif
67- ]
56+ [ testEmptyArray, testSizeOneArray ]
6857 where
6958
7059 -- Testing the output of an empty array.
@@ -79,8 +68,11 @@ testMakeArray = testGroup "MakeArray Tests"
7968 QC. forAll QC. arbitrary $ \ (randomElement :: Int ) ->
8069 let customArr = CustomArray. makeArray 1 randomElement
8170 standardArr = makeStandardArray 1 randomElement
82- in CustomArray. size customArr QC. === 1 QC. .&. CustomArray. toList customArr QC. === StandardArray. elems standardArr
83-
71+ in CustomArray. size customArr QC. === 1
72+ -- The mutable backend doesn't initialize array elements, StandardArray(Data.Array) does
73+ #ifndef MUTABLE_ARRAYS
74+ QC. .&. CustomArray. toList customArr QC. === StandardArray. elems standardArr
75+ #endif
8476
8577 -- The property tests for the makeArray function.
8678 -- Tests that random arrays have proper size and elements.
@@ -94,7 +86,11 @@ testMakeArray = testGroup "MakeArray Tests"
9486 QC. forAll ((,) <$> QC. chooseInt (0 , mediumNumber) <*> QC. arbitrary) $ \ (randomSize :: Int , randomElement :: Int ) ->
9587 let customArr = CustomArray. makeArray randomSize randomElement
9688 standardArr = makeStandardArray randomSize randomElement
97- in CustomArray. size customArr QC. === randomSize QC. .&. CustomArray. toList customArr QC. === StandardArray. elems standardArr
89+ in CustomArray. size customArr QC. === randomSize
90+ -- The mutable backend doesn't initialize array elements, StandardArray(Data.Array) does
91+ #ifndef MUTABLE_ARRAYS
92+ QC. .&. CustomArray. toList customArr QC. === StandardArray. elems standardArr
93+ #endif
9894
9995 -- The tests for exception cases of the MakeArray functions.
10096 -- Tests that negative size arrays can't be made.
@@ -260,51 +256,53 @@ testSwap = testGroup "Swap Tests" [ caseTests, performanceTests, propertyTests ]
260256 , testValuesSwapped2
261257 , testValuesSwapped3
262258 , testValuesSwapped4
263- -- TODO: the below should work for mutable backends too
264- #ifndef MUTABLE_ARRAYS
259+ -- TODO: This should work for the primitive mutable backend
260+ #ifndef PRIM_MUTABLE_ARRAYS
265261 , testSwapSameIndex
266262#endif
267263 ] where
268264
269265 -- Testing if swapping two elements works correctly.
270266 testValuesSwapped1 :: TestTree
271267 testValuesSwapped1 = testCase " Test Values Swapped Manual" $ do
272- let arr = CustomArray. makeArray 5 ( 0 :: Int )
268+ let arr = CustomArray. makeArray @ Int 5 0
273269 let arr1 = CustomArray. set arr 0 1
274270 let arr2 = CustomArray. set arr1 1 2
275271 let swappedArr = CustomOperations. swap arr2 0 1
276272 assertEqual " First element should be 2" 2 (CustomArray. get swappedArr 0 )
277273 assertEqual " Second element should be 1" 1 (CustomArray. get swappedArr 1 )
278274
279275 -- Testing if swapping two elements works correctly.
280- testValuesSwapped2 = valueSwapTest 5 0 0 1 1 ( 2 :: Int )
281- testValuesSwapped3 = valueSwapTest 10 1 1 2 2 ( 4 :: Int )
282- testValuesSwapped4 = valueSwapTest 20 1 2 3 4 ( 5 :: Int )
276+ testValuesSwapped2 = valueSwapTest @ Int 5 0 0 1 1 2
277+ testValuesSwapped3 = valueSwapTest @ Int 10 1 1 2 2 4
278+ testValuesSwapped4 = valueSwapTest @ Int 20 1 2 3 4 5
283279
284280 -- Testing that swapping an element with itself doesn't change anything.
285281 testSwapSameIndex :: TestTree
286282 testSwapSameIndex = testCase " Test Swapping Same Index" $ do
287- let arr = CustomArray. makeArray 5 ( 1 :: Int )
288- let swappedArr = CustomOperations. swap arr 2 2
283+ let arr = CustomArray. makeArray @ Int 5 1
284+ swappedArr = CustomOperations. swap arr 2 2
289285 assertEqual " Array should remain unchanged" 1 (CustomArray. get swappedArr 2 )
290286
291287 -- Test performance for swap.
292288 performanceTests :: TestTree
293- performanceTests = testGroup " Swap Performance Tests" [ testLargeArraySwap ] where
289+ performanceTests = testGroup " Swap Performance Tests" [
290+ testLargeArraySwap
291+ ] where
294292 largeInt = 1000000 * performanceTestMultiplier
295293
296294 -- Test performance of creating and splitting a large.
297295 testLargeArraySwap :: TestTree
298296 testLargeArraySwap = testCase " Test Large Array Swap" $ do
299- let largeArr = CustomArray. makeArray largeInt ( 0 :: Int )
297+ let largeArr = CustomArray. makeArray @ Int largeInt 0
300298 let updatedArr = CustomArray. set largeArr (largeInt- 1 ) 1
301299 let swappedArr = CustomOperations. swap updatedArr (largeInt- 1 ) 0
302300 assertEqual " Last element should be 0" 0 (CustomArray. get swappedArr (largeInt- 1 ))
303301
304302 -- The property tests for the split function.
305303 propertyTests :: TestTree
306304 propertyTests = testGroup " Swap Property Tests" [
307- testSwapCommutative
305+ testSwapCommutative
308306 ] where
309307
310308 -- Generates random arrays to test that swap is commutative.
@@ -326,25 +324,24 @@ testSwap = testGroup "Swap Tests" [ caseTests, performanceTests, propertyTests ]
326324-- TODO: Missing performance and property tests.
327325--------------------------------------------------------------------------------
328326testSplit :: TestTree
329- testSplit = testGroup " Test Split" [ caseTests ] where
327+ testSplit = testGroup " Test Split" [
328+ caseTests
329+ ] where
330330
331331 -- The case tests for the split function.
332332 caseTests :: TestTree
333333 caseTests = testGroup " Split Case Tests" [
334- -- TODO: the below should work for mutable backends too
335- #ifndef MUTABLE_ARRAYS
336334 testSplitMid
337- ,
338- #endif
339- testSplitEmpty
335+ , testSplitEmpty
340336 ] where
341337
342338 -- Testing after splitting an array in the middle the sizes of the left and right are correct.
343339 -- and the contents of the left and right don't change.
344340 -- Hardcoded array size and values.
345341 testSplitMid :: TestTree
346342 testSplitMid = testCase " Test Split Mid" $ do
347- let arr = CustomArray. makeArray 6 (1 :: Int )
343+ let list = replicate @ Int 6 1
344+ arr = CustomArray. fromList list
348345 let (leftArr, rightArr) = CustomOperations. splitMid arr
349346 assertEqual " Left array size should be 3" 3 (CustomArray. size leftArr)
350347 assertEqual " Right array size should be 3" 3 (CustomArray. size rightArr)
@@ -356,7 +353,7 @@ testSplit = testGroup "Test Split" [ caseTests ] where
356353 -- Tests that splitting an empty array leads to two arrays of size 0.
357354 testSplitEmpty :: TestTree
358355 testSplitEmpty = testCase " Test Splitting Empty Array" $ do
359- let arr = CustomArray. makeArray 0 ( 0 :: Int )
356+ let arr = CustomArray. makeArray @ Int 0 0
360357 let (leftArr, rightArr) = CustomOperations. splitMid arr
361358 assertEqual " Left array size should be 0" 0 (CustomArray. size leftArr)
362359 assertEqual " Right array size should be 0" 0 (CustomArray. size rightArr)
0 commit comments