File: SingletonTests.hs

package info (click to toggle)
haskell-arithmoi 0.13.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 964 kB
  • sloc: haskell: 10,379; makefile: 3
file content (46 lines) | stat: -rw-r--r-- 1,267 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
-- |
-- Module:      Math.NumberTheory.Moduli.SingletonTests
-- Copyright:   (c) 2019 Andrew Lelechenko
-- Licence:     MIT
-- Maintainer:  Andrew Lelechenko <andrew.lelechenko@gmail.com>
--
-- Tests for Math.NumberTheory.Moduli.Singleton
--

{-# LANGUAGE TypeApplications #-}

{-# OPTIONS_GHC -fno-warn-type-defaults #-}

module Math.NumberTheory.Moduli.SingletonTests
  ( testSuite
  ) where

import Test.Tasty

import qualified Data.Map as M

import Math.NumberTheory.Moduli.Singleton
import Math.NumberTheory.Primes
import Math.NumberTheory.TestUtils

someSFactorsProperty1
  :: (Ord a, Num a)
  => [(Prime a, Word)]
  -> Bool
someSFactorsProperty1 xs = case someSFactors xs of
  Some sm -> unSFactors sm == M.assocs (M.fromListWith (+) xs)

cyclicGroupFromModuloProperty1
  :: (Integral a, UniqueFactorisation a)
  => Positive a
  -> Bool
cyclicGroupFromModuloProperty1 (Positive m) = mcg1 == mcg2
  where
    mcg1 = cyclicGroupFromModulo m
    mcg2 = cyclicGroupFromFactors (factorise m)

testSuite :: TestTree
testSuite = testGroup "Singleton"
  [ testSmallAndQuick "unSFactors . someSFactors = id" (someSFactorsProperty1 @Integer)
  , testIntegralPropertyNoLarge "cyclicGroupFromModulo = cyclicGroupFromFactors . factorise" cyclicGroupFromModuloProperty1
  ]