Skip to content

Commit 766b7f4

Browse files
committed
Fix groupBy tests
\x y -> odd x && odd y is not an equivalence relation! It doesn't satisfy reflexivity.
1 parent 60fe96a commit 766b7f4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

test/Test/Data/Array.purs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ testArray = do
285285
assert $ A.group' [1, 2, 2, 3, 3, 3, 1] == [1 :| [1], 2 :| [2], 3 :| [3, 3]]
286286

287287
log "groupBy should group consecutive equal elements into arrays based on an equivalence relation"
288-
assert $ A.groupBy (\x y -> odd x && odd y) [1, 1, 2, 2, 3, 5] == [1 :| [1], NE.singleton 2, NE.singleton 2, 3 :| [5]]
288+
assert $ A.groupBy eqParity [1, 1, 2, 2, 3, 5, 4] == [1 :| [1], 2 :| [2], 3 :| [5], NE.singleton 4]
289289

290290
log "nub should remove duplicate elements from the list, keeping the first occurence"
291291
assert $ A.nub [1, 2, 2, 3, 4, 1] == [1, 2, 3, 4]
@@ -365,6 +365,11 @@ odd n = n `mod` 2 /= zero
365365
doubleAndOrig :: Int -> Array Int
366366
doubleAndOrig x = [x * 2, x]
367367

368+
-- | An equivalence relation on integers. This relation splits the integers
369+
-- | into two equivalence classes: odds and evens.
370+
eqParity :: Int -> Int -> Boolean
371+
eqParity x y = x `mod` 2 == y `mod` 2
372+
368373
data Replicated a = Replicated Int a
369374

370375
instance foldableReplicated :: Foldable Replicated where

0 commit comments

Comments
 (0)