-
Notifications
You must be signed in to change notification settings - Fork 4
/
CommandTests.fs
194 lines (164 loc) · 6.26 KB
/
CommandTests.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/// <summary>
/// Functions and types for commands.
/// </summary>
module Starling.Tests.Core.Command
open Starling.Core.TypeSystem
open NUnit.Framework
open Starling.Utils.Testing
open Starling.Core.Command
open Starling.Core.Command.Create
open Starling.Core.Model
open Starling.Core.Var
open Starling.Core.Symbolic
open Starling.Core.Expr
module Nops =
let check n : unit =
match n with
| Queries.NopCmd _ -> ()
| n ->
Assert.Fail
(Starling.Core.Pretty.printUnstyled
(Starling.Core.Pretty.headed
"Command is not a nop but should be one"
[ Pretty.printCommand n ] ))
let checkNot n : unit =
match n with
| Queries.NopCmd _ ->
Assert.Fail
(Starling.Core.Pretty.printUnstyled
(Starling.Core.Pretty.headed
"Command is a nop but shouldn't be one"
[ Pretty.printCommand n ] ))
| n -> ()
[<Test>]
let ``Classify [] as a no-op``() =
check []
[<Test>]
let ``Classify Assume(x!before) as a no-op``() =
check [ command "Assume" [] [ normalBoolExpr (sbVar "x") ] ]
[<Test>]
let ``Reject baz <- Foo(bar) as a no-op``() =
checkNot [ command "Foo" [ normalIntExpr (siVar "baz") ] [ normalIntExpr (siVar "bar") ] ]
[<Test>]
let ``Reject Assume (x!before); baz <- Foo(bar) as a no-op``() =
checkNot
[ command "Assume" [] [ normalBoolExpr (sbVar "x") ]
command "Foo" [ normalIntExpr (siVar "baz") ] [ normalIntExpr (siVar "bar") ] ]
module Assumes =
let isAssume c =
match c with
| Queries.Assume _ -> true
| _ -> false
let check a = Assert.IsTrue ( isAssume a )
let checkNot a = Assert.IsFalse ( isAssume a )
[<Test>]
let ``Reject [] as an assume``() =
checkNot []
[<Test>]
let ``Classify Assume(x!before) as an assume``() =
check [ command "Assume" [] [ normalBoolExpr (sbVar "x") ] ]
[<Test>]
let ``Reject baz <- Foo(bar); Assume(x!before) as an Assume`` ()=
checkNot [ command "Foo" [ normalIntExpr (siVar "baz") ] [ normalIntExpr (siVar "bar") ]
command "Assume" [] [ normalBoolExpr (sbVar "x") ] ]
module Observable =
open Starling.Core.Command.Queries
open Starling.Core.Pretty
let tvars =
Map.ofList
[ ("x", Bool (normalRec, ()))
("y", Int (normalRec, ())) ]
let check v c d : unit =
assertOkAndEqual
v
(isObservable tvars c d)
(Starling.Core.Traversal.Pretty.printTraversalError (fun _ -> String "?")
>> printUnstyled)
[<Test>]
let ``the empty command is unobservable after the empty command`` () =
check false [] []
[<Test>]
let ``the empty command is unobservable after a local stored command`` () =
check false
[]
[ command "Foo" [ normalIntExpr (siVar "y") ] [ normalBoolExpr (sbVar "x") ] ]
[<Test>]
let ``the empty command is unobservable after a nonlocal stored command`` () =
check false
[]
[ command "Foo" [ normalIntExpr (siVar "g") ] [ normalBoolExpr (sbVar "x") ] ]
[<Test>]
let ``assumes are observable after the empty command`` () =
check true
[ command "Assume" [] [ normalBoolExpr (sbVar "x") ] ]
[]
[<Test>]
let ``assumes are observable after a local stored command`` () =
check true
[ command "Assume" [] [ normalBoolExpr (sbVar "x") ] ]
[ command "Foo" [ normalIntExpr (siVar "y") ] [ normalBoolExpr (sbVar "x") ] ]
[<Test>]
let ``assumes are observable after a nonlocal stored command`` () =
check true
[ command "Assume" [] [ normalBoolExpr (sbVar "x") ] ]
[ command "Foo" [ normalIntExpr (siVar "g") ] [ normalBoolExpr (sbVar "x") ] ]
[<Test>]
let ``symbolics with are observable after the empty command`` () =
check true
[ SymC [ SymString "foo" ] ]
[]
[<Test>]
let ``symbolics are observable after a local stored command`` () =
check true
[ SymC [ SymString "foo" ] ]
[ command "Foo" [ normalIntExpr (siVar "y") ] [ normalBoolExpr (sbVar "x") ] ]
[<Test>]
let ``symbolics are observable after a nonlocal stored command`` () =
check true
[ SymC [ SymString "foo" ] ]
[ command "Foo" [ normalIntExpr (siVar "g") ] [ normalBoolExpr (sbVar "x") ] ]
[<Test>]
let ``local assignment is observable after a disjoint assignment`` () =
check true
[ Intrinsic
(IAssign
{ AssignType = Local
TypeRec = normalRec
LValue = siVar "y"
RValue = mkAdd2 (siVar "y") (IInt 1L) } ) ]
[ Intrinsic
(IAssign
{ AssignType = Store
TypeRec = normalRec
LValue = siVar "g"
RValue = mkAdd2 (siVar "y") (IInt 1L) } ) ]
[<Test>]
let ``local assignment is observable after a chained assignment`` () =
check true
[ Intrinsic
(IAssign
{ AssignType = Local
TypeRec = normalRec
LValue = siVar "y"
RValue = mkAdd2 (siVar "y") (IInt 1L) } ) ]
[ Intrinsic
(IAssign
{ AssignType = Store
TypeRec = normalRec
LValue = siVar "g"
RValue = siVar "y" } ) ]
[<Test>]
let ``local assignment is unobservable after an overwiting assignment`` () =
check false
[ Intrinsic
(IAssign
{ AssignType = Local
TypeRec = normalRec
LValue = siVar "y"
RValue = mkAdd2 (siVar "y") (IInt 1L) } ) ]
[ Intrinsic
(IAssign
{ AssignType = Load
TypeRec = normalRec
LValue = siVar "y"
RValue = siVar "g" } ) ]