comfort-glpk-0.0: test/Test/Numeric/GLPK.hs
-- Do not edit! Automatically created with doctest-extract from src/Numeric/GLPK.hs
{-# LINE 68 "src/Numeric/GLPK.hs" #-}
module Test.Numeric.GLPK where
import Test.DocTest.Base
import qualified Test.DocTest.Driver as DocTest
{-# LINE 69 "src/Numeric/GLPK.hs" #-}
import qualified Numeric.GLPK as LP
import Numeric.GLPK ((.*), (<=.), (==.))
import qualified Data.Array.Comfort.Storable as Array
import qualified Data.Array.Comfort.Shape as Shape
import Data.Tuple.HT (mapPair, mapSnd)
import qualified Test.QuickCheck as QC
import Test.QuickCheck ((===), (.&&.), (.||.))
type X = Shape.Element
type PairShape = Shape.NestedTuple Shape.TupleIndex (X,X)
type TripletShape = Shape.NestedTuple Shape.TupleIndex (X,X,X)
pairShape :: PairShape
pairShape = Shape.static
tripletShape :: TripletShape
tripletShape = Shape.static
round3 :: Double -> Double
round3 x = fromInteger (round (1000*x)) / 1000
test :: DocTest.T ()
test = do
DocTest.printPrefix "Numeric.GLPK:198: "
{-# LINE 198 "src/Numeric/GLPK.hs" #-}
DocTest.property
{-# LINE 198 "src/Numeric/GLPK.hs" #-}
(\(QC.Positive posWeight) (QC.Positive negWeight) target -> case Shape.indexTupleFromShape pairShape of (pos,neg) -> case mapSnd (mapSnd Array.toTuple) <$> LP.simplex [] [[1.*pos, (-1).*neg] ==. target] (LP.Minimize, Array.fromTuple (posWeight,negWeight) :: Array.Array PairShape Double) of (Right (LP.Optimal,(absol,(posResult,negResult)))) -> QC.property (absol>=0) .&&. (posResult === 0 .||. negResult === 0); _ -> QC.property False)
DocTest.printPrefix "Numeric.GLPK:195: "
{-# LINE 195 "src/Numeric/GLPK.hs" #-}
DocTest.example
{-# LINE 195 "src/Numeric/GLPK.hs" #-}
(case Shape.indexTupleFromShape tripletShape of (x1,x2,x3) -> mapSnd (mapSnd Array.toTuple) <$> LP.simplex [] [[2.*x1, 1.*x2] <=. 10, [1.*x2, 5.*x3] <=. 20] (LP.Maximize, Array.fromTuple (4,-3,2) :: Array.Array TripletShape Double))
[ExpectedLine [LineChunk "Right (Optimal,(28.0,(5.0,0.0,4.0)))"]]
DocTest.printPrefix "Numeric.GLPK:256: "
{-# LINE 256 "src/Numeric/GLPK.hs" #-}
DocTest.example
{-# LINE 256 "src/Numeric/GLPK.hs" #-}
(case Shape.indexTupleFromShape tripletShape of (x1,x2,x3) -> mapSnd (mapSnd Array.toTuple) <$> LP.exact [] [[2.*x1, 1.*x2] <=. 10, [1.*x2, 5.*x3] <=. 20] (LP.Maximize, Array.fromTuple (4,-3,2) :: Array.Array TripletShape Double))
[ExpectedLine [LineChunk "Right (Optimal,(28.0,(5.0,0.0,4.0)))"]]
DocTest.printPrefix "Numeric.GLPK:288: "
{-# LINE 288 "src/Numeric/GLPK.hs" #-}
DocTest.example
{-# LINE 288 "src/Numeric/GLPK.hs" #-}
(case Shape.indexTupleFromShape tripletShape of (x1,x2,x3) -> mapSnd (mapPair (round3, Array.toTuple . Array.map round3)) <$> LP.interior [] [[2.*x1, 1.*x2] <=. 10, [1.*x2, 5.*x3] <=. 20] (LP.Maximize, Array.fromTuple (4,-3,2) :: Array.Array TripletShape Double))
[ExpectedLine [LineChunk "Right (Optimal,(28.0,(5.0,0.0,4.0)))"]]