58 lines
1.6 KiB
Haskell
58 lines
1.6 KiB
Haskell
import Test.QuickCheck
|
|
|
|
import Dodge.LevelGen.StaticWalls
|
|
import Geometry
|
|
|
|
main :: IO ()
|
|
main = do
|
|
putStrLn "Running tests:"
|
|
quickCheck prop_looping
|
|
|
|
nextPair :: Eq a => (a,a) -> [(a,a)] -> [(a,a)]
|
|
nextPair (_,y) = filter (\(x,_) -> x == y)
|
|
|
|
isLooping :: Eq a => [(a,a)] -> Bool
|
|
isLooping xs = all (( == 1) . length . flip nextPair xs) xs
|
|
|
|
isLooping' :: Eq a => [(a,a)] -> Bool
|
|
isLooping' xs = all (f xs) xs
|
|
where
|
|
f ys (x,y) = length ins == length outs && length rins == length routs
|
|
where
|
|
ins = filter (\(a,b) -> a == x) ys
|
|
outs = filter (\(a,b) -> b == x) ys
|
|
rins = filter (\(a,b) -> a == y) ys
|
|
routs = filter (\(a,b) -> b == y) ys
|
|
|
|
polygonStrictlyConvex :: [Point2] -> Bool
|
|
polygonStrictlyConvex ps = True
|
|
|
|
--prop_looping :: [Point2] -> [WallP] -> Bool
|
|
|
|
prop_looping = forAllShrink genTris shrinkTris $ \tris ->
|
|
(all (not . (\[a,b,c] -> isOnLine a b c
|
|
|| isOnLine a c b
|
|
|| isOnLine b c a
|
|
) ) tris)
|
|
==> (isLooping' $ foldr cutWalls' [] tris)
|
|
|
|
shrinkTris [] = []
|
|
shrinkTris (x:xs) = xs : map (x :) (shrinkTris xs)
|
|
|
|
genTri = zip <$> trip <*> trip
|
|
where
|
|
trip = vectorOf 3 $ fmap fromIntegral $ choose (0,5::Int)
|
|
|
|
genTris = listOf genTri
|
|
|
|
--extractLoops :: Eq a => [(a,a)] -> [[(a,a)]]
|
|
--extractLoops [] = []
|
|
--extractLoops (x:xs) =
|
|
|
|
--[[(4.0,10.0),(6.0,2.0),(3.0,0.0)],[(9.0,3.0),(2.0,5.0),(0.0,6.0)]]
|
|
--
|
|
--[[(314.0,-396.0),(0.0,-223.71985),(-239.32773,357.25983)],[(0.0,0.0),(-84.0,-177.0),(237.0,-355.5366)]]
|
|
--
|
|
--
|
|
--[[(5.0,2.0),(3.0,5.0),(1.0,2.0)],[(3.0,2.0),(2.0,0.0),(4.0,0.0)],[(5.0,1.0),(3.0,0.0),(3.0,1.0)]]
|