{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ViewPatterns #-}
module Evaluation.Builtins.Integer.RingProperties
( test_integer_ring_properties
, integer_ring_property_names
, generate_integer_ring_properties
)
where
import Evaluation.Builtins.Common
import Evaluation.Builtins.Integer.Common
import Evaluation.Builtins.Integer.Conformance
import Evaluation.Builtins.Conformance (CheckMode, OutputFormat, PropertyFilter, PropertyId (..))
import Test.QuickCheck.Random (QCGen)
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.QuickCheck
prop_addition_associative :: BigInteger -> BigInteger -> BigInteger -> Check
prop_addition_associative :: BigInteger -> BigInteger -> BigInteger -> Check
prop_addition_associative (BigInteger -> PlcTerm
biginteger -> PlcTerm
a) (BigInteger -> PlcTerm
biginteger -> PlcTerm
b) (BigInteger -> PlcTerm
biginteger -> PlcTerm
c) =
let t1 :: PlcTerm
t1 = PlcTerm -> PlcTerm -> PlcTerm
addInteger PlcTerm
a (PlcTerm -> PlcTerm -> PlcTerm
addInteger PlcTerm
b PlcTerm
c)
t2 :: PlcTerm
t2 = PlcTerm -> PlcTerm -> PlcTerm
addInteger (PlcTerm -> PlcTerm -> PlcTerm
addInteger PlcTerm
a PlcTerm
b) PlcTerm
c
in PlcTerm -> PlcTerm -> Check
CheckEq PlcTerm
t1 PlcTerm
t2
prop_addition_commutative :: BigInteger -> BigInteger -> Check
prop_addition_commutative :: BigInteger -> BigInteger -> Check
prop_addition_commutative (BigInteger -> PlcTerm
biginteger -> PlcTerm
a) (BigInteger -> PlcTerm
biginteger -> PlcTerm
b) =
PlcTerm -> PlcTerm -> Check
CheckEq (PlcTerm -> PlcTerm -> PlcTerm
addInteger PlcTerm
a PlcTerm
b) (PlcTerm -> PlcTerm -> PlcTerm
addInteger PlcTerm
b PlcTerm
a)
prop_zero_additive_identity :: BigInteger -> Check
prop_zero_additive_identity :: BigInteger -> Check
prop_zero_additive_identity (BigInteger -> PlcTerm
biginteger -> PlcTerm
a) =
PlcTerm -> PlcTerm -> Check
CheckEq (PlcTerm -> PlcTerm -> PlcTerm
addInteger PlcTerm
a PlcTerm
zero) PlcTerm
a
prop_add_subtract_inverse :: BigInteger -> BigInteger -> Check
prop_add_subtract_inverse :: BigInteger -> BigInteger -> Check
prop_add_subtract_inverse (BigInteger -> PlcTerm
biginteger -> PlcTerm
a) (BigInteger -> PlcTerm
biginteger -> PlcTerm
b) =
PlcTerm -> PlcTerm -> Check
CheckEq (PlcTerm -> PlcTerm -> PlcTerm
subtractInteger (PlcTerm -> PlcTerm -> PlcTerm
addInteger PlcTerm
a PlcTerm
b) PlcTerm
b) PlcTerm
a
prop_multiplication_associative
:: BigInteger -> BigInteger -> BigInteger -> Check
prop_multiplication_associative :: BigInteger -> BigInteger -> BigInteger -> Check
prop_multiplication_associative (BigInteger -> PlcTerm
biginteger -> PlcTerm
a) (BigInteger -> PlcTerm
biginteger -> PlcTerm
b) (BigInteger -> PlcTerm
biginteger -> PlcTerm
c) =
let t1 :: PlcTerm
t1 = PlcTerm -> PlcTerm -> PlcTerm
multiplyInteger PlcTerm
a (PlcTerm -> PlcTerm -> PlcTerm
multiplyInteger PlcTerm
b PlcTerm
c)
t2 :: PlcTerm
t2 = PlcTerm -> PlcTerm -> PlcTerm
multiplyInteger (PlcTerm -> PlcTerm -> PlcTerm
multiplyInteger PlcTerm
a PlcTerm
b) PlcTerm
c
in PlcTerm -> PlcTerm -> Check
CheckEq PlcTerm
t1 PlcTerm
t2
prop_multiplication_commutative :: BigInteger -> BigInteger -> Check
prop_multiplication_commutative :: BigInteger -> BigInteger -> Check
prop_multiplication_commutative (BigInteger -> PlcTerm
biginteger -> PlcTerm
a) (BigInteger -> PlcTerm
biginteger -> PlcTerm
b) =
let t1 :: PlcTerm
t1 = PlcTerm -> PlcTerm -> PlcTerm
multiplyInteger PlcTerm
a PlcTerm
b
t2 :: PlcTerm
t2 = PlcTerm -> PlcTerm -> PlcTerm
multiplyInteger PlcTerm
b PlcTerm
a
in PlcTerm -> PlcTerm -> Check
CheckEq PlcTerm
t1 PlcTerm
t2
prop_one_multiplicative_identity :: BigInteger -> Check
prop_one_multiplicative_identity :: BigInteger -> Check
prop_one_multiplicative_identity (BigInteger -> PlcTerm
biginteger -> PlcTerm
a) =
let t :: PlcTerm
t = PlcTerm -> PlcTerm -> PlcTerm
multiplyInteger PlcTerm
a PlcTerm
one
in PlcTerm -> PlcTerm -> Check
CheckEq PlcTerm
t PlcTerm
a
prop_distributive :: BigInteger -> BigInteger -> BigInteger -> Check
prop_distributive :: BigInteger -> BigInteger -> BigInteger -> Check
prop_distributive (BigInteger -> PlcTerm
biginteger -> PlcTerm
a) (BigInteger -> PlcTerm
biginteger -> PlcTerm
b) (BigInteger -> PlcTerm
biginteger -> PlcTerm
c) =
let t1 :: PlcTerm
t1 = PlcTerm -> PlcTerm -> PlcTerm
multiplyInteger PlcTerm
a (PlcTerm -> PlcTerm -> PlcTerm
addInteger PlcTerm
b PlcTerm
c)
t2 :: PlcTerm
t2 = PlcTerm -> PlcTerm -> PlcTerm
addInteger (PlcTerm -> PlcTerm -> PlcTerm
multiplyInteger PlcTerm
a PlcTerm
b) (PlcTerm -> PlcTerm -> PlcTerm
multiplyInteger PlcTerm
a PlcTerm
c)
in PlcTerm -> PlcTerm -> Check
CheckEq PlcTerm
t1 PlcTerm
t2
test_integer_ring_properties :: TestTree
test_integer_ring_properties :: TestTree
test_integer_ring_properties =
TestName -> [TestTree] -> TestTree
testGroup TestName
"Ring properties for integer arithmetic builtins" ([TestTree] -> TestTree) -> [TestTree] -> TestTree
forall a b. (a -> b) -> a -> b
$
(Property -> Property) -> [PropertySpec (Gen Check)] -> [TestTree]
testPropertySpecs Property -> Property
forall a. a -> a
id [PropertySpec (Gen Check)]
integerRingProperties
integerRingProperties :: [PropertySpec (Gen Check)]
integerRingProperties :: [PropertySpec (Gen Check)]
integerRingProperties =
[ TestName
-> TestName
-> (BigInteger -> BigInteger -> BigInteger -> Check)
-> PropertySpec (Gen Check)
forall prop.
GenerateCases prop =>
TestName -> TestName -> prop -> PropertySpec (Gen Check)
propertySpec TestName
"addition_associative" TestName
"addInteger is associative" BigInteger -> BigInteger -> BigInteger -> Check
prop_addition_associative
, TestName
-> TestName
-> (BigInteger -> BigInteger -> Check)
-> PropertySpec (Gen Check)
forall prop.
GenerateCases prop =>
TestName -> TestName -> prop -> PropertySpec (Gen Check)
propertySpec TestName
"addition_commutative" TestName
"addInteger is commutative" BigInteger -> BigInteger -> Check
prop_addition_commutative
, TestName
-> TestName -> (BigInteger -> Check) -> PropertySpec (Gen Check)
forall prop.
GenerateCases prop =>
TestName -> TestName -> prop -> PropertySpec (Gen Check)
propertySpec
TestName
"zero_additive_identity"
TestName
"0 is an identity element for addInteger"
BigInteger -> Check
prop_zero_additive_identity
, TestName
-> TestName
-> (BigInteger -> BigInteger -> Check)
-> PropertySpec (Gen Check)
forall prop.
GenerateCases prop =>
TestName -> TestName -> prop -> PropertySpec (Gen Check)
propertySpec
TestName
"add_subtract_inverse"
TestName
"subtraction is the inverse of addition"
BigInteger -> BigInteger -> Check
prop_add_subtract_inverse
, TestName
-> TestName
-> (BigInteger -> BigInteger -> BigInteger -> Check)
-> PropertySpec (Gen Check)
forall prop.
GenerateCases prop =>
TestName -> TestName -> prop -> PropertySpec (Gen Check)
propertySpec
TestName
"multiplication_associative"
TestName
"multiplyInteger is associative"
BigInteger -> BigInteger -> BigInteger -> Check
prop_multiplication_associative
, TestName
-> TestName
-> (BigInteger -> BigInteger -> Check)
-> PropertySpec (Gen Check)
forall prop.
GenerateCases prop =>
TestName -> TestName -> prop -> PropertySpec (Gen Check)
propertySpec
TestName
"multiplication_commutative"
TestName
"multiplyInteger is commutative"
BigInteger -> BigInteger -> Check
prop_multiplication_commutative
, TestName
-> TestName -> (BigInteger -> Check) -> PropertySpec (Gen Check)
forall prop.
GenerateCases prop =>
TestName -> TestName -> prop -> PropertySpec (Gen Check)
propertySpec
TestName
"one_multiplicative_identity"
TestName
"1 is a multiplicative identity"
BigInteger -> Check
prop_one_multiplicative_identity
, TestName
-> TestName
-> (BigInteger -> BigInteger -> BigInteger -> Check)
-> PropertySpec (Gen Check)
forall prop.
GenerateCases prop =>
TestName -> TestName -> prop -> PropertySpec (Gen Check)
propertySpec TestName
"distributive" TestName
"multiplyInteger distributes over addInteger" BigInteger -> BigInteger -> BigInteger -> Check
prop_distributive
]
generate_integer_ring_properties
:: OutputFormat -> CheckMode -> PropertyFilter -> FilePath -> Int -> QCGen -> IO [PropertyReport]
generate_integer_ring_properties :: OutputFormat
-> CheckMode
-> PropertyFilter
-> TestName
-> Int
-> QCGen
-> IO [PropertyReport]
generate_integer_ring_properties OutputFormat
format CheckMode
mode PropertyFilter
include TestName
outputDir Int
numFiles QCGen
seed =
OutputFormat
-> CheckMode
-> PropertyFilter
-> TestName
-> Int
-> QCGen
-> [TestName]
-> [PropertySpec (Gen Check)]
-> IO [PropertyReport]
generatePropertySpecs
OutputFormat
format
CheckMode
mode
PropertyFilter
include
TestName
outputDir
Int
numFiles
QCGen
seed
[TestName]
conformanceSuiteDirectory
[PropertySpec (Gen Check)]
integerRingProperties
integer_ring_property_names :: [PropertyId]
integer_ring_property_names :: [PropertyId]
integer_ring_property_names =
[TestName] -> [PropertySpec (Gen Check)] -> [PropertyId]
forall gen. [TestName] -> [PropertySpec gen] -> [PropertyId]
propertySpecPropertyIds [TestName]
conformanceSuiteDirectory [PropertySpec (Gen Check)]
integerRingProperties
conformanceSuiteDirectory :: [String]
conformanceSuiteDirectory :: [TestName]
conformanceSuiteDirectory = [TestName
"integer", TestName
"RingProperties"]