Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. module Test.SlamData.Property.RectanglePacking where
  2.  
  3. import SlamData.Prelude
  4.  
  5. import Data.Int as Int
  6. import Math (abs)
  7. import Test.StrongCheck as SC
  8. import Test.StrongCheck.Gen as Gen
  9. import RectanglePacking as RP
  10.  
  11. check ∷ ∀ e. SC.SC e Unit
  12. check = do
  13. SC.quickCheck' 1000 checkTileWithBoundingRatio
  14. SC.quickCheck' 1000 checkMostRatioFittingRectangleWithSpacings
  15.  
  16. checkTileWithBoundingRatio ∷ Gen.Gen SC.Result
  17. checkTileWithBoundingRatio = do
  18. width ← Gen.choose 1.0 4096.0
  19. height ← Gen.choose 1.0 4096.0
  20. count ← Gen.chooseInt 1 128
  21. let
  22. out = RP.tileWithBoundingRatio RP.goldenRatio count { width, height }
  23. total = width * height
  24. dim = out.dimensions
  25. tile = dim.height * dim.width
  26. actual = Int.toNumber count * tile
  27. pure $ abs (actual - total) < 0.01 SC.<?>
  28. "There is a problem with `tileWithBoundingRatio` using `goldenRatio` \n"
  29. <> "count: " <> show count <> "\n"
  30. <> "width: " <> show width <> "\n"
  31. <> "height: " <> show height <> "\n"
  32.  
  33. checkMostRatioFittingRectangleWithSpacings ∷ Gen.Gen SC.Result
  34. checkMostRatioFittingRectangleWithSpacings = do
  35. width ← Gen.choose 1.0 4096.0
  36. height ← Gen.choose 1.0 4096.0
  37. count ← Gen.chooseInt 1 128
  38. let _ × spacers = RP.mostRatioFittingRectangleWithSpacings { width, height } count
  39. pure $ spacers < count SC.<?>
  40. "There is a problem with `mostRatioFittingRectangleWithSpacings` \n"
  41. <> "count: " <> show count <> "\n"
  42. <> "width: " <> show width <> "\n"
  43. <> "height: " <> show height <> "\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement