Comments (1)
I just adapted my example to use the current version from main (commit 21337e4), and everything seem to be working now! New code below:
module Specs.SimpleCounterSpec where
import Data.Either qualified as Either
import Data.Hashable (Hashable)
import GHC.Generics (Generic)
import Language.Spectacle (
ActionType (ActionWF),
Fairness (WeakFair),
Modality (Eventually, Stays),
Specification (..),
Temporal,
TemporalType (PropF, PropFG),
modelcheck,
plain,
(.=),
pattern ConF,
pattern NilF,
type (#),
)
import Test.Hspec (Spec, describe, hspec, it, shouldSatisfy)
main :: IO ()
main = hspec spec
spec :: Spec
spec =
describe "SimpleCounter spec" $ do
describe "eventually is maxCounter" $ do
specification <- pure $ specification @Eventually PropF
it "passes when initialCounter < maxCounter" $ do
result <- modelcheck (specification (1, 4))
result `shouldSatisfy` Either.isRight
it "passes when initialCounter = maxCounter" $ do
result <- modelcheck (specification (4, 4))
result `shouldSatisfy` Either.isRight
it "fails when initialCounter > maxCounter" $ do
result <- modelcheck (specification (4, 2))
result `shouldSatisfy` Either.isLeft
describe "eventually always is maxCounter" $ do
specification <- pure $ specification @Stays PropFG
it "passes when initialCounter < maxCounter" $ do
result <- modelcheck (specification (1, 4))
result `shouldSatisfy` Either.isRight
it "passes when initialCounter = maxCounter" $ do
result <- modelcheck (specification (4, 4))
result `shouldSatisfy` Either.isRight
it "fails when initialCounter > maxCounter" $ do
result <- modelcheck (specification (4, 2))
result `shouldSatisfy` Either.isLeft
data Counter = Counting Word | Done Word
deriving stock (Eq, Show, Generic)
deriving anyclass (Hashable)
type CounterSpec modality =
Specification CounterState CounterActions (CounterProperty modality)
type CounterState =
'[ "goal" # Word
, "counter" # Counter
]
type CounterActions =
'[ "counterInc" # 'WeakFair
]
type CounterProperty modality =
'["counterEqualsMax" # modality]
specification ::
(forall s. Temporal s Bool -> TemporalType s modality) ->
(Word, Word) ->
CounterSpec modality
specification toProp (initialCounter, maxCounter) =
Specification
{ specInit =
ConF #goal (pure maxCounter)
. ConF #counter (pure (Counting initialCounter))
$ NilF
, specNext =
ConF #counterInc (ActionWF counterInc) NilF
, specProp =
ConF #counterEqualsMax (toProp counterEqualsMax) NilF
}
where
counterInc =
plain #counter >>= \case
Done _ -> pure False
Counting counter -> do
goal <- plain #goal
let counter' =
if counter < goal
then Counting $ counter + 1
else Done counter
#counter .= pure counter'
pure True
counterEqualsMax = do
goal <- plain #goal
counter <- plain #counter
pure
case counter of
Done c -> c == goal
_ -> False
from spectacle.
Related Issues (18)
- Rename type ascription syntax
- Temporal formula not applied to initial states
- Model checker option to emit state trace.
- Detect liveness violations in infinite unchanging extensions
- Adding Spectacle to Hackage & nixpkgs? HOT 3
- Print States Leading Up To Error HOT 1
- Checking Inductive Invariants HOT 2
- How to disable a formula? HOT 1
- The integration tests are not verified correctly HOT 1
- Use `Managed` monad in CLI HOT 1
- Publish a new revision of `spectacle-1.0.0` to remove the changelog entry
- Fix the spanning tree spec for spectacle-1.0.0
- Weird behaviour with NonDet and Stays modality HOT 10
- Support GHC 9.0 / base 4.15 HOT 2
- Should --only-trace should imply --log when using `interaction`? HOT 1
- Generating counterexample behaviors with Interaction seems awkward? HOT 3
- Stuttering steps are not inserted for unchanged steps
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spectacle.