module Test where

import Test.QuickCheck
import Data.Int

import Data.Binary.Builder
import qualified Data.ByteString.Lazy.Char8 as LB

import Metrics (quals)
import Print(putInt)

type Flow = Int16

-- Metrics.hs

int :: Int
int = undefined

instance Arbitrary Int16 where
    arbitrary = do x <- arbitrary 
                   return (fromIntegral (x `asTypeOf` int) `mod` 10000)

prop_quals :: [Flow] -> Bool
prop_quals fs = let q = quals fs in q <= 100 && q >= 0

prop_quals_bad :: [Flow] -> Bool
prop_quals_bad fs = quals (pessimal fs) == 0
    where pessimal = map (\x -> 50+100*(x `div` 100))

prop_quals_good :: [Flow] -> Bool
prop_quals_good fs = quals (optimal (0:fs)) == 100
    where optimal = map (\x -> 100*(x `div` 100))

-- Print.hs

prop_int i = toLazyByteString (putInt i) == LB.pack (show i)
