File: CommutativitySpec.hs

package info (click to toggle)
haskell-genvalidity-property 1.0.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 176 kB
  • sloc: haskell: 1,333; makefile: 3
file content (32 lines) | stat: -rw-r--r-- 948 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{-# LANGUAGE TypeApplications #-}

module Test.Validity.Operations.CommutativitySpec
  ( spec,
  )
where

import Data.GenValidity (GenValid)
import Test.Hspec
import Test.QuickCheck
import Test.Validity.Operations.Commutativity (commutative)

spec :: Spec
spec = do
  describe "commutative" $ do
    specify "+ is commutative" $ commutative @Int (+)
    specify "* is commutative" $ commutative @Int (*)
    specify "dot product is commutative" $ commutative dotProduct

    specify "- is not commutative" $ notCommmutative @Int (-)
    specify "cross product is not commutative" $ notCommmutative crossProduct

notCommmutative :: (Show a, Show b, Eq b, GenValid a) => (a -> a -> b) -> Property
notCommmutative op = expectFailure (commutative op)

type Point = (Int, Int)

dotProduct :: Point -> Point -> Int
dotProduct (x1, y1) (x2, y2) = x1 * x2 + y1 * y2

crossProduct :: Point -> Point -> Int
crossProduct (x1, y1) (x2, y2) = x1 * y2 - x2 * y1