Commit 0588e103 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢

wta: Fix one more overflow

parent 3facb35a
......@@ -75,9 +75,9 @@ aritySummand spec arity =
transitionsPerState :: WTASpec m -> (Integer, Vector Integer)
transitionsPerState spec =
let n = numStates spec
let n :: Integer = fromIntegral $ numStates spec
tPerSymbol =
(V.imap (\i syms -> fromIntegral $ syms * n ^ i) (numSymbols spec))
(V.imap (\i syms -> fromIntegral syms * n ^ i) (numSymbols spec))
runningTotal = V.scanl' (+) 0 tPerSymbol
in (V.last runningTotal, runningTotal)
......
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Main (main) where
import Test.Hspec
......@@ -27,6 +29,11 @@ main = hspec $ do
(IndexedTransition.fromIndex wta t)
== t
describe "maxIndex" $ do
it "doesn't overflow for large values" $ do
let wta = WTASpec MaxInt 72000 (V.fromList [0, 0, 0, 0, 4])
IndexedTransition.maxIndex wta `shouldSatisfy` (>0)
describe "Generator" $ describe "uniqueTransitions" $ do
it "generates unique transitions" $ do
res <- uniqueTransitions 5 (IndexedTransition.Index 10)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment