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
d2a5eb79
Commit
d2a5eb79
authored
13 years ago
by
Régis Blanc
Browse files
Options
Downloads
Patches
Plain Diff
convert testcases from Map to Array
parent
3fcf0733
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
testcases/LinearSearch.scala
+13
-27
13 additions, 27 deletions
testcases/LinearSearch.scala
testcases/MaxSum.scala
+8
-40
8 additions, 40 deletions
testcases/MaxSum.scala
with
21 additions
and
67 deletions
testcases/LinearSearch.scala
+
13
−
27
View file @
d2a5eb79
...
@@ -4,29 +4,29 @@ import leon.Utils._
...
@@ -4,29 +4,29 @@ import leon.Utils._
object
LinearSearch
{
object
LinearSearch
{
def
linearSearch
(
a
:
Map
[
Int
,
Int
],
size
:
Int
,
c
:
Int
)
:
Boolean
=
({
def
linearSearch
(
a
:
Array
[
Int
]
,
c
:
Int
)
:
Boolean
=
({
require
(
size
<=
5
&&
isArray
(
a
,
size
)
)
require
(
a
.
length
>=
0
)
var
i
=
0
var
i
=
0
var
found
=
false
var
found
=
false
(
while
(
i
<
size
)
{
(
while
(
i
<
a
.
length
)
{
if
(
a
(
i
)
==
c
)
if
(
a
(
i
)
==
c
)
found
=
true
found
=
true
i
=
i
+
1
i
=
i
+
1
})
invariant
(
i
<=
size
&&
})
invariant
(
i
>=
0
&&
i
<=
a
.
length
&&
(
if
(
found
)
contains
(
a
,
i
,
c
)
else
!
contains
(
a
,
i
,
c
))
i
>=
0
&&
)
(
if
(
found
)
contains
(
a
,
i
,
c
)
else
!
contains
(
a
,
i
,
c
))
)
found
found
})
ensuring
(
res
=>
if
(
res
)
contains
(
a
,
size
,
c
)
else
!
contains
(
a
,
size
,
c
))
})
ensuring
(
res
=>
if
(
res
)
contains
(
a
,
a
.
length
,
c
)
else
!
contains
(
a
,
a
.
length
,
c
))
def
contains
(
a
:
Map
[
Int
,
Int
],
size
:
Int
,
c
:
Int
)
:
Boolean
=
{
def
contains
(
a
:
Array
[
Int
],
size
:
Int
,
c
:
Int
)
:
Boolean
=
{
require
(
isArray
(
a
,
size
)
&&
size
<=
5
)
require
(
a
.
length
>=
0
&&
size
>=
0
&&
size
<=
a
.
length
)
content
(
a
,
size
).
contains
(
c
)
content
(
a
,
size
).
contains
(
c
)
}
}
def
content
(
a
:
Array
[
Int
],
size
:
Int
)
:
Set
[
Int
]
=
{
def
content
(
a
:
Map
[
Int
,
Int
],
size
:
Int
)
:
Set
[
Int
]
=
{
require
(
a
.
length
>=
0
&&
size
>=
0
&&
size
<=
a
.
length
)
require
(
isArray
(
a
,
size
)
&&
size
<=
5
)
var
set
=
Set
.
empty
[
Int
]
var
set
=
Set
.
empty
[
Int
]
var
i
=
0
var
i
=
0
(
while
(
i
<
size
)
{
(
while
(
i
<
size
)
{
...
@@ -36,18 +36,4 @@ object LinearSearch {
...
@@ -36,18 +36,4 @@ object LinearSearch {
set
set
}
}
def
isArray
(
a
:
Map
[
Int
,
Int
],
size
:
Int
)
:
Boolean
=
{
def
rec
(
i
:
Int
)
:
Boolean
=
{
require
(
i
>=
0
)
if
(
i
>=
size
)
true
else
{
if
(
a
.
isDefinedAt
(
i
))
rec
(
i
+
1
)
else
false
}
}
if
(
size
<
0
)
false
else
rec
(
0
)
}
}
}
This diff is collapsed.
Click to expand it.
testcases/MaxSum.scala
+
8
−
40
View file @
d2a5eb79
...
@@ -4,44 +4,26 @@ import leon.Utils._
...
@@ -4,44 +4,26 @@ import leon.Utils._
object
MaxSum
{
object
MaxSum
{
def
maxSum
(
a
:
Array
[
Int
])
:
(
Int
,
Int
)
=
({
def
maxSum
(
a
:
Map
[
Int
,
Int
],
size
:
Int
)
:
(
Int
,
Int
)
=
({
require
(
a
.
length
>=
0
&&
isPositive
(
a
))
require
(
isArray
(
a
,
size
)
&&
size
<
5
&&
isPositive
(
a
,
size
))
var
sum
=
0
var
sum
=
0
var
max
=
0
var
max
=
0
var
i
=
0
var
i
=
0
(
while
(
i
<
size
)
{
(
while
(
i
<
a
.
length
)
{
if
(
max
<
a
(
i
))
if
(
max
<
a
(
i
))
max
=
a
(
i
)
max
=
a
(
i
)
sum
=
sum
+
a
(
i
)
sum
=
sum
+
a
(
i
)
i
=
i
+
1
i
=
i
+
1
})
invariant
(
sum
<=
i
*
max
&&
/*isGreaterEq(a, i, max) &&*/
/*(if(i == 0) max == 0 else true) &&*/
i
>=
0
&&
i
<=
size
)
})
invariant
(
sum
<=
i
*
max
&&
i
>=
0
&&
i
<=
a
.
length
)
(
sum
,
max
)
(
sum
,
max
)
})
ensuring
(
res
=>
res
.
_1
<=
size
*
res
.
_2
)
})
ensuring
(
res
=>
res
.
_1
<=
a
.
length
*
res
.
_2
)
/*
def isGreaterEq(a: Map[Int, Int], size: Int, n: Int): Boolean = {
require(size <= 5 && isArray(a, size))
def rec(i: Int): Boolean = {
require(i >= 0)
if(i >= size)
true
else {
if(a(i) > n)
false
else
rec(i+1)
}
}
rec(0)
}
*/
def
isPositive
(
a
:
Map
[
Int
,
Int
],
size
:
Int
)
:
Boolean
=
{
def
isPositive
(
a
:
Array
[
Int
]
)
:
Boolean
=
{
require
(
size
<=
5
&&
isArray
(
a
,
size
)
)
require
(
a
.
length
>=
0
)
def
rec
(
i
:
Int
)
:
Boolean
=
{
def
rec
(
i
:
Int
)
:
Boolean
=
{
require
(
i
>=
0
)
require
(
i
>=
0
)
if
(
i
>=
size
)
if
(
i
>=
a
.
length
)
true
true
else
{
else
{
if
(
a
(
i
)
<
0
)
if
(
a
(
i
)
<
0
)
...
@@ -53,18 +35,4 @@ object MaxSum {
...
@@ -53,18 +35,4 @@ object MaxSum {
rec
(
0
)
rec
(
0
)
}
}
def
isArray
(
a
:
Map
[
Int
,
Int
],
size
:
Int
)
:
Boolean
=
{
def
rec
(
i
:
Int
)
:
Boolean
=
{
require
(
i
>=
0
)
if
(
i
>=
size
)
true
else
{
if
(
a
.
isDefinedAt
(
i
))
rec
(
i
+
1
)
else
false
}
}
if
(
size
<
0
)
false
else
rec
(
0
)
}
}
}
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