line-drawing-0.3.0.0: test/Line/DrawSpec.hs
module Line.DrawSpec where
import Line.Draw
import Test.Hspec
main :: IO ()
main = hspec spec
spec :: Spec
spec = do
describe "bresenham" $ do
it "rasterises a simple line" $
bresenham (0 :: Int, 0) (4, 4) `shouldBe`
[(0,0), (1,1), (2,2), (3,3), (4,4)]
it "rasterises a simple line starting from (1, 1)" $
bresenham (1 :: Int, 1) (4, 4) `shouldBe`
[(1,1), (2,2), (3,3), (4,4)]
it "rasterises a line" $
bresenham (0 :: Int, 0) (4, 2) `shouldBe`
[(0,0), (1,0), (2,1), (3,1), (4,2)]
it "rasterises a line, quadrant 2, m<1" $
bresenham (0 :: Int, 0) (-4, 2) `shouldBe`
[(0,0), (-1,0), (-2,1), (-3,1), (-4,2)]
it "rasterises a line, quadrant 3, m<1" $
bresenham (0 :: Int, 0) (-4, -2) `shouldBe`
[(0,0), (-1,0), (-2,-1), (-3,-1), (-4,-2)]
it "rasterises a line, quadrant 1, m>1" $
bresenham (0 :: Int, 0) (2, 4) `shouldBe`
[(0,0), (0,1), (1,2), (1,3), (2,4)]
it "rasterises a line, quadrant 4, m>1" $
bresenham (0 :: Int, 0) (2, -4) `shouldBe`
[(0,0), (0,-1), (1,-2), (1,-3), (2,-4)]
it "returns a singleton list if start and end are the same" $
bresenham (2 :: Int, 2) (2, 2) `shouldBe`
[(2,2)]