urbit-hob

Haskell utilities for phonetic base wrangling.
Log | Files | Refs | README | LICENSE

commit a56d5903fa9265a374583fffddc95473dcbb9d4a
parent 0be9bdbbbba83fdd6434cd1e1b1d8cf8902c4667
Author: Jared Tobin <jared@jtobin.io>
Date:   Tue, 10 Sep 2019 13:56:02 -0230

tests: restructure test suite

Restructures tests by module rather than individual case.

Diffstat:
Dtest/Med.hs | 72------------------------------------------------------------------------
Atest/Ob.hs | 11+++++++++++
Atest/Ob/Tests/Med.hs | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atest/Ob/Tests/Small.hs | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Dtest/Small.hs | 48------------------------------------------------
Murbit-hob.cabal | 19+++++--------------
6 files changed, 138 insertions(+), 134 deletions(-)

diff --git a/test/Med.hs b/test/Med.hs @@ -1,72 +0,0 @@ -module Main where - -import Control.Monad (unless) -import Data.List (nub, foldl') -import Prelude hiding (tail) -import Test.Hspec -import qualified Urbit.Ob.Ob as Ob - -a, b, c :: Int -a = 2 ^ 4 - 1 -b = 2 ^ 4 -c = a * b - -emm = [ - 0, 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, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, - 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, - 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, - 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, - 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, - 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, - 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, - 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239 - ] - - -eff _ m = v0 !! m where - v0 = [ - 106, 54, 57, 110, 216, 157, 90, 138, 148, 205, 214, 229, 25, 104, 217, 70, 16, 91, - 180, 108, 189, 176, 67, 213, 154, 194, 122, 199, 136, 140, 36, 56, 87, 112, 8, 34, - 14, 171, 227, 160, 211, 228, 37, 121, 119, 65, 132, 45, 224, 61, 141, 59, 82, 77, - 74, 20, 130, 181, 123, 186, 166, 42, 81, 172, 105, 196, 44, 135, 156, 192, 116, 39, - 7, 40, 84, 169, 193, 131, 88, 142, 24, 128, 38, 222, 197, 218, 159, 30, 145, 58, - 53, 85, 62, 49, 158, 86, 72, 210, 225, 52, 73, 149, 143, 195, 124, 179, 219, 9, - 200, 64, 51, 48, 26, 234, 27, 232, 231, 153, 190, 133, 109, 126, 6, 178, 183, 151, - 117, 46, 161, 43, 185, 236, 127, 89, 223, 23, 69, 68, 209, 139, 19, 33, 79, 164, - 207, 50, 144, 31, 134, 170, 29, 107, 220, 184, 47, 103, 206, 201, 175, 125, 35, 114, - 146, 10, 55, 152, 98, 1, 168, 215, 28, 237, 101, 17, 155, 118, 83, 147, 115, 100, - 233, 4, 66, 0, 150, 203, 22, 5, 174, 11, 18, 177, 3, 165, 99, 167, 202, 212, - 163, 182, 80, 162, 71, 97, 12, 60, 113, 221, 204, 41, 226, 187, 63, 230, 2, 188, - 208, 76, 191, 235, 93, 13, 111, 238, 78, 198, 21, 92, 95, 94, 96, 102, 120, 239, - 32, 129, 15, 173, 137, 75 - ] - -feis = Ob.capFe 4 a b c eff - -tail = Ob.capFen 4 a b c eff - -main :: IO () -main = do - let perm = fmap feis emm - inv = fmap tail perm - distincts = nub perm - - hspec $ do - describe "feis" $ do - it "produces distinct elements" $ - length distincts `shouldBe` length perm - - it "permutes successfully" $ - foldl' (\acc x -> x `elem` emm && acc) True perm `shouldBe` True - - describe "tail" $ - it "inverts feis" $ - emm `shouldBe` inv - diff --git a/test/Ob.hs b/test/Ob.hs @@ -0,0 +1,11 @@ +module Main where + +import qualified Ob.Tests.Small as S +import qualified Ob.Tests.Med as M +import Test.Hspec + +main :: IO () +main = + hspec $ do + context "small input space" S.tests + context "medium input space" M.tests diff --git a/test/Ob/Tests/Med.hs b/test/Ob/Tests/Med.hs @@ -0,0 +1,73 @@ +module Ob.Tests.Med ( + tests + ) where + +import Control.Monad (unless) +import Data.List (nub, foldl') +import Prelude hiding (tail) +import Test.Hspec +import qualified Urbit.Ob.Ob as Ob + +a, b, c :: Int +a = 2 ^ 4 - 1 +b = 2 ^ 4 +c = a * b + +emm = [ + 0, 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, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, + 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, + 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, + 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, + 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, + 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, + 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239 + ] + + +eff _ m = v0 !! m where + v0 = [ + 106, 54, 57, 110, 216, 157, 90, 138, 148, 205, 214, 229, 25, 104, 217, 70, 16, 91, + 180, 108, 189, 176, 67, 213, 154, 194, 122, 199, 136, 140, 36, 56, 87, 112, 8, 34, + 14, 171, 227, 160, 211, 228, 37, 121, 119, 65, 132, 45, 224, 61, 141, 59, 82, 77, + 74, 20, 130, 181, 123, 186, 166, 42, 81, 172, 105, 196, 44, 135, 156, 192, 116, 39, + 7, 40, 84, 169, 193, 131, 88, 142, 24, 128, 38, 222, 197, 218, 159, 30, 145, 58, + 53, 85, 62, 49, 158, 86, 72, 210, 225, 52, 73, 149, 143, 195, 124, 179, 219, 9, + 200, 64, 51, 48, 26, 234, 27, 232, 231, 153, 190, 133, 109, 126, 6, 178, 183, 151, + 117, 46, 161, 43, 185, 236, 127, 89, 223, 23, 69, 68, 209, 139, 19, 33, 79, 164, + 207, 50, 144, 31, 134, 170, 29, 107, 220, 184, 47, 103, 206, 201, 175, 125, 35, 114, + 146, 10, 55, 152, 98, 1, 168, 215, 28, 237, 101, 17, 155, 118, 83, 147, 115, 100, + 233, 4, 66, 0, 150, 203, 22, 5, 174, 11, 18, 177, 3, 165, 99, 167, 202, 212, + 163, 182, 80, 162, 71, 97, 12, 60, 113, 221, 204, 41, 226, 187, 63, 230, 2, 188, + 208, 76, 191, 235, 93, 13, 111, 238, 78, 198, 21, 92, 95, 94, 96, 102, 120, 239, + 32, 129, 15, 173, 137, 75 + ] + +feis = Ob.capFe 4 a b c eff + +tail = Ob.capFen 4 a b c eff + +tests :: Spec +tests = do + let perm = fmap feis emm + inv = fmap tail perm + distincts = nub perm + + describe "feis" $ do + it "produces distinct elements" $ + length distincts `shouldBe` length perm + + it "permutes successfully" $ + foldl' (\acc x -> x `elem` emm && acc) True perm `shouldBe` True + + describe "tail" $ + it "inverts feis" $ + emm `shouldBe` inv + diff --git a/test/Ob/Tests/Small.hs b/test/Ob/Tests/Small.hs @@ -0,0 +1,49 @@ +module Ob.Tests.Small ( + tests + ) where + +import Control.Monad (unless) +import Data.List (nub, foldl') +import Prelude hiding (tail) +import Test.Hspec +import qualified Urbit.Ob.Ob as Ob + +a, b, c :: Int +a = 2 ^ 2 - 1 +b = 2 ^ 2 +c = a * b + +eff j m = + let v0 = [5, 9, 2, 6, 4, 0, 8, 7, 1, 10, 3, 11] + v1 = [2, 1, 0, 3, 10, 4, 9, 5, 7, 11, 6, 8] + v2 = [10, 6, 7, 1, 0, 11, 3, 9, 5, 2, 8, 4] + v3 = [11, 0, 3, 5, 9, 8, 6, 10, 4, 1, 2, 7] + + in case j of + 0 -> v0 !! m + 1 -> v1 !! m + 2 -> v2 !! m + _ -> v3 !! m + +feis = Ob.capFe 4 a b c eff + +tail = Ob.capFen 4 a b c eff + +tests :: Spec +tests = do + let emm = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] + perm = fmap feis emm + inv = fmap tail perm + distincts = nub perm + + describe "feis" $ do + it "produces distinct elements" $ + length distincts `shouldBe` length perm + + it "permutes successfully" $ + foldl' (\acc x -> x `elem` emm && acc) True perm `shouldBe` True + + describe "tail" $ + it "inverts feis" $ + emm `shouldBe` inv + diff --git a/test/Small.hs b/test/Small.hs @@ -1,48 +0,0 @@ -module Main where - -import Control.Monad (unless) -import Data.List (nub, foldl') -import Prelude hiding (tail) -import Test.Hspec -import qualified Urbit.Ob.Ob as Ob - -a, b, c :: Int -a = 2 ^ 2 - 1 -b = 2 ^ 2 -c = a * b - -eff j m = - let v0 = [5, 9, 2, 6, 4, 0, 8, 7, 1, 10, 3, 11] - v1 = [2, 1, 0, 3, 10, 4, 9, 5, 7, 11, 6, 8] - v2 = [10, 6, 7, 1, 0, 11, 3, 9, 5, 2, 8, 4] - v3 = [11, 0, 3, 5, 9, 8, 6, 10, 4, 1, 2, 7] - - in case j of - 0 -> v0 !! m - 1 -> v1 !! m - 2 -> v2 !! m - _ -> v3 !! m - -feis = Ob.capFe 4 a b c eff - -tail = Ob.capFen 4 a b c eff - -main :: IO () -main = do - let emm = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] - perm = fmap feis emm - inv = fmap tail perm - distincts = nub perm - - hspec $ do - describe "feis" $ do - it "produces distinct elements" $ - length distincts `shouldBe` length perm - - it "permutes successfully" $ - foldl' (\acc x -> x `elem` emm && acc) True perm `shouldBe` True - - describe "tail" $ - it "inverts feis" $ - emm `shouldBe` inv - diff --git a/urbit-hob.cabal b/urbit-hob.cabal @@ -64,22 +64,13 @@ library , text >= 1.2 && < 2 , vector >= 0.12 && < 1 -Test-suite small +Test-suite ob type: exitcode-stdio-1.0 hs-source-dirs: test - main-is: Small.hs - default-language: Haskell2010 - ghc-options: - -rtsopts - build-depends: - base - , hspec - , urbit-hob - -Test-suite medium - type: exitcode-stdio-1.0 - hs-source-dirs: test - main-is: Med.hs + main-is: Ob.hs + other-modules: + Ob.Tests.Small + Ob.Tests.Med default-language: Haskell2010 ghc-options: -rtsopts