{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module IntervalAlgebra.RelationProperties where
import Data.Maybe (fromJust, isJust, isNothing)
import Data.Set (Set, disjointUnion,
fromList, member)
import Data.Time as DT (Day, NominalDiffTime,
UTCTime)
import IntervalAlgebra.Arbitrary
import IntervalAlgebra.Core
import IntervalAlgebra.IntervalUtilities ((.+.))
import Test.QuickCheck (Arbitrary (arbitrary),
Property, (===), (==>))
allIArelations :: (SizedIv (Interval a), Ord a) => [ComparativePredicateOf1 (Interval a)]
allIArelations :: [ComparativePredicateOf1 (Interval a)]
allIArelations =
[ ComparativePredicateOf1 (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
equals
, ComparativePredicateOf1 (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
meets
, ComparativePredicateOf1 (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
metBy
, ComparativePredicateOf1 (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
before
, ComparativePredicateOf1 (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
after
, ComparativePredicateOf1 (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
starts
, ComparativePredicateOf1 (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
startedBy
, ComparativePredicateOf1 (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
finishes
, ComparativePredicateOf1 (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
finishedBy
, ComparativePredicateOf1 (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
overlaps
, ComparativePredicateOf1 (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
overlappedBy
, ComparativePredicateOf1 (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
during
, ComparativePredicateOf1 (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
contains
]
prop_exclusiveRelations:: (SizedIv (Interval a), Ord a) => Interval a -> Interval a -> Property
prop_exclusiveRelations :: Interval a -> Interval a -> Property
prop_exclusiveRelations Interval a
x Interval a
y =
( Int
1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== [Bool] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ((Bool -> Bool) -> [Bool] -> [Bool]
forall a. (a -> Bool) -> [a] -> [a]
filter Bool -> Bool
forall a. a -> a
id ([Bool] -> [Bool]) -> [Bool] -> [Bool]
forall a b. (a -> b) -> a -> b
$ ((Interval a -> Interval a -> Bool) -> Bool)
-> [Interval a -> Interval a -> Bool] -> [Bool]
forall a b. (a -> b) -> [a] -> [b]
map (\Interval a -> Interval a -> Bool
r -> Interval a -> Interval a -> Bool
r Interval a
x Interval a
y) [Interval a -> Interval a -> Bool]
forall a.
(SizedIv (Interval a), Ord a) =>
[ComparativePredicateOf1 (Interval a)]
allIArelations)) Bool -> Bool -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Bool
True
prop_predicate_unions :: (SizedIv (Interval a), Ord a) =>
Set IntervalRelation
-> ComparativePredicateOf2 (Interval a) (Interval a)
-> Interval a
-> Interval a
-> Property
prop_predicate_unions :: Set IntervalRelation
-> ComparativePredicateOf2 (Interval a) (Interval a)
-> Interval a
-> Interval a
-> Property
prop_predicate_unions Set IntervalRelation
s ComparativePredicateOf2 (Interval a) (Interval a)
pred Interval a
i0 Interval a
i1 =
ComparativePredicateOf2 (Interval a) (Interval a)
pred Interval a
i0 Interval a
i1 Bool -> Bool -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Interval a -> Interval a -> IntervalRelation
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
i0 a -> i1 a -> IntervalRelation
relate Interval a
i0 Interval a
i1 IntervalRelation -> Set IntervalRelation -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` Set IntervalRelation
s)
prop_IAbefore :: forall a. (SizedIv (Interval a), Ord a, Ord (Moment (Interval a))) => Interval a -> Interval a -> Property
prop_IAbefore :: Interval a -> Interval a -> Property
prop_IAbefore Interval a
i Interval a
j =
ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
before Interval a
i Interval a
j Bool -> Bool -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> (Interval a
i ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
`meets` Interval a
k) Bool -> Bool -> Bool
&& (Interval a
k ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
`meets` Interval a
j)
where k :: Interval a
k = (a, a) -> Interval a
forall a.
(SizedIv (Interval a), Ord (Moment (Interval a))) =>
(a, a) -> Interval a
safeInterval (Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
end Interval a
i, Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
begin Interval a
j)
prop_IAstarts:: (SizedIv (Interval a), Ord a, Ord (Moment (Interval a))) => Interval a -> Interval a -> Property
prop_IAstarts :: Interval a -> Interval a -> Property
prop_IAstarts Interval a
i Interval a
j
| ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
starts Interval a
i Interval a
j = (Interval a
j ComparativePredicateOf2 (Interval a) (Interval a)
forall a. Eq a => a -> a -> Bool
== Maybe (Interval a) -> Interval a
forall a. HasCallStack => Maybe a -> a
fromJust (Interval a
i Interval a -> Interval a -> Maybe (Interval a)
forall a (i :: * -> *).
(Iv (Interval a), Ord (Moment (Interval a)), SizedIv (Interval a),
Intervallic i) =>
i a -> i a -> Maybe (Interval a)
.+. Interval a
k)) Bool -> Bool -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Bool
True
| Bool
otherwise = ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
starts Interval a
i Interval a
j Bool -> Bool -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Bool
False
where k :: Interval a
k = (a, a) -> Interval a
forall a.
(SizedIv (Interval a), Ord (Moment (Interval a))) =>
(a, a) -> Interval a
safeInterval (Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
end Interval a
i, Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
end Interval a
j)
prop_IAfinishes:: (SizedIv (Interval a), Ord a, Ord (Moment (Interval a))) => Interval a -> Interval a -> Property
prop_IAfinishes :: Interval a -> Interval a -> Property
prop_IAfinishes Interval a
i Interval a
j
| ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
finishes Interval a
i Interval a
j = (Interval a
j ComparativePredicateOf2 (Interval a) (Interval a)
forall a. Eq a => a -> a -> Bool
== Maybe (Interval a) -> Interval a
forall a. HasCallStack => Maybe a -> a
fromJust ( Interval a
k Interval a -> Interval a -> Maybe (Interval a)
forall a (i :: * -> *).
(Iv (Interval a), Ord (Moment (Interval a)), SizedIv (Interval a),
Intervallic i) =>
i a -> i a -> Maybe (Interval a)
.+. Interval a
i)) Bool -> Bool -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Bool
True
| Bool
otherwise = ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
finishes Interval a
i Interval a
j Bool -> Bool -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Bool
False
where k :: Interval a
k = (a, a) -> Interval a
forall a.
(SizedIv (Interval a), Ord (Moment (Interval a))) =>
(a, a) -> Interval a
safeInterval (Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
begin Interval a
j, Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
begin Interval a
i)
prop_IAoverlaps:: forall a. (SizedIv (Interval a), Ord a, Ord (Moment (Interval a))) => Interval a -> Interval a -> Property
prop_IAoverlaps :: Interval a -> Interval a -> Property
prop_IAoverlaps Interval a
i Interval a
j
| ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
overlaps Interval a
i Interval a
j = ((Interval a
i ComparativePredicateOf2 (Interval a) (Interval a)
forall a. Eq a => a -> a -> Bool
== Maybe (Interval a) -> Interval a
forall a. HasCallStack => Maybe a -> a
fromJust ( Interval a
k Interval a -> Interval a -> Maybe (Interval a)
forall a (i :: * -> *).
(Iv (Interval a), Ord (Moment (Interval a)), SizedIv (Interval a),
Intervallic i) =>
i a -> i a -> Maybe (Interval a)
.+. Interval a
l )) Bool -> Bool -> Bool
&&
(Interval a
j ComparativePredicateOf2 (Interval a) (Interval a)
forall a. Eq a => a -> a -> Bool
== Maybe (Interval a) -> Interval a
forall a. HasCallStack => Maybe a -> a
fromJust ( Interval a
l Interval a -> Interval a -> Maybe (Interval a)
forall a (i :: * -> *).
(Iv (Interval a), Ord (Moment (Interval a)), SizedIv (Interval a),
Intervallic i) =>
i a -> i a -> Maybe (Interval a)
.+. Interval a
m ))) Bool -> Bool -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Bool
True
| Bool
otherwise = ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
overlaps Interval a
i Interval a
j Bool -> Bool -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Bool
False
where k :: Interval a
k = (a, a) -> Interval a
forall a.
(SizedIv (Interval a), Ord (Moment (Interval a))) =>
(a, a) -> Interval a
safeInterval (Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
begin Interval a
i, Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
begin Interval a
j)
l :: Interval a
l = (a, a) -> Interval a
forall a.
(SizedIv (Interval a), Ord (Moment (Interval a))) =>
(a, a) -> Interval a
safeInterval (Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
begin Interval a
j, Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
end Interval a
i)
m :: Interval a
m = (a, a) -> Interval a
forall a.
(SizedIv (Interval a), Ord (Moment (Interval a))) =>
(a, a) -> Interval a
safeInterval (Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
end Interval a
i, Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
end Interval a
j)
prop_IAduring:: forall a. (SizedIv (Interval a), Ord a, Ord (Moment (Interval a))) => Interval a -> Interval a-> Property
prop_IAduring :: Interval a -> Interval a -> Property
prop_IAduring Interval a
i Interval a
j
| ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
during Interval a
i Interval a
j = (Interval a
j ComparativePredicateOf2 (Interval a) (Interval a)
forall a. Eq a => a -> a -> Bool
== Maybe (Interval a) -> Interval a
forall a. HasCallStack => Maybe a -> a
fromJust ( Maybe (Interval a) -> Interval a
forall a. HasCallStack => Maybe a -> a
fromJust (Interval a
k Interval a -> Interval a -> Maybe (Interval a)
forall a (i :: * -> *).
(Iv (Interval a), Ord (Moment (Interval a)), SizedIv (Interval a),
Intervallic i) =>
i a -> i a -> Maybe (Interval a)
.+. Interval a
i) Interval a -> Interval a -> Maybe (Interval a)
forall a (i :: * -> *).
(Iv (Interval a), Ord (Moment (Interval a)), SizedIv (Interval a),
Intervallic i) =>
i a -> i a -> Maybe (Interval a)
.+. Interval a
l)) Bool -> Bool -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Bool
True
| Bool
otherwise = ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(Iv (Interval a), Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
during Interval a
i Interval a
j Bool -> Bool -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Bool
False
where k :: Interval a
k = (a, a) -> Interval a
forall a.
(SizedIv (Interval a), Ord (Moment (Interval a))) =>
(a, a) -> Interval a
safeInterval (Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
begin Interval a
j, Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
begin Interval a
i)
l :: Interval a
l = (a, a) -> Interval a
forall a.
(SizedIv (Interval a), Ord (Moment (Interval a))) =>
(a, a) -> Interval a
safeInterval (Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
end Interval a
i, Interval a -> a
forall (i :: * -> *) a.
(SizedIv (Interval a), Intervallic i) =>
i a -> a
end Interval a
j)
prop_disjoint_predicate :: (SizedIv (Interval a), Ord a) =>
Interval a
-> Interval a
-> Property
prop_disjoint_predicate :: Interval a -> Interval a -> Property
prop_disjoint_predicate = Set IntervalRelation
-> ComparativePredicateOf2 (Interval a) (Interval a)
-> Interval a
-> Interval a
-> Property
forall a.
(SizedIv (Interval a), Ord a) =>
Set IntervalRelation
-> ComparativePredicateOf2 (Interval a) (Interval a)
-> Interval a
-> Interval a
-> Property
prop_predicate_unions Set IntervalRelation
disjointRelations ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(SizedIv (Interval a), Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
disjoint
prop_notdisjoint_predicate :: (SizedIv (Interval a), Ord a) =>
Interval a
-> Interval a
-> Property
prop_notdisjoint_predicate :: Interval a -> Interval a -> Property
prop_notdisjoint_predicate =
Set IntervalRelation
-> ComparativePredicateOf2 (Interval a) (Interval a)
-> Interval a
-> Interval a
-> Property
forall a.
(SizedIv (Interval a), Ord a) =>
Set IntervalRelation
-> ComparativePredicateOf2 (Interval a) (Interval a)
-> Interval a
-> Interval a
-> Property
prop_predicate_unions (Set IntervalRelation -> Set IntervalRelation
complement Set IntervalRelation
disjointRelations) ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(SizedIv (Interval a), Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
notDisjoint
prop_concur_predicate :: (SizedIv (Interval a), Ord a) =>
Interval a
-> Interval a
-> Property
prop_concur_predicate :: Interval a -> Interval a -> Property
prop_concur_predicate =
Set IntervalRelation
-> ComparativePredicateOf2 (Interval a) (Interval a)
-> Interval a
-> Interval a
-> Property
forall a.
(SizedIv (Interval a), Ord a) =>
Set IntervalRelation
-> ComparativePredicateOf2 (Interval a) (Interval a)
-> Interval a
-> Interval a
-> Property
prop_predicate_unions (Set IntervalRelation -> Set IntervalRelation
complement Set IntervalRelation
disjointRelations) ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(SizedIv (Interval a), Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
concur
prop_within_predicate :: (SizedIv (Interval a), Ord a) =>
Interval a
-> Interval a
-> Property
prop_within_predicate :: Interval a -> Interval a -> Property
prop_within_predicate = Set IntervalRelation
-> ComparativePredicateOf2 (Interval a) (Interval a)
-> Interval a
-> Interval a
-> Property
forall a.
(SizedIv (Interval a), Ord a) =>
Set IntervalRelation
-> ComparativePredicateOf2 (Interval a) (Interval a)
-> Interval a
-> Interval a
-> Property
prop_predicate_unions Set IntervalRelation
withinRelations ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(SizedIv (Interval a), Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
within
prop_enclosedBy_predicate :: (SizedIv (Interval a), Ord a) =>
Interval a
-> Interval a
-> Property
prop_enclosedBy_predicate :: Interval a -> Interval a -> Property
prop_enclosedBy_predicate = Set IntervalRelation
-> ComparativePredicateOf2 (Interval a) (Interval a)
-> Interval a
-> Interval a
-> Property
forall a.
(SizedIv (Interval a), Ord a) =>
Set IntervalRelation
-> ComparativePredicateOf2 (Interval a) (Interval a)
-> Interval a
-> Interval a
-> Property
prop_predicate_unions Set IntervalRelation
withinRelations ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(SizedIv (Interval a), Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
enclosedBy
prop_encloses_predicate :: (SizedIv (Interval a), Ord a) =>
Interval a
-> Interval a
-> Property
prop_encloses_predicate :: Interval a -> Interval a -> Property
prop_encloses_predicate = Set IntervalRelation
-> ComparativePredicateOf2 (Interval a) (Interval a)
-> Interval a
-> Interval a
-> Property
forall a.
(SizedIv (Interval a), Ord a) =>
Set IntervalRelation
-> ComparativePredicateOf2 (Interval a) (Interval a)
-> Interval a
-> Interval a
-> Property
prop_predicate_unions (Set IntervalRelation -> Set IntervalRelation
converse Set IntervalRelation
withinRelations) ComparativePredicateOf2 (Interval a) (Interval a)
forall a (i0 :: * -> *) (i1 :: * -> *).
(SizedIv (Interval a), Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
encloses