AsciiClassifiers.hs (1944B)
1 module Main where 2 import Runtime 3 import Wire 4 import qualified Data.ByteString as B 5 import qualified Data.Text as T 6 import qualified Data.Vector as V 7 import qualified Data.Map.Strict as M 8 import Control.Monad 9 import System.Environment 10 11 -- Independent Integer predicates: no implementation bit tests or tree slicing. 12 expected :: String -> Integer -> Bool 13 expected "digit" n = n >= 48 && n <= 57 14 expected "letter" n = n >= 65 && n <= 90 || n >= 97 && n <= 122 15 expected "lowerHex" n = expected "digit" n || n >= 97 && n <= 102 16 expected name _ = error ("unknown classifier: " ++ name) 17 truth :: Bool -> T 18 truth True = Stem Leaf 19 truth False = Leaf 20 21 -- Include all bytes, BMP code points (including non-scalar naturals), Unicode 22 -- boundaries, large values retaining ASCII low bits, and deterministic samples. 23 -- Arbitrary/partial trees are explicitly outside native_math's input contract. 24 values :: [Integer] 25 values = [0..65535] 26 ++ [0xD7FF,0xD800,0xDFFF,0xE000,0xFFFF,0x10000,0x10FFFF,0x110000] 27 ++ [2^k+d | k <- [16,17,20,21,31,32,63,64,127,128,255,256,1024 :: Int], 28 d <- [-1,0,1,48,65,97]] 29 ++ take 1024 (iterate (\n -> (n*6364136223846793005+1442695040888963407) 30 `mod` (2^(256 :: Int))) 42) 31 32 main :: IO () 33 main = do 34 [file] <- getArgs 35 bundle <- B.readFile file >>= either fail pure . decodeBundle 36 either fail pure (verifyBundle bundle) 37 let nodes = reconstructBundleTerms (bundleNodes bundle) 38 workers = M.fromList [(T.unpack (exportName e), 39 nodes V.! fromIntegral (exportRoot e)) 40 | e <- manifestExports (bundleManifest bundle)] 41 forM_ ["digit", "letter", "lowerHex"] $ \name -> do 42 let worker = workers M.! name 43 forM_ values $ \n -> 44 unless (apply worker (ofNumber n) == truth (expected name n)) 45 (fail ("classifier mismatch: " ++ show (name,n))) 46 putStrLn ("PASS " ++ show (length values*3) ++ " complete Boolean observations")