Selftest.hs 803 Bytes
Newer Older
1
2
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
3
module Rules.Selftest (selftestRules) where
4
5

import Development.Shake
6
import Settings.Builders.Ar (chunksOfSize)
7
import Test.QuickCheck
8
import Way
9
10
11
12
13
14
15

instance Arbitrary Way where
    arbitrary = wayFromUnits <$> arbitrary

instance Arbitrary WayUnit where
    arbitrary = arbitraryBoundedEnum

Andrey Mokhov's avatar
Andrey Mokhov committed
16
17
selftestRules :: Rules ()
selftestRules =
18
    "selftest" ~> do
Neil Mitchell's avatar
Neil Mitchell committed
19
        test $ \(x :: Way) -> read (show x) == x
20
21
22
23
        test $ \n xs ->
            let res = chunksOfSize n xs
            in concat res == xs && all (\r -> length r == 1 || length (concat r) <= n) res
        test $ chunksOfSize 3 ["a","b","c","defg","hi","jk"] == [["a","b","c"],["defg"],["hi"],["jk"]]
Neil Mitchell's avatar
Neil Mitchell committed
24
25
26
27


test :: Testable a => a -> Action ()
test = liftIO . quickCheck