Skip to content

Commit 525ca98

Browse files
committed
fixed tests
1 parent 0adc84d commit 525ca98

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

test/Properties/DataView.purs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Test.Properties.DataView where
33

44
import Prelude
55

6+
import Data.Array.Partial (head) as Array
67
import Data.ArrayBuffer.DataView as DV
78
import Data.ArrayBuffer.DataView.Gen (genDataView, genWithOffsetAndValue, WithOffsetAndValue(..))
89
import Data.ArrayBuffer.Typed.Gen (genFloat32, genFloat64, genInt16, genInt32, genInt8, genUint16, genUint32, genUint8)
@@ -12,14 +13,15 @@ import Data.Maybe (Maybe(..))
1213
import Data.Typelevel.Num (class Nat, D1, D2, D4, D8)
1314
import Data.UInt (UInt)
1415
import Data.Float32 (Float32) as F
15-
import Data.Vec (head) as Vec
16+
-- import Data.Vec (head) as Vec
1617
import Data.Symbol (class IsSymbol)
1718
import Effect (Effect)
1819
import Effect.Console (log)
1920
import Effect.Ref (Ref)
2021
import Effect.Ref as Ref
2122
import Effect.Unsafe (unsafePerformEffect)
2223
import Test.QuickCheck (class Testable, quickCheckGen, Result, (===))
24+
import Partial.Unsafe (unsafePartial)
2325

2426

2527

@@ -102,7 +104,7 @@ placingAValueIsThereTests endian count = overAll count placingAValueIsThere
102104
where
103105
placingAValueIsThere :: forall a name b t. TestableViewF a name b D1 t Result
104106
placingAValueIsThere (WithOffsetAndValue os t xs) =
105-
let o = Vec.head os
107+
let o = unsafePartial $ Array.head os
106108
prx = DV.AProxy :: DV.AProxy a
107109
in unsafePerformEffect do
108110
_ <- DV.set endian prx xs o t

test/Properties/TypedArray.purs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ module Test.Properties.TypedArray where
44
import Prelude
55

66
import Control.Monad.Gen (suchThat)
7-
import Data.Array as Array
7+
import Data.Array (all, cons, drop, length, reverse, slice, snoc, sort, take, unsafeIndex) as Array
8+
import Data.Array.Partial (head) as Array
89
import Data.ArrayBuffer.Typed (class TypedArray)
910
import Data.ArrayBuffer.Typed as TA
1011
import Data.ArrayBuffer.Typed.Gen (WithIndices(..), genFloat32, genFloat64, genInt16, genInt32, genInt8, genTypedArray, genUint16, genUint32, genUint8, genWithIndices)
1112
import Data.ArrayBuffer.Types (ArrayView, Float32Array, Float64Array, Int16Array, Int32Array, Int8Array, Uint16Array, Uint8Array, Uint8ClampedArray, Uint32Array)
1213
import Data.ArrayBuffer.ValueMapping (class BytesPerValue)
1314
import Data.Maybe (Maybe(..), fromMaybe, isJust)
1415
import Data.Traversable (traverse)
15-
import Data.Typelevel.Num (class Nat, D0, D1, D2, D5, d0, d1, toInt')
16-
import Data.Vec (head, index) as Vec
16+
import Data.Typelevel.Num (class Nat, D0, D1, D2, D5, toInt')
17+
-- import Data.Vec (head, index) as Vec
1718
import Effect (Effect)
1819
import Effect.Console (log)
1920
import Effect.Ref (Ref)
2021
import Effect.Ref as Ref
2122
import Effect.Unsafe (unsafePerformEffect)
23+
import Partial.Unsafe (unsafePartial)
2224
import Test.QuickCheck (class Testable, Result(..), quickCheckGen, (/==), (<?>), (===))
2325
import Test.QuickCheck.Combinators ((==>), (|=|))
2426
import Test.QuickCheck.Gen (Gen)
@@ -155,8 +157,8 @@ subarrayBehavesLikeArraySliceTests count = overAll count f
155157
where
156158
f :: forall a b t. TestableArrayF a b D2 t Result
157159
f (WithIndices os xs) = do
158-
let s = os `Vec.index` d0
159-
e = os `Vec.index` d1
160+
let s = unsafePartial $ os `Array.unsafeIndex` 0
161+
e = unsafePartial $ os `Array.unsafeIndex` 1
160162
axs <- TA.toArray xs
161163
let sxs = TA.subArray s e xs
162164
a <- TA.toArray sxs
@@ -167,8 +169,8 @@ sliceBehavesLikeArraySliceTests count = overAll count f
167169
where
168170
f :: forall a b t. TestableArrayF a b D2 t Result
169171
f (WithIndices os xs) = do
170-
let s = os `Vec.index` d0
171-
e = os `Vec.index` d1
172+
let s = unsafePartial $ os `Array.unsafeIndex` 0
173+
e = unsafePartial $ os `Array.unsafeIndex` 1
172174
axs <- TA.toArray xs
173175
sxs <- TA.slice s e xs
174176
a <- TA.toArray sxs
@@ -224,12 +226,12 @@ setSingletonIsEqTests count = overAll count setSingletonIsEq
224226
setSingletonIsEq (WithIndices os xs) = do
225227
e <- TA.at xs 0
226228
case e of
227-
Nothing -> pure Success
228-
Just x -> do
229-
let o = Vec.head os
230-
_ <- TA.set xs (Just o) [x]
231-
e' <- TA.at xs o
232-
pure $ e' === Just x
229+
Nothing -> pure Success
230+
Just x -> do
231+
let o = unsafePartial $ Array.head os
232+
_ <- TA.set xs (Just o) [x]
233+
e' <- TA.at xs o
234+
pure $ e' === Just x
233235

234236

235237
-- | Should work with any arbitrary predicate, but we can't generate them
@@ -592,7 +594,7 @@ modifyingOriginalMutatesSubArrayPartTests count = overAll count modifyingOrigina
592594
where
593595
modifyingOriginalMutatesSubArrayPart :: forall a b t. TestableArrayF a b D1 t Result
594596
modifyingOriginalMutatesSubArrayPart (WithIndices os xs) = do
595-
let o = Vec.head os
597+
let o = unsafePartial $ Array.head os
596598
l = TA.length xs
597599
zsSub = TA.subArray 0 l xs
598600
zs <- TA.toArray zsSub
@@ -628,7 +630,7 @@ modifyingOriginalDoesntMutateSlicePartTests count = overAll count modifyingOrigi
628630
modifyingOriginalDoesntMutateSlicePart (WithIndices os xs) = do
629631
let l = TA.length xs
630632
axs <- TA.toArray =<< TA.slice 0 l xs
631-
let o = Vec.head os
633+
let o = unsafePartial $ Array.head os
632634
e <- TA.at xs o
633635
if Array.all (eq zero) axs || e == Just zero
634636
then pure Success
@@ -645,7 +647,7 @@ modifyingOriginalDoesntMutateSlicePart2Tests count = overAll count modifyingOrig
645647
where
646648
modifyingOriginalDoesntMutateSlicePart2 :: forall a b t. TestableArrayF a b D1 t Result
647649
modifyingOriginalDoesntMutateSlicePart2 (WithIndices os xs) = do
648-
let o = Vec.head os
650+
let o = unsafePartial $ Array.head os
649651
l = TA.length xs
650652
axs <- TA.toArray =<< TA.slice o l xs
651653
e <- TA.at xs o
@@ -675,7 +677,7 @@ copyWithinIsSliceTests count = overAll count copyWithinIsSlice
675677
where
676678
copyWithinIsSlice :: forall a b t. TestableArrayF a b D1 t Result
677679
copyWithinIsSlice (WithIndices os xs) = do
678-
let o = Vec.head os
680+
let o = unsafePartial $ Array.head os
679681
l = TA.length xs
680682
ys <- TA.toArray =<< TA.slice o l xs
681683
TA.copyWithin xs 0 o Nothing
@@ -689,7 +691,7 @@ copyWithinViaSetTypedTests count = overAll count copyWithinViaSetTyped
689691
where
690692
copyWithinViaSetTyped :: forall a b t. TestableArrayF a b D1 t Result
691693
copyWithinViaSetTyped (WithIndices os xs) = do
692-
let o = Vec.head os
694+
let o = unsafePartial $ Array.head os
693695
txs <- TA.toArray xs
694696
xs' <- TA.fromArray txs :: Effect (ArrayView a)
695697
let l = TA.length xs'

0 commit comments

Comments
 (0)