-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
-- SPDX-FileCopyrightText: Copyright Preetham Gujjula | ||
-- SPDX-License-Identifier: BSD-3-Clause | ||
module Test.Data.List.ApplyMerge (tests) where | ||
|
||
import Data.Complex (Complex ((:+))) | ||
import Data.List (sortOn) | ||
import Data.List.ApplyMerge (applyMergeOn) | ||
import Data.Ratio ((%)) | ||
import Test.ApplyMerge.Common (basicTest, blockTest, maxTest, skewedTest) | ||
import Test.Tasty (TestTree, testGroup) | ||
import Test.Tasty.HUnit (testCase, (@?=)) | ||
|
||
tests :: TestTree | ||
tests = | ||
testGroup | ||
"Data.List.ApplyMerge.applyMergeOn" | ||
[ basicTest (applyMergeOn id), | ||
skewedTest (applyMergeOn id), | ||
blockTest (applyMergeOn id), | ||
maxTest (applyMergeOn id), | ||
gaussianIntegerTest | ||
] | ||
|
||
gaussianIntegerTest :: TestTree | ||
gaussianIntegerTest = | ||
testCase "gaussian integers x + yi, with 0 <= x <= y, ordered by norm" $ do | ||
let actual = | ||
take 100 $ | ||
applyMergeOn | ||
(\x -> (norm x, slope x)) | ||
(\x k -> x :+ (x + k)) | ||
[0 ..] | ||
[0 ..] | ||
expected = | ||
take 100 $ | ||
filter (\(x :+ y) -> x <= y) $ | ||
sortOn | ||
(\x -> (norm x, slope x)) | ||
(liftA2 (:+) [0 .. 100] [0 .. 100]) | ||
Check failure on line 39 in test/Test/Data/List/ApplyMerge.hs GitHub Actions / cabal test - ghc-9.2.8
|
||
in actual @?= expected | ||
|
||
norm :: Complex Integer -> Integer | ||
norm (a :+ b) = a * a + b * b | ||
|
||
data Slope = Finite Rational | Infinity | ||
deriving (Eq, Show, Ord) | ||
|
||
slope :: Complex Integer -> Slope | ||
slope (x :+ y) = | ||
if x == 0 | ||
then Infinity | ||
else Finite (y % x) |