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 = ...@@ -75,9 +75,9 @@ aritySummand spec arity =
transitionsPerState :: WTASpec m -> (Integer, Vector Integer) transitionsPerState :: WTASpec m -> (Integer, Vector Integer)
transitionsPerState spec = transitionsPerState spec =
let n = numStates spec let n :: Integer = fromIntegral $ numStates spec
tPerSymbol = 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 runningTotal = V.scanl' (+) 0 tPerSymbol
in (V.last runningTotal, runningTotal) in (V.last runningTotal, runningTotal)
......
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Main (main) where module Main (main) where
import Test.Hspec import Test.Hspec
...@@ -27,6 +29,11 @@ main = hspec $ do ...@@ -27,6 +29,11 @@ main = hspec $ do
(IndexedTransition.fromIndex wta t) (IndexedTransition.fromIndex wta t)
== 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 describe "Generator" $ describe "uniqueTransitions" $ do
it "generates unique transitions" $ do it "generates unique transitions" $ do
res <- uniqueTransitions 5 (IndexedTransition.Index 10) 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