Skip to content

Instantly share code, notes, and snippets.

@beckyconning
Created August 12, 2019 11:45
Show Gist options
  • Save beckyconning/3b0afed654aad83db53389fc82a49020 to your computer and use it in GitHub Desktop.
Save beckyconning/3b0afed654aad83db53389fc82a49020 to your computer and use it in GitHub Desktop.
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment