Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //test: ListExerciseTests
- class ListExerciseTests extends org.scalatest.Suite {
- import ListFuns._
- def testSumNil {
- expect(0) { sum(Nil()) }
- }
- def testSum2 {
- expect(3) { sum(Cons(1,Cons(2,Nil())))}
- }
- def testLengthNil {
- expect(0) { length(Nil()) }
- }
- def testLength2 {
- expect(2) { length(Cons(2,Cons(3,Nil()))) }
- }
- def testMapNil {
- expect(Nil()) {
- map(Nil(), ((x: Int) => (x + 1)))
- }
- }
- def testMap2 {
- expect(Cons(9,Cons(4,Nil()))) {
- map(Cons(3,Cons(2,Nil())),((x: Int) => x*x))
- }
- }
- def testFilterNil {
- expect(Nil()) {
- filter(Nil(), ((x: Int) => x % 2 == 1))
- }
- }
- def testFilter2 {
- expect(Cons(4,Cons(3,Nil()))) {
- filter(Cons(4,Cons(8,Cons(3,Nil()))), ((x: Int) => x < 5))
- }
- }
- def testAppendNil {
- expect(Nil()) {
- append(Nil(), Nil())
- }
- }
- def testAppend() {
- expect(Cons(3,Cons(4,Cons(5,Nil())))) {
- append(Cons(3,Nil()),Cons(4,Cons(5,Nil())))
- }
- }
- def testFlatMapNil {
- expect(Nil()) {
- flatMap(Nil(), (x: Int) => Nil())
- }
- }
- def testFlatMap2 {
- expect(Cons(9,Cons(4,Nil()))) {
- flatMap(Cons(3,Cons(2,Nil())),(x : Int) => Cons(x*x,Nil()))
- }
- }
- def testMaximumNil {
- expect(Int.MinValue) {
- maximum(Nil())
- }
- }
- def testMaximum2 {
- expect(4) {
- maximum(Cons(1,Cons(2,Cons(3,Cons(4,Nil())))))
- }
- }
- def testReverseNil {
- expect(Nil()) {
- reverse(Nil())
- }
- }
- def testReverse2 {
- expect(Cons(3,Cons(2,Cons(1,Nil())))) {
- reverse(Cons(1,Cons(2,Cons(3,Nil()))))
- }
- }
- def testZipWithNil {
- expect(Nil()) {
- zipWith(Nil(), Nil(), (x, y) => 3)
- }
- }
- def testZipWidth2 {
- expect(Cons(5,Cons(3,Nil()))) {
- zipWith(Cons(3,Cons(1,Nil())),Cons(2,Cons(2,Nil())), (x : Int, y : Int) => x+y)
- }
- }
- def testFromUntilNil {
- expect(Nil()) { fromUntil(6,5) }
- }
- def testFromUntil {
- expect(Cons(3,Cons(4,Cons(5,Nil())))) {
- fromUntil(3,5)
- }
- }
- }//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement