Created
August 12, 2019 11:45
-
-
Save beckyconning/9d953d982288179f834fe2bb49ec2ea6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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