packages feed

interval-algebra 0.9.0 → 0.10.0

raw patch · 6 files changed

+61/−3 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ IntervalAlgebra: diffFromBegin :: (IntervalSizeable a b, Functor i1, Intervallic i0 a) => i0 a -> i1 a -> i1 b
+ IntervalAlgebra: diffFromEnd :: (IntervalSizeable a b, Functor i1, Intervallic i0 a) => i0 a -> i1 a -> i1 b
+ IntervalAlgebra.PairedInterval: instance GHC.Base.Functor (IntervalAlgebra.PairedInterval.PairedInterval b)

Files

ChangeLog.md view
@@ -1,5 +1,14 @@ # Changelog for interval-algebra +## 0.10.0++* Adds `diffFromBegin` (`diffFromEnd`) functions (not totally satisfied with these names) which change the reference point of the interval in the second argument by the difference from the `begin` (`end`) of the interval in the first argument.+* Adds a `Functor` instance for `PairedInterval b`s, which maps an `PairedInterval c a` to `PairedInterval c b`. That is, `fmap` acts on the interval type.++## 0.9.0++* Fixes bug in `gapsWithin` introduced in last version.+ ## 0.8.6  * Adds the `beginervalFromEnd` and `endervalFromBegin` utilities to create an interval of the provided duration from the end (respectively, begin) of another interval.
interval-algebra.cabal view
@@ -1,6 +1,6 @@ cabal-version:  2.2 name:           interval-algebra-version:        0.9.0+version:        0.10.0 synopsis:       An implementation of Allen's interval algebra for temporal logic description:    Please see the README on GitHub at <https://github.com/novisci/interval-algebra> category:       Algebra,Time
src/IntervalAlgebra.hs view
@@ -157,6 +157,8 @@     , ComparativePredicateOf2     , beginervalFromEnd     , endervalFromBegin+    , diffFromBegin+    , diffFromEnd      -- ** Algebraic operations     , intervalRelations@@ -634,7 +636,6 @@      -> Interval a endervalFromBegin d i = enderval d (begin i) - -- | Creates a new @Interval@ spanning the extent x and y. -- -- >>> extenterval (Interval (0, 1)) (Interval (9, 10))@@ -644,6 +645,22 @@ extenterval x y = Interval (s, e)     where s = min (begin x) (begin y)           e = max (end x) (end y)++-- | Modifies the endpoints of second argument's interval by taking the difference+--   from the first's input's 'begin'. +diffFromBegin :: ( IntervalSizeable a b+                 , Functor i1+                 , Intervallic i0 a ) => +    i0 a -> i1 a -> i1 b+diffFromBegin i = fmap (`diff` begin i)++-- | Modifies the endpoints of second argument's interval by taking the difference+--   from the first's input's 'end'. +diffFromEnd :: ( IntervalSizeable a b+               , Functor i1+               , Intervallic i0 a ) => +    i0 a -> i1 a -> i1 b+diffFromEnd i = fmap (`diff` end i)  {- | The @'IntervalCombinable'@ typeclass provides methods for (possibly) combining
src/IntervalAlgebra/PairedInterval.hs view
@@ -39,6 +39,9 @@     getInterval (PairedInterval x)        = fst x     setInterval (PairedInterval (x, y)) i = PairedInterval (i, y) +instance Functor (PairedInterval b) where+    fmap f (PairedInterval (x, y)) = PairedInterval (fmap f x, y)+ instance Bifunctor PairedInterval where     bimap f g (PairedInterval (x, y)) = PairedInterval (fmap g x, f y) 
test/IntervalAlgebra/PairedIntervalSpec.hs view
@@ -34,7 +34,10 @@   describe "Basic tests of paired intervals" $     do      it "the same pairInterval should be equal" $ t1 == t1 `shouldBe` True -    it "different pairInterval should not be equal" $ t1 /= t2 `shouldBe` True  +    it "different pairInterval should not be equal" $ t1 /= t2 `shouldBe` True+    it "fmapping into a different interval type" $ +        fmap ModifiedJulianDay (makePairedInterval "hi" (beginerval 5 0))+            `shouldBe` makePairedInterval "hi" (beginerval 5 (fromGregorian 1858 11 17))      it "bimapping into a different type" $          bimap (== "hi") ModifiedJulianDay (makePairedInterval "hi" (beginerval 5 0))             `shouldBe `makePairedInterval True (beginerval 5 (fromGregorian 1858 11 17))
test/IntervalAlgebraSpec.hs view
@@ -58,6 +58,8 @@                                   , union                                   , intersection                                   , complement+                                  , diffFromBegin+                                  , diffFromEnd                                   , IntervalCombinable((.+.))                                   , IntervalSizeable(moment, moment', diff)                                   , ComparativePredicateOf1@@ -630,6 +632,30 @@         Right (enderval (0::Int) 10) `shouldBe` parseInterval (9::Int) (10::Int)       it "enderval -2 10 should be Interval (9, 10)" $         Right (enderval (-2::Int) 10) `shouldBe` parseInterval (9::Int) (10::Int)++      it "diffFromBegin can convert Interval Int to Interval Int" $+         diffFromBegin +            (beginerval 2 (4 :: Int))+            (beginerval 2 10) `shouldBe`+            beginerval 2 6 -- (6, 8)++      it "diffFromEnd can convert Interval Int to Interval Int" $+         diffFromEnd+            (beginerval 2 (4 :: Int))+            (beginerval 2 10) `shouldBe`+            beginerval 2 4 -- (4, 6)++      it "diffFromBegin can convert Interval Day to Interval Integer" $+         diffFromBegin +            (beginerval 2 (fromGregorian 2001 1 1))+            (beginerval 2 (fromGregorian 2001 1 10)) `shouldBe`+            beginerval 2 9 -- (9, 11)++      it "diffFromEnd can convert Interval Day to Interval Integer" $+         diffFromEnd+            (beginerval 2 (fromGregorian 2001 1 1))+            (beginerval 2 (fromGregorian 2001 1 10)) `shouldBe`+            beginerval 2 7 -- (7, 9)    describe "Intervallic tests" $      modifyMaxSuccess (*10000) $