Advertisement
ultiprosan

Tests Scala assignments for Tom

Mar 5th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 2.09 KB | None | 0 0
  1. //test: ListExerciseTests
  2.  
  3. class ListExerciseTests extends org.scalatest.Suite {
  4.   import ListFuns._
  5.  
  6.   def testSumNil {
  7.     expect(0) { sum(Nil()) }
  8.   }
  9.   def testSum2 {
  10.     expect(3) { sum(Cons(1,Cons(2,Nil())))}
  11.   }
  12.  
  13.   def testLengthNil {
  14.     expect(0) { length(Nil()) }
  15.   }  
  16.   def testLength2 {
  17.     expect(2) { length(Cons(2,Cons(3,Nil()))) }
  18.   }
  19.  
  20.   def testMapNil {
  21.     expect(Nil()) {
  22.       map(Nil(), ((x: Int) => (x + 1)))
  23.     }
  24.   }
  25.   def testMap2 {
  26.     expect(Cons(9,Cons(4,Nil()))) {
  27.       map(Cons(3,Cons(2,Nil())),((x: Int) => x*x))
  28.     }
  29.   }
  30.  
  31.   def testFilterNil {
  32.     expect(Nil()) {
  33.       filter(Nil(), ((x: Int) => x % 2 == 1))
  34.     }
  35.   }
  36.   def testFilter2 {
  37.     expect(Cons(4,Cons(3,Nil()))) {
  38.       filter(Cons(4,Cons(8,Cons(3,Nil()))), ((x: Int) => x < 5))
  39.     }    
  40.   }
  41.  
  42.   def testAppendNil {
  43.     expect(Nil()) {
  44.       append(Nil(), Nil())
  45.     }
  46.   }
  47.   def testAppend() {
  48.     expect(Cons(3,Cons(4,Cons(5,Nil())))) {
  49.       append(Cons(3,Nil()),Cons(4,Cons(5,Nil())))
  50.     }
  51.   }
  52.  
  53.   def testFlatMapNil {
  54.     expect(Nil()) {
  55.       flatMap(Nil(), (x: Int) => Nil())
  56.     }
  57.   }
  58.   def testFlatMap2 {
  59.     expect(Cons(9,Cons(4,Nil()))) {
  60.       flatMap(Cons(3,Cons(2,Nil())),(x : Int) => Cons(x*x,Nil()))
  61.     }
  62.   }
  63.  
  64.   def testMaximumNil {
  65.     expect(Int.MinValue) {
  66.       maximum(Nil())
  67.     }
  68.   }
  69.   def testMaximum2 {
  70.     expect(4) {
  71.       maximum(Cons(1,Cons(2,Cons(3,Cons(4,Nil())))))
  72.     }
  73.   }
  74.  
  75.   def testReverseNil {
  76.     expect(Nil()) {
  77.       reverse(Nil())
  78.     }
  79.   }
  80.   def testReverse2 {
  81.     expect(Cons(3,Cons(2,Cons(1,Nil())))) {
  82.       reverse(Cons(1,Cons(2,Cons(3,Nil()))))
  83.     }
  84.   }
  85.  
  86.   def testZipWithNil {
  87.     expect(Nil()) {
  88.       zipWith(Nil(), Nil(), (x, y) => 3)
  89.     }
  90.   }
  91.   def testZipWidth2 {
  92.     expect(Cons(5,Cons(3,Nil()))) {
  93.       zipWith(Cons(3,Cons(1,Nil())),Cons(2,Cons(2,Nil())), (x : Int, y : Int) => x+y)
  94.     }
  95.   }
  96.  
  97.   def testFromUntilNil {
  98.     expect(Nil()) { fromUntil(6,5) }
  99.   }
  100.   def testFromUntil {
  101.     expect(Cons(3,Cons(4,Cons(5,Nil())))) {
  102.       fromUntil(3,5)
  103.     }
  104.   }
  105. }//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement