Implement Arbitrary for Vertex

This commit is contained in:
Simon Bruder 2022-12-27 20:01:09 +01:00
parent 002b834449
commit 5d956a3d89
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC

View file

@ -1,6 +1,7 @@
module Main where module Main where
import Control.Monad (join) import Control.Monad (join)
import Test.QuickCheck (Arbitrary (arbitrary))
-- | One point of a path, consisting of its \(x\) and \(y\) coordinates. -- | One point of a path, consisting of its \(x\) and \(y\) coordinates.
newtype Vertex = Point (Double, Double) newtype Vertex = Point (Double, Double)
@ -8,6 +9,12 @@ newtype Vertex = Point (Double, Double)
instance Show Vertex where instance Show Vertex where
show (Point (x, y)) = show x ++ " " ++ show y show (Point (x, y)) = show x ++ " " ++ show y
instance Arbitrary Vertex where
arbitrary = do
x <- arbitrary
y <- arbitrary
return (Point (x, y))
-- | 'fromAngle' @angle@ -- | 'fromAngle' @angle@
-- creats a point on the unit circle at the specified angle -- creats a point on the unit circle at the specified angle
-- (specified in radians). -- (specified in radians).