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
22426e3e
Commit
22426e3e
authored
15 years ago
by
Mirco Dotta
Browse files
Options
Downloads
Patches
Plain Diff
more involved examples that actually works!!!
parent
1971b706
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
Test6.scala
+53
-0
53 additions, 0 deletions
Test6.scala
with
53 additions
and
0 deletions
Test6.scala
0 → 100644
+
53
−
0
View file @
22426e3e
import
funcheck.lib.Specs._
import
funcheck.lib.Specs
object
TreeFuncheckTest
extends
Application
{
/** class hierarchy*/
sealed
abstract
class
BST
@generator
case
class
Empty
()
extends
BST
case
class
Node
(
left
:
BST
,
value
:
Int
,
right
:
BST
)
extends
BST
/** used for specification purposes */
def
content
(
t
:
BST
)
:
Set
[
Int
]
=
t
match
{
case
Empty
()
=>
Set
.
empty
case
Node
(
left
,
v
,
right
)
=>
(
content
(
left
)
++
Set
(
v
)
++
content
(
right
))
}
/** compute the size of the given tree*/
def
size
(
t
:
BST
)
:
Int
=
t
match
{
case
Empty
()
=>
0
case
Node
(
left
,
v
,
right
)
=>
size
(
left
)
+
1
+
size
(
right
)
}
/** build correct binary trees (this should be used instead of the default case class constructor)*/
@generator
def
add
(
x
:
Int
,
t
:
BST
)
:
Node
=
{
t
match
{
case
Empty
()
=>
Node
(
Empty
(),
x
,
Empty
())
case
t
@
Node
(
left
,
v
,
right
)
=>
{
if
(
x
<
v
)
Node
(
add
(
x
,
left
),
v
,
right
)
else
if
(
x
==
v
)
t
else
Node
(
left
,
v
,
add
(
x
,
right
))
}
}
}
/** check if the tree contains the key*/
def
contains
(
key
:
Int
,
t
:
BST
)
:
Boolean
=
{
t
match
{
case
Empty
()
=>
false
case
Node
(
left
,
v
,
right
)
=>
{
if
(
key
==
v
)
true
else
if
(
key
<
v
)
contains
(
key
,
left
)
else
contains
(
key
,
right
)
}
}
}
/** properties */
Specs
.
forAll
[(
BST
,
Int
)](
p
=>
contains
(
p
.
_2
,
p
.
_1
)
==
content
(
p
.
_1
).
contains
(
p
.
_2
))
Specs
.
forAll
[(
BST
,
Int
)](
p
=>
content
(
add
(
p
.
_2
,
p
.
_1
))
==
content
(
p
.
_1
)
+
p
.
_2
)
}
\ No newline at end of file
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