From d50a0b5b57aae1c7558fa77c362ae2e36038b63c Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sat, 9 May 2020 16:40:44 +0100 Subject: Add distance function (#75) * Add distance function * Add distance measure for lists with testcases * Add more distance measures for AST * Add distance to commandline * Fix distance always giving 0 --- test/Distance.hs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/Distance.hs (limited to 'test/Distance.hs') diff --git a/test/Distance.hs b/test/Distance.hs new file mode 100644 index 0000000..a59b401 --- /dev/null +++ b/test/Distance.hs @@ -0,0 +1,30 @@ +module Distance + ( distanceTests + ) +where + +import Hedgehog (Property, (===)) +import qualified Hedgehog as Hog +import qualified Hedgehog.Gen as Hog +import qualified Hedgehog.Range as Hog +import Verismith.Verilog.Distance +import Test.Tasty +import Test.Tasty.Hedgehog + +distanceLess :: Property +distanceLess = Hog.property $ do + x <- Hog.forAll (Hog.list (Hog.linear 0 15) Hog.alpha) + y <- Hog.forAll (Hog.list (Hog.linear 0 15) Hog.alpha) + Hog.assert $ udistance x y <= distance x y + +distanceEq :: Property +distanceEq = Hog.property $ do + x <- Hog.forAll (Hog.list (Hog.linear 0 15) Hog.alpha) + distance x x === 0 + udistance x x === 0 + +distanceTests :: TestTree +distanceTests = testGroup "Distance tests" + [ testProperty "Unordered distance <= distance" distanceLess + , testProperty "distance x x === 0" distanceEq + ] -- cgit