Skip to content
Snippets Groups Projects
Commit 1aed662c authored by Alexander Gehrke's avatar Alexander Gehrke
Browse files

[lec04] readd tests

parent ab8184e8
No related branches found
No related tags found
No related merge requests found
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
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment