Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
short-exercises
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
Container 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
Tilman Voit
short-exercises
Commits
1aed662c
Commit
1aed662c
authored
5 years ago
by
Alexander Gehrke
Browse files
Options
Downloads
Patches
Plain Diff
[lec04] readd tests
parent
ab8184e8
No related branches found
Branches containing commit
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/laziness/StreamSpec.scala
+44
-0
44 additions, 0 deletions
src/test/scala/laziness/StreamSpec.scala
with
44 additions
and
0 deletions
src/test/scala/laziness/StreamSpec.scala
0 → 100644
+
44
−
0
View file @
1aed662c
package
laziness
import
org.scalatest._
import
testutil.PendingIfUnimplemented
class
StreamSpec
extends
FlatSpec
with
Matchers
with
AppendedClues
with
PendingIfUnimplemented
{
import
Stream._
/*
* Note that equivalence checking on streams does not work.
* Therefore it is important, that your toList implementation works for most later tests.
*/
"A stream"
should
"be convertable to a list"
in
{
Stream
(
1
,
2
,
3
).
toList
shouldBe
List
(
1
,
2
,
3
)
Stream
.
empty
.
toList
shouldBe
List
()
}
it
should
"have a take method that keeps only a certain number of elements"
in
{
ones
.
take
(
1
).
toList
shouldBe
List
(
1
)
ones
.
take
(
23
).
toList
should
have
size
23
}
it
should
"have a drop method that removes a certain number of elements from the start"
in
{
Stream
(
1
,
2
,
3
,
4
).
drop
(
1
).
toList
shouldBe
List
(
2
,
3
,
4
)
ones
.
drop
(
17
).
headOption
should
contain
(
1
)
}
"the fibs method"
should
"be able to generate fibonacci numbers"
in
{
fibs
.
take
(
8
).
toList
shouldBe
List
(
0
,
1
,
1
,
2
,
3
,
5
,
8
,
13
)
}
"unfold"
should
"should generate streams from a function while stopping on None"
in
{
val
alphabet
=
unfold
(
'a'
)(
s
=>
if
(
s
<=
'z'
)
Some
((
s
,
(
s
+
1
).
toChar
))
else
None
)
alphabet
.
toList
shouldBe
(
'a'
to
'z'
).
toList
}
"fibsViaUnfold"
should
"result in the same values as fibs without unfold"
in
{
fibsViaUnfold
.
take
(
10
).
toList
shouldBe
fibs
.
take
(
10
).
toList
}
}
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