File: UniqueFactorisationTests.hs

package info (click to toggle)
haskell-arithmoi 0.13.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 964 kB
  • sloc: haskell: 10,379; makefile: 3
file content (47 lines) | stat: -rw-r--r-- 1,388 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
47
-- |
-- Module:      Math.NumberTheory.UniqueFactorisationTests
-- Copyright:   (c) 2016 Andrew Lelechenko
-- Licence:     MIT
-- Maintainer:  Andrew Lelechenko <andrew.lelechenko@gmail.com>
--
-- Tests for Math.NumberTheory.ArithmeticFunctions
--

{-# LANGUAGE ScopedTypeVariables #-}

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

module Math.NumberTheory.UniqueFactorisationTests
  ( testSuite
  ) where

import Test.Tasty

import Math.NumberTheory.Quadratic.EisensteinIntegers
import Math.NumberTheory.Quadratic.GaussianIntegers
import Math.NumberTheory.Primes
import Math.NumberTheory.TestUtils

import Numeric.Natural

testRules :: forall a. (UniqueFactorisation a, Num a, Eq a) => a -> Bool
testRules n
  = n == 0
  || all (\(p, _) -> unP p == abs (unP p)) fs
  && abs n == abs (product (map (\(p, k) -> unP p ^ k) fs))
  where
    fs = factorise n

    unP :: Prime a -> a
    unP = unPrime

testSuite :: TestTree
testSuite = testGroup "UniqueFactorisation"
  [ testSmallAndQuick "Int"     (testRules :: Int     -> Bool)
  , testSmallAndQuick "Word"    (testRules :: Word    -> Bool)
  , testSmallAndQuick "Integer" (testRules :: Integer -> Bool)
  , testSmallAndQuick "Natural" (testRules :: Natural -> Bool)

  , testSmallAndQuick "GaussianInteger"   (testRules :: GaussianInteger   -> Bool)
  , testSmallAndQuick "EisensteinInteger" (testRules :: EisensteinInteger -> Bool)
  ]