2KOAQWUTFV673P2CLZEIZIVOCPTMXNKDILOVWP6PHRJWAXEGLC6QC module Main (main) whereimport Control.Monad (unless)import Test.Tastyimport Test.Tasty.Falsifyimport qualified Test.Falsify.Generator as Genimport qualified Test.Falsify.Range as Ranimport qualified GardGround.Utils.ScopeMask as ScMmain :: IO ()main = defaultMain $testProperty "scope mask list roundtrip" $ dox <- gen . Gen.inRange $ Ran.between (0, 10000000)let x' = toEnum x :: Integerlet ScM.ScopeMask y = ScM.fromList . ScM.toList $ ScM.ScopeMask x'unless (x' == y) $ testFailed "roundtrip failed"
{-# LANGUAGE DerivingVia #-}module GardGround.Utils.ScopeMask where-- this mostly a direct copy of https://github.com/AndrasKovacs/smalltt/blob/b5fc9b3747dcbf8c71ca9f976afb7b574b630996/src/LvlSet.hs-- see LICENSE.smalltt for license informationimport Data.Bitsimport Data.Foldable (foldl')newtype ScopeMask = ScopeMask Integer deriving (Eq, Bits) via Integerinstance Semigroup ScopeMask where(<>) = (.|.){-# INLINE (<>) #-}instance Monoid ScopeMask wheremempty = ScopeMask 0{-# INLINE mempty #-}insert :: Int -> ScopeMask -> ScopeMaskinsert x (ScopeMask s) = ScopeMask (unsafeShiftL 1 x .|. s){-# INLINE insert #-}member :: Int -> ScopeMask -> Boolmember x (ScopeMask s) = (unsafeShiftL 1 x .&. s) /= 0{-# INLINE member #-}toList :: ScopeMask -> [Int]toList s' = reverse $ intern 0 s'where-- | `intern offset smask`intern :: Int -> ScopeMask -> [Int]intern _ (ScopeMask 0) = []intern i (ScopeMask s) =let nxt = intern (i + 1) (ScopeMask $ unsafeShiftR s 1) inif 1 .&. s /= 0 then i:nxt else nxtfromList :: [Int] -> ScopeMaskfromList = foldl' (flip insert) memptyinstance Show ScopeMask whereshow = show . toList
test-suite gardground-testimport: warningsdefault-language: Haskell2010type: exitcode-stdio-1.0hs-source-dirs: testmain-is: Main.hsbuild-depends:base (>= 4.16.0.0 && <4.19), falsify >= 0.2, tasty >= 1.5, gardground-core
Copyright 2021 András KovácsPermission is hereby granted, free of charge, to any person obtaining a copy ofthis software and associated documentation files (the "Software"), to deal inthe Software without restriction, including without limitation the rights touse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies ofthe Software, and to permit persons to whom the Software is furnished to do so,subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESSFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS ORCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHERIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.