2013-08-15 23:47:39 +04:00
|
|
|
{-# LANGUAGE DisambiguateRecordFields #-}
|
|
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
|
|
|
module VerifyLayersSpanGeneration where
|
|
|
|
|
2013-12-20 10:24:56 +04:00
|
|
|
import Verify.Graphics.Vty.Prelude
|
|
|
|
|
2013-08-15 23:47:39 +04:00
|
|
|
import Verify.Graphics.Vty.Image
|
|
|
|
import Verify.Graphics.Vty.Picture
|
|
|
|
import Verify.Graphics.Vty.Span
|
|
|
|
|
|
|
|
import Graphics.Vty.Debug
|
|
|
|
import Graphics.Vty.PictureToSpans
|
|
|
|
|
|
|
|
import Verify
|
|
|
|
|
|
|
|
import qualified Data.Vector as Vector
|
|
|
|
|
2014-04-12 04:51:13 +04:00
|
|
|
largerHorizSpanOcclusion :: SingleRowSingleAttrImage -> SingleRowSingleAttrImage -> Result
|
|
|
|
largerHorizSpanOcclusion row0 row1 =
|
|
|
|
let i0 = rowImage row0
|
|
|
|
i1 = rowImage row1
|
|
|
|
(iLarger, iSmaller) = if imageWidth i0 > imageWidth i1 then (i0, i1) else (i1, i0)
|
|
|
|
expectedOps = displayOpsForImage iLarger
|
|
|
|
p = picForLayers [iLarger, iSmaller]
|
|
|
|
ops = displayOpsForPic p (imageWidth iLarger,imageHeight iLarger)
|
|
|
|
in verifyOpsEquality expectedOps ops
|
2013-08-16 00:05:38 +04:00
|
|
|
|
2013-08-17 17:40:47 +04:00
|
|
|
-- | Two rows stacked vertical is equivalent to the first row rendered as the top layer and the
|
|
|
|
-- second row rendered as a bottom layer with a background fill where the first row would be.
|
2014-04-12 04:51:13 +04:00
|
|
|
vertStackLayerEquivalence0 :: SingleRowSingleAttrImage -> SingleRowSingleAttrImage -> Result
|
|
|
|
vertStackLayerEquivalence0 row0 row1 =
|
|
|
|
let i0 = rowImage row0
|
|
|
|
i1 = rowImage row1
|
|
|
|
i = i0 <-> i1
|
|
|
|
p = picForImage i
|
|
|
|
iLower = backgroundFill (imageWidth i0) 1 <-> i1
|
|
|
|
pLayered = picForLayers [i0, iLower]
|
|
|
|
expectedOps = displayOpsForImage i
|
|
|
|
opsLayered = displayOpsForPic pLayered (imageWidth iLower,imageHeight iLower)
|
|
|
|
in verifyOpsEquality expectedOps opsLayered
|
2013-08-17 17:40:47 +04:00
|
|
|
|
2014-04-12 04:51:13 +04:00
|
|
|
vertStackLayerEquivalence1 :: SingleRowSingleAttrImage -> SingleRowSingleAttrImage -> Result
|
|
|
|
vertStackLayerEquivalence1 row0 row1 =
|
|
|
|
let i0 = rowImage row0
|
|
|
|
i1 = rowImage row1
|
|
|
|
i = i0 <-> i1
|
|
|
|
p = picForImage i
|
|
|
|
iLower = i0 <-> backgroundFill (imageWidth i1) 1
|
|
|
|
iUpper = backgroundFill (imageWidth i0) 1 <-> i1
|
|
|
|
pLayered = picForLayers [iUpper, iLower]
|
|
|
|
expectedOps = displayOpsForImage i
|
|
|
|
opsLayered = displayOpsForPic pLayered (imageWidth iLower,imageHeight iLower)
|
|
|
|
in verifyOpsEquality expectedOps opsLayered
|
2013-08-17 17:40:47 +04:00
|
|
|
|
|
|
|
-- | Two rows horiz joined is equivalent to the first row rendered as the top layer and the
|
|
|
|
-- second row rendered as a bottom layer with a background fill where the first row would be.
|
2014-04-12 04:51:13 +04:00
|
|
|
horizJoinLayerEquivalence0 :: SingleRowSingleAttrImage -> SingleRowSingleAttrImage -> Result
|
|
|
|
horizJoinLayerEquivalence0 row0 row1 =
|
|
|
|
let i0 = rowImage row0
|
|
|
|
i1 = rowImage row1
|
|
|
|
i = i0 <|> i1
|
|
|
|
p = picForImage i
|
|
|
|
iLower = backgroundFill (imageWidth i0) 1 <|> i1
|
|
|
|
pLayered = picForLayers [i0, iLower]
|
|
|
|
expectedOps = displayOpsForImage i
|
|
|
|
opsLayered = displayOpsForPic pLayered (imageWidth iLower,imageHeight iLower)
|
|
|
|
in verifyOpsEquality expectedOps opsLayered
|
2013-08-17 17:40:47 +04:00
|
|
|
|
2014-04-12 04:51:13 +04:00
|
|
|
horizJoinLayerEquivalence1 :: SingleRowSingleAttrImage -> SingleRowSingleAttrImage -> Result
|
|
|
|
horizJoinLayerEquivalence1 row0 row1 =
|
|
|
|
let i0 = rowImage row0
|
|
|
|
i1 = rowImage row1
|
|
|
|
i = i0 <|> i1
|
|
|
|
p = picForImage i
|
|
|
|
iLower = i0 <|> backgroundFill (imageWidth i1) 1
|
|
|
|
iUpper = backgroundFill (imageWidth i0) 1 <|> i1
|
|
|
|
pLayered = picForLayers [iUpper, iLower]
|
|
|
|
expectedOps = displayOpsForImage i
|
|
|
|
opsLayered = displayOpsForPic pLayered (imageWidth iLower,imageHeight iLower)
|
|
|
|
in verifyOpsEquality expectedOps opsLayered
|
2013-08-17 17:40:47 +04:00
|
|
|
|
2014-04-12 04:51:13 +04:00
|
|
|
horizJoinAlternate0 :: Result
|
|
|
|
horizJoinAlternate0 =
|
2013-08-18 08:58:43 +04:00
|
|
|
let size = 4
|
2014-04-12 04:51:13 +04:00
|
|
|
str0 = replicate size 'a'
|
|
|
|
str1 = replicate size 'b'
|
|
|
|
i0 = string defAttr str0
|
|
|
|
i1 = string defAttr str1
|
|
|
|
i = horizCat $ zipWith horizJoin (replicate size i0) (replicate size i1)
|
|
|
|
layer0 = horizCat $ replicate size $ i0 <|> backgroundFill size 1
|
|
|
|
layer1 = horizCat $ replicate size $ backgroundFill size 1 <|> i1
|
|
|
|
expectedOps = displayOpsForImage i
|
|
|
|
opsLayered = displayOpsForPic (picForLayers [layer0, layer1])
|
|
|
|
(imageWidth i,imageHeight i)
|
|
|
|
in verifyOpsEquality expectedOps opsLayered
|
2013-08-18 08:58:43 +04:00
|
|
|
|
2014-04-12 04:51:13 +04:00
|
|
|
horizJoinAlternate1 :: Result
|
|
|
|
horizJoinAlternate1 =
|
2013-08-18 08:58:43 +04:00
|
|
|
let size = 4
|
2014-04-12 04:51:13 +04:00
|
|
|
str0 = replicate size 'a'
|
|
|
|
str1 = replicate size 'b'
|
|
|
|
i0 = string defAttr str0
|
|
|
|
i1 = string defAttr str1
|
|
|
|
i = horizCat $ zipWith horizJoin (replicate size i0) (replicate size i1)
|
|
|
|
layers = [l | b <- take 4 [0,size*2..], let l = backgroundFill b 1 <|> i0 <|> i1]
|
|
|
|
expectedOps = displayOpsForImage i
|
|
|
|
opsLayered = displayOpsForPic (picForLayers layers)
|
|
|
|
(imageWidth i,imageHeight i)
|
|
|
|
in verifyOpsEquality expectedOps opsLayered
|
2013-08-18 08:58:43 +04:00
|
|
|
|
2013-08-15 23:47:39 +04:00
|
|
|
tests :: IO [Test]
|
|
|
|
tests = return
|
2013-08-16 00:05:38 +04:00
|
|
|
[ verify "a larger horiz span occludes a smaller span on a lower layer"
|
2014-04-12 04:51:13 +04:00
|
|
|
largerHorizSpanOcclusion
|
2013-08-17 17:40:47 +04:00
|
|
|
, verify "two rows stack vertical equiv to first image layered on top of second with padding (0)"
|
2014-04-12 04:51:13 +04:00
|
|
|
vertStackLayerEquivalence0
|
2013-08-17 17:40:47 +04:00
|
|
|
, verify "two rows stack vertical equiv to first image layered on top of second with padding (1)"
|
2014-04-12 04:51:13 +04:00
|
|
|
vertStackLayerEquivalence1
|
2013-10-26 09:28:22 +04:00
|
|
|
-- , verify "two rows horiz joined equiv to first image layered on top of second with padding (0)"
|
2014-04-12 04:51:13 +04:00
|
|
|
-- horizJoinLayerEquivalence0
|
2013-10-25 11:24:56 +04:00
|
|
|
-- , verify "two rows horiz joined equiv to first image layered on top of second with padding (1)"
|
2014-04-12 04:51:13 +04:00
|
|
|
-- horizJoinLayerEquivalence1
|
2013-10-25 11:24:56 +04:00
|
|
|
-- , verify "alternating images using joins is the same as alternating images using layers (0)"
|
2014-04-12 04:51:13 +04:00
|
|
|
-- horizJoinAlternate0
|
2013-10-25 11:24:56 +04:00
|
|
|
-- , verify "alternating images using joins is the same as alternating images using layers (1)"
|
2014-04-12 04:51:13 +04:00
|
|
|
-- horizJoinAlternate1
|
2013-08-16 00:05:38 +04:00
|
|
|
]
|
2013-08-15 23:47:39 +04:00
|
|
|
|