Small.hs (1189B)
1 module Ob.Tests.Small ( 2 tests 3 ) where 4 5 import Control.Monad (unless) 6 import Data.List (nub, foldl') 7 import Prelude hiding (tail) 8 import Test.Hspec 9 import qualified Urbit.Ob.Ob as Ob 10 11 a = 2 ^ 2 - 1 12 b = 2 ^ 2 13 c = a * b 14 15 eff j m = 16 let v0 = [5, 9, 2, 6, 4, 0, 8, 7, 1, 10, 3, 11] 17 v1 = [2, 1, 0, 3, 10, 4, 9, 5, 7, 11, 6, 8] 18 v2 = [10, 6, 7, 1, 0, 11, 3, 9, 5, 2, 8, 4] 19 v3 = [11, 0, 3, 5, 9, 8, 6, 10, 4, 1, 2, 7] 20 21 in case j of 22 0 -> v0 !! fromIntegral m 23 1 -> v1 !! fromIntegral m 24 2 -> v2 !! fromIntegral m 25 _ -> v3 !! fromIntegral m 26 27 feis = Ob.capFe 4 a b c eff 28 29 tail = Ob.capFen 4 a b c eff 30 31 tests :: Spec 32 tests = do 33 let emm = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] 34 perm = fmap feis emm 35 inv = fmap tail perm 36 rinv = fmap feis inv 37 distincts = nub perm 38 39 describe "feis" $ do 40 it "produces distinct elements" $ 41 length distincts `shouldBe` length perm 42 43 it "permutes successfully" $ 44 foldl' (\acc x -> x `elem` emm && acc) True perm `shouldBe` True 45 46 describe "feis" $ 47 it "inverts tail" $ 48 rinv `shouldBe` perm 49 50 describe "tail" $ 51 it "inverts feis" $ 52 emm `shouldBe` inv 53