From 023a86c585cc6bcf9c7edb483add60b1d76e1758 Mon Sep 17 00:00:00 2001 From: Mitchell Rosen Date: Wed, 6 Oct 2021 12:24:45 -0400 Subject: [PATCH] add unison-util-relation test suite --- .github/workflows/ci.yaml | 2 + hie.yaml | 28 ++++++++------ lib/unison-util-relation/package.yaml | 9 +++++ lib/unison-util-relation/test/Main.hs | 37 +++++++++++++++++++ .../unison-util-relation.cabal | 33 +++++++++++++++++ yaks/easytest/src/EasyTest.hs | 15 ++++++++ 6 files changed, 113 insertions(+), 11 deletions(-) create mode 100644 lib/unison-util-relation/test/Main.hs diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 47c470a1f..835171bb9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -85,3 +85,5 @@ jobs: x=`git status --porcelain -uno` bash -c 'if [[ -n $x ]]; then echo "$x" && false; fi' - name: prettyprint-round-trip run: stack --no-terminal exec unison transcript unison-src/transcripts-round-trip/main.md + - name: other test suites + run: stack --no-terminal test union-util-relation diff --git a/hie.yaml b/hie.yaml index 91af04b86..931f013bb 100644 --- a/hie.yaml +++ b/hie.yaml @@ -1,33 +1,39 @@ cradle: stack: - - path: "codebase2/codebase" + - path: "codebase2/codebase/./" component: "unison-codebase:lib" - - path: "codebase2/codebase-sqlite" + - path: "codebase2/codebase-sqlite/./" component: "unison-codebase-sqlite:lib" - - path: "codebase2/codebase-sync" + - path: "codebase2/codebase-sync/./" component: "unison-codebase-sync:lib" - - path: "codebase2/core" + - path: "codebase2/core/./" component: "unison-core:lib" - - path: "codebase2/util" + - path: "codebase2/util/./" component: "unison-util:lib" - - path: "codebase2/util-serialization" + - path: "codebase2/util-serialization/./" component: "unison-util-serialization:lib" - - path: "codebase2/util-term" + - path: "codebase2/util-term/./" component: "unison-util-term:lib" + - path: "lib/unison-prelude/src" + component: "unison-prelude:lib" + + - path: "lib/unison-util-relation/src" + component: "unison-util-relation:lib" + + - path: "lib/unison-util-relation/test" + component: "unison-util-relation:test:tests" + - path: "parser-typechecker/src" component: "unison-parser-typechecker:lib" - - path: "parser-typechecker/prettyprintdemo/Main.hs" - component: "unison-parser-typechecker:exe:prettyprintdemo" - - - path: "parser-typechecker/prettyprintdemo/Paths_unison_parser_typechecker.hs" + - path: "parser-typechecker/prettyprintdemo" component: "unison-parser-typechecker:exe:prettyprintdemo" - path: "parser-typechecker/tests" diff --git a/lib/unison-util-relation/package.yaml b/lib/unison-util-relation/package.yaml index c9ab493a9..89f6b6428 100644 --- a/lib/unison-util-relation/package.yaml +++ b/lib/unison-util-relation/package.yaml @@ -5,6 +5,15 @@ copyright: Copyright (C) 2013-2021 Unison Computing, PBC and contributors library: source-dirs: src +tests: + tests: + dependencies: + - easytest + - random + - unison-util-relation + main: Main.hs + source-dirs: test + dependencies: - base - containers diff --git a/lib/unison-util-relation/test/Main.hs b/lib/unison-util-relation/test/Main.hs new file mode 100644 index 000000000..8191ee723 --- /dev/null +++ b/lib/unison-util-relation/test/Main.hs @@ -0,0 +1,37 @@ +module Main where + +import EasyTest +import System.Random (Random) +import qualified Unison.Util.Relation as Relation +import Unison.Util.Relation3 (Relation3) +import qualified Unison.Util.Relation3 as Relation3 +import Unison.Util.Relation4 (Relation4) +import qualified Unison.Util.Relation4 as Relation4 + +main :: IO () +main = + run do + scope "Relation3" do + scope "d12 works" do + r3 <- randomR3 @Char @Char @Char 1000 + let d12 = Relation.fromList . map (\(a, b, _) -> (a, b)) . Relation3.toList + expectEqual (Relation3.d12 r3) (d12 r3) + + scope "d13 works" do + r3 <- randomR3 @Char @Char @Char 1000 + let d13 = Relation.fromList . map (\(a, _, c) -> (a, c)) . Relation3.toList + expectEqual (Relation3.d13 r3) (d13 r3) + + scope "Relation4" do + scope "d124 works" do + r4 <- randomR4 @Char @Char @Char @Char 1000 + let d124 = Relation3.fromList . map (\(a, b, _, d) -> (a, b, d)) . Relation4.toList + expectEqual (Relation4.d124 r4) (d124 r4) + +randomR3 :: (Ord a, Random a, Ord b, Random b, Ord c, Random c) => Int -> Test (Relation3 a b c) +randomR3 n = + Relation3.fromList <$> listOf n tuple3 + +randomR4 :: (Ord a, Random a, Ord b, Random b, Ord c, Random c, Ord d, Random d) => Int -> Test (Relation4 a b c d) +randomR4 n = + Relation4.fromList <$> listOf n tuple4 diff --git a/lib/unison-util-relation/unison-util-relation.cabal b/lib/unison-util-relation/unison-util-relation.cabal index 1a38be215..c3cadf263 100644 --- a/lib/unison-util-relation/unison-util-relation.cabal +++ b/lib/unison-util-relation/unison-util-relation.cabal @@ -46,3 +46,36 @@ library , extra , unison-prelude default-language: Haskell2010 + +test-suite tests + type: exitcode-stdio-1.0 + main-is: Main.hs + other-modules: + Paths_unison_util_relation + hs-source-dirs: + test + default-extensions: + ApplicativeDo + BlockArguments + DeriveFunctor + DerivingStrategies + DoAndIfThenElse + FlexibleContexts + FlexibleInstances + LambdaCase + MultiParamTypeClasses + NamedFieldPuns + ScopedTypeVariables + TupleSections + TypeApplications + ViewPatterns + ghc-options: -Wall + build-depends: + base + , containers + , easytest + , extra + , random + , unison-prelude + , unison-util-relation + default-language: Haskell2010 diff --git a/yaks/easytest/src/EasyTest.hs b/yaks/easytest/src/EasyTest.hs index 76e0b678b..fa4278d2b 100644 --- a/yaks/easytest/src/EasyTest.hs +++ b/yaks/easytest/src/EasyTest.hs @@ -296,6 +296,21 @@ listsOf sizes gen = sizes `forM` \n -> listOf n gen pair :: Test a -> Test b -> Test (a,b) pair = liftA2 (,) +-- | Alias for 'pair'. +tuple2 :: (Random a, Random b) => Test (a, b) +tuple2 = + (,) <$> random <*> random + +-- | Generate a random 3-tuple. +tuple3 :: (Random a, Random b, Random c) => Test (a, b, c) +tuple3 = + (,,) <$> random <*> random <*> random + +-- | Generate a random 4-tuple. +tuple4 :: (Random a, Random b, Random c, Random d) => Test (a, b, c, d) +tuple4 = + (,,,) <$> random <*> random <*> random <*> random + -- | Generate a `Data.Map k v` of the given size. mapOf :: Ord k => Int -> Test k -> Test v -> Test (Map k v) mapOf n k v = Map.fromList <$> listOf n (pair k v)