{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} module Test where import Data.Function (($), (.)) import qualified Data.List as List import Data.Maybe (Maybe(..), fromJust) import Data.Monoid ((<>)) import Data.Ord (Ordering(..)) import Prelude (Integer) import System.IO (IO) import Test.Tasty import Test.Tasty.HUnit import Text.Show (Show(..)) import qualified Data.Interval as Interval import qualified Sieve.Test as Sieve main :: IO () main = defaultMain $ testGroup "Interval" [ testGroup "position" $ List.concatMap (\(mi, mj, p) -> let i = fromJust mi in let j = fromJust mj in let (le, ge) = case p of Interval.Equal -> (EQ, EQ) _ -> (LT, GT) in [ testCase ((show . Interval.Pretty) i <> " " <> (show . Interval.Pretty) j) $ Interval.position i j @?= (p, le) , testCase ((show . Interval.Pretty) j <> " " <> (show . Interval.Pretty) i) $ Interval.position j i @?= (p, ge) ] ) [ ( (Interval.<..<) 0 (4::Integer) , (Interval.<..<) 5 9 , Interval.Away ) , ( (Interval.<..<) 0 4 , (Interval.<=..<) 4 9 , Interval.Adjacent ) , ( (Interval.<..<) 0 5 , (Interval.<..<) 4 9 , Interval.Overlap ) , ( (Interval.<..<) 0 5 , (Interval.<..<) 0 9 , Interval.Prefix ) , ( (Interval.<..<) 0 9 , (Interval.<..<) 1 8 , Interval.Include ) , ( (Interval.<..<) 0 9 , (Interval.<..<) 5 9 , Interval.Suffixed ) , ( (Interval.<..<) 0 9 , (Interval.<..<) 0 9 , Interval.Equal ) , ( (Interval.<..<) 0 9 , (Interval.<..<=) 0 9 , Interval.Prefix ) , ( (Interval.<=..<) 0 9 , (Interval.<..<) 0 9 , Interval.Suffixed ) , ( (Interval.<=..<=) 0 9 , (Interval.<..<) 0 9 , Interval.Include ) ] , testGroup "intersection" $ List.concatMap (\(mi, mj, e) -> let i = fromJust mi in let j = fromJust mj in [ testCase ((show . Interval.Pretty) i <> " " <> (show . Interval.Pretty) j) $ Interval.intersection i j @?= e , testCase ((show . Interval.Pretty) j <> " " <> (show . Interval.Pretty) i) $ Interval.intersection j i @?= e ] ) [ ( (Interval.<..<) 0 (4::Integer) , (Interval.<..<) 5 9 , Nothing ) , ( (Interval.<..<=) 0 5 , (Interval.<=..<) 5 9 , (Interval.<=..<=) 5 5 ) , ( (Interval.<..<) 0 6 , (Interval.<..<) 4 9 , (Interval.<..<) 4 6 ) , ( (Interval.<..<=) 0 6 , (Interval.<=..<) 4 9 , (Interval.<=..<=) 4 6 ) , ( (Interval.<..<) 0 6 , (Interval.<=..<) 4 9 , (Interval.<=..<) 4 6 ) , ( (Interval.<..<=) 0 6 , (Interval.<..<) 4 9 , (Interval.<..<=) 4 6 ) , ( (Interval.<..<) 0 9 , (Interval.<..<) 0 9 , (Interval.<..<) 0 9 ) , ( (Interval.<=..<) 0 9 , (Interval.<..<=) 0 9 , (Interval.<..<) 0 9 ) , ( (Interval.<..<=) 0 9 , (Interval.<=..<) 0 9 , (Interval.<..<) 0 9 ) , ( (Interval.<=..<=) 0 9 , (Interval.<=..<=) 0 9 , (Interval.<=..<=) 0 9 ) ] , testGroup "union" $ List.concatMap (\(mi, mj, e) -> let i = fromJust mi in let j = fromJust mj in [ testCase ((show . Interval.Pretty) i <> " " <> (show . Interval.Pretty) j) $ Interval.union i j @?= e , testCase ((show . Interval.Pretty) j <> " " <> (show . Interval.Pretty) i) $ Interval.union j i @?= e ] ) [ ( (Interval.<..<) 0 (4::Integer) , (Interval.<..<) 5 9 , Nothing ) , ( (Interval.<..<=) 0 5 , (Interval.<..<) 5 9 , (Interval.<..<) 0 9 ) , ( (Interval.<..<) 0 5 , (Interval.<=..<) 5 9 , (Interval.<..<) 0 9 ) , ( (Interval.<..<=) 0 5 , (Interval.<=..<) 5 9 , (Interval.<..<) 0 9 ) , ( (Interval.<..<) 0 6 , (Interval.<..<) 4 9 , (Interval.<..<) 0 9 ) , ( (Interval.<..<) 0 9 , (Interval.<..<) 0 9 , (Interval.<..<) 0 9 ) , ( (Interval.<=..<) 0 9 , (Interval.<..<=) 0 9 , (Interval.<=..<=) 0 9 ) , ( (Interval.<..<=) 0 9 , (Interval.<=..<) 0 9 , (Interval.<=..<=) 0 9 ) , ( (Interval.<=..<=) 0 9 , (Interval.<=..<=) 0 9 , (Interval.<=..<=) 0 9 ) ] , Sieve.tests ]