New patches: [Fix ticket 1762 David Benbennick **20071111201939] { hunk ./Data/IntSet.hs 113 -import QuickCheck +import Test.QuickCheck hunk ./Data/IntSet.hs 116 +import qualified Data.Set as Set hunk ./Data/IntSet.hs 171 +-- Invariant: The Mask is a power of 2. It is the largest bit position at which +-- two elements of the set differ. +-- Invariant: Prefix is the common high-order bits that all elements share to +-- the left of the Mask bit. +-- Invariant: In Bin prefix mask left right, left consists of the elements that +-- don't have the mask bit set; right is all the elements that do. hunk ./Data/IntSet.hs 413 - | shorter m2 m1 = subsetCmpLt + | shorter m2 m1 = case subsetCmpLt of + GT -> GT + _ -> LT hunk ./Data/IntSet.hs 864 +-- Suppose a is largest such that 2^a divides 2*m. +-- Then mask i m is i with the low a bits zeroed out. hunk ./Data/IntSet.hs 1031 + +{-------------------------------------------------------------------- + Bin invariants +--------------------------------------------------------------------} +powersOf2 :: IntSet +powersOf2 = fromList [2^i | i <- [0..63]] + +-- Check the invariant that the mask is a power of 2. +prop_MaskPow2 :: IntSet -> Bool +prop_MaskPow2 (Bin _ msk left right) = member msk powersOf2 && prop_MaskPow2 left && prop_MaskPow2 right +prop_MaskPow2 _ = True + +-- Check that the prefix satisfies its invariant. +prop_Prefix :: IntSet -> Bool +prop_Prefix s@(Bin prefix msk left right) = all (\elem -> match elem prefix msk) (toList s) && prop_Prefix left && prop_Prefix right +prop_Prefix _ = True + +-- Check that the left elements don't have the mask bit set, and the right +-- ones do. +prop_LeftRight :: IntSet -> Bool +prop_LeftRight (Bin _ msk left right) = and [x .&. msk == 0 | x <- toList left] && and [x .&. msk == msk | x <- toList right] +prop_LeftRight _ = True + +{-------------------------------------------------------------------- + IntSet operations are like Set operations +--------------------------------------------------------------------} +toSet :: IntSet -> Set.Set Int +toSet = Set.fromList . toList + +-- Check that IntSet.isProperSubsetOf is the same as Set.isProperSubsetOf. +prop_isProperSubsetOf :: IntSet -> IntSet -> Bool +prop_isProperSubsetOf a b = isProperSubsetOf a b == Set.isProperSubsetOf (toSet a) (toSet b) + +-- In the above test, isProperSubsetOf almost always returns False (since a +-- random set is almost never a subset of another random set). So this second +-- test checks the True case. +prop_isProperSubsetOf2 :: IntSet -> IntSet -> Bool +prop_isProperSubsetOf2 a b = isProperSubsetOf a c == (a /= c) where + c = union a b } [Add tiny regression test David Benbennick **20071113045358] { hunk ./tests/all.T 5 - +test('dataintset001', normal, compile_and_run, ['-package containers']) addfile ./tests/dataintset001.hs hunk ./tests/dataintset001.hs 1 + +{- +Through 6.8.1 this printed False, should be True. +-} + +module Main (main) where + +import Data.IntSet + +main :: IO () +main = print $ isProperSubsetOf (fromList [2,3]) $ fromList [2,3,4] addfile ./tests/dataintset001.stdout hunk ./tests/dataintset001.stdout 1 +True } Context: [Specify build-type: Simple Duncan Coutts **20071018125404] [Add a boring file Ian Lynagh **20070913204647] [TAG 2007-09-13 Ian Lynagh **20070913215901] Patch bundle hash: 14737998e2fca643fc53bcac37a8d9c03b5e7af2