Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
12032a9a
Commit
12032a9a
authored
10 years ago
by
Regis Blanc
Browse files
Options
Downloads
Patches
Plain Diff
Unit test for default evaluator
parent
ef3642c6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/scala/leon/test/evaluators/DefaultEvaluatorTests.scala
+106
-0
106 additions, 0 deletions
...st/scala/leon/test/evaluators/DefaultEvaluatorTests.scala
with
106 additions
and
0 deletions
src/test/scala/leon/test/evaluators/DefaultEvaluatorTests.scala
0 → 100644
+
106
−
0
View file @
12032a9a
/* Copyright 2009-2014 EPFL, Lausanne */
package
leon.test.evaluators
import
leon._
import
leon.evaluators._
import
leon.utils.
{
TemporaryInputPhase
,
PreprocessingPhase
}
import
leon.frontends.scalac.ExtractionPhase
import
leon.purescala.Common._
import
leon.purescala.Definitions._
import
leon.purescala.Trees._
import
leon.purescala.DefOps._
import
leon.purescala.TypeTrees._
class
DefaultEvaluatorTests
extends
leon
.
test
.
LeonTestSuite
{
private
implicit
lazy
val
leonContext
:
LeonContext
=
createLeonContext
()
private
val
emptyProgram
=
Program
.
empty
private
val
defaultEvaluator
=
new
DefaultEvaluator
(
leonContext
,
emptyProgram
)
def
expectSuccessful
(
res
:
EvaluationResults.Result
,
expected
:
Expr
)
:
Unit
=
{
res
match
{
case
EvaluationResults
.
Successful
(
value
)
=>
assert
(
value
===
expected
)
case
_
=>
assert
(
false
)
}
}
test
(
"eval correctly evaluates literals"
)
{
expectSuccessful
(
defaultEvaluator
.
eval
(
BooleanLiteral
(
true
)),
BooleanLiteral
(
true
))
expectSuccessful
(
defaultEvaluator
.
eval
(
BooleanLiteral
(
false
)),
BooleanLiteral
(
false
))
expectSuccessful
(
defaultEvaluator
.
eval
(
IntLiteral
(
0
)),
IntLiteral
(
0
))
expectSuccessful
(
defaultEvaluator
.
eval
(
IntLiteral
(
42
)),
IntLiteral
(
42
))
expectSuccessful
(
defaultEvaluator
.
eval
(
UnitLiteral
()),
UnitLiteral
())
}
test
(
"eval of simple arithmetic expressions"
)
{
expectSuccessful
(
defaultEvaluator
.
eval
(
Plus
(
IntLiteral
(
3
),
IntLiteral
(
5
))),
IntLiteral
(
8
))
expectSuccessful
(
defaultEvaluator
.
eval
(
Minus
(
IntLiteral
(
7
),
IntLiteral
(
2
))),
IntLiteral
(
5
))
expectSuccessful
(
defaultEvaluator
.
eval
(
UMinus
(
IntLiteral
(
7
))),
IntLiteral
(-
7
))
expectSuccessful
(
defaultEvaluator
.
eval
(
Times
(
IntLiteral
(
2
),
IntLiteral
(
3
))),
IntLiteral
(
6
))
expectSuccessful
(
defaultEvaluator
.
eval
(
Modulo
(
IntLiteral
(
10
),
IntLiteral
(
3
))),
IntLiteral
(
1
))
}
test
(
"Eval of simple boolean operations"
)
{
expectSuccessful
(
defaultEvaluator
.
eval
(
And
(
BooleanLiteral
(
true
),
BooleanLiteral
(
true
))),
BooleanLiteral
(
true
))
expectSuccessful
(
defaultEvaluator
.
eval
(
And
(
BooleanLiteral
(
true
),
BooleanLiteral
(
false
))),
BooleanLiteral
(
false
))
expectSuccessful
(
defaultEvaluator
.
eval
(
And
(
BooleanLiteral
(
false
),
BooleanLiteral
(
false
))),
BooleanLiteral
(
false
))
expectSuccessful
(
defaultEvaluator
.
eval
(
And
(
BooleanLiteral
(
false
),
BooleanLiteral
(
true
))),
BooleanLiteral
(
false
))
expectSuccessful
(
defaultEvaluator
.
eval
(
Or
(
BooleanLiteral
(
true
),
BooleanLiteral
(
true
))),
BooleanLiteral
(
true
))
expectSuccessful
(
defaultEvaluator
.
eval
(
Or
(
BooleanLiteral
(
true
),
BooleanLiteral
(
false
))),
BooleanLiteral
(
true
))
expectSuccessful
(
defaultEvaluator
.
eval
(
Or
(
BooleanLiteral
(
false
),
BooleanLiteral
(
false
))),
BooleanLiteral
(
false
))
expectSuccessful
(
defaultEvaluator
.
eval
(
Or
(
BooleanLiteral
(
false
),
BooleanLiteral
(
true
))),
BooleanLiteral
(
true
))
expectSuccessful
(
defaultEvaluator
.
eval
(
Not
(
BooleanLiteral
(
false
))),
BooleanLiteral
(
true
))
expectSuccessful
(
defaultEvaluator
.
eval
(
Not
(
BooleanLiteral
(
true
))),
BooleanLiteral
(
false
))
}
test
(
"eval simple variable"
)
{
val
id
=
FreshIdentifier
(
"id"
).
setType
(
Int32Type
)
expectSuccessful
(
defaultEvaluator
.
eval
(
Variable
(
id
),
Map
(
id
->
IntLiteral
(
23
))),
IntLiteral
(
23
))
}
test
(
"eval with unbound variable should return EvaluatorError"
)
{
val
id
=
FreshIdentifier
(
"id"
).
setType
(
Int32Type
)
val
foo
=
FreshIdentifier
(
"foo"
).
setType
(
Int32Type
)
val
res
=
defaultEvaluator
.
eval
(
Variable
(
id
),
Map
(
foo
->
IntLiteral
(
23
)))
assert
(
res
.
isInstanceOf
[
EvaluationResults.EvaluatorError
])
}
test
(
"eval let expression"
)
{
val
id
=
FreshIdentifier
(
"id"
)
expectSuccessful
(
defaultEvaluator
.
eval
(
Let
(
id
,
IntLiteral
(
42
),
Variable
(
id
))),
IntLiteral
(
42
))
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment