Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Test.SlamData.Property.RectanglePacking where
- import SlamData.Prelude
- import Data.Int as Int
- import Math (abs)
- import Test.StrongCheck as SC
- import Test.StrongCheck.Gen as Gen
- import RectanglePacking as RP
- check ∷ ∀ e. SC.SC e Unit
- check = do
- SC.quickCheck' 1000 checkTileWithBoundingRatio
- SC.quickCheck' 1000 checkMostRatioFittingRectangleWithSpacings
- checkTileWithBoundingRatio ∷ Gen.Gen SC.Result
- checkTileWithBoundingRatio = do
- width ← Gen.choose 1.0 4096.0
- height ← Gen.choose 1.0 4096.0
- count ← Gen.chooseInt 1 128
- let
- out = RP.tileWithBoundingRatio RP.goldenRatio count { width, height }
- total = width * height
- dim = out.dimensions
- tile = dim.height * dim.width
- actual = Int.toNumber count * tile
- pure $ abs (actual - total) < 0.01 SC.<?>
- "There is a problem with `tileWithBoundingRatio` using `goldenRatio` \n"
- <> "count: " <> show count <> "\n"
- <> "width: " <> show width <> "\n"
- <> "height: " <> show height <> "\n"
- checkMostRatioFittingRectangleWithSpacings ∷ Gen.Gen SC.Result
- checkMostRatioFittingRectangleWithSpacings = do
- width ← Gen.choose 1.0 4096.0
- height ← Gen.choose 1.0 4096.0
- count ← Gen.chooseInt 1 128
- let _ × spacers = RP.mostRatioFittingRectangleWithSpacings { width, height } count
- pure $ spacers < count SC.<?>
- "There is a problem with `mostRatioFittingRectangleWithSpacings` \n"
- <> "count: " <> show count <> "\n"
- <> "width: " <> show width <> "\n"
- <> "height: " <> show height <> "\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement