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
13283a54
Commit
13283a54
authored
14 years ago
by
Swen Jacobs
Browse files
Options
Downloads
Patches
Plain Diff
New insertion sort example, parsable by funcheck
parent
fe8a64df
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
testcases/InsertionSort-new.scala
+36
-0
36 additions, 0 deletions
testcases/InsertionSort-new.scala
with
36 additions
and
0 deletions
testcases/InsertionSort-new.scala
0 → 100644
+
36
−
0
View file @
13283a54
import
scala.collection.immutable.Set
object
InsertionSort
{
sealed
abstract
class
List
case
class
Cons
(
head
:
Int
,
tail
:
List
)
extends
List
case
class
Nil
()
extends
List
def
contents
(
l
:
List
)
:
Set
[
Int
]
=
l
match
{
case
Nil
()
=>
Set
.
empty
case
Cons
(
x
,
xs
)
=>
contents
(
xs
)
++
Set
(
x
)
}
def
is_sorted
(
l
:
List
)
:
Boolean
=
l
match
{
case
Nil
()
=>
true
case
Cons
(
x
,
Nil
())
=>
true
case
Cons
(
x
,
Cons
(
y
,
xs
))
=>
x
<
y
&&
is_sorted
(
Cons
(
y
,
xs
))
}
def
sortedIns
(
e
:
Int
,
l
:
List
)
:
List
=
(
l
match
{
case
Nil
()
=>
Cons
(
e
,
Nil
())
case
Cons
(
x
,
xs
)
if
(
x
<
e
)
=>
Cons
(
x
,
sortedIns
(
e
,
xs
))
case
_
=>
Cons
(
e
,
l
)
})
ensuring
(
res
=>
contents
(
res
)
==
contents
(
l
)
++
Set
(
e
))
def
sorted
(
l
:
List
)
:
List
=
(
l
match
{
case
Nil
()
=>
Nil
()
case
Cons
(
x
,
xs
)
=>
sortedIns
(
x
,
sorted
(
xs
))
})
ensuring
(
res
=>
contents
(
res
)
==
contents
(
l
)
&&
is_sorted
(
res
))
def
main
(
args
:
Array
[
String
])
:
Unit
=
{
val
ls
:
List
=
Cons
(
5
,
Cons
(
2
,
Cons
(
4
,
Cons
(
5
,
Cons
(
1
,
Cons
(
8
,
Nil
()))))))
println
(
ls
)
println
(
sorted
(
ls
))
}
}
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