Advertisement
VladNitu

Tests

Feb 15th, 2023
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 3.49 KB | None | 0 0
  1. //test: StudentTest
  2.  
  3. import org.scalatest.FunSuite
  4. import Solution._
  5.  
  6. class StudentTest extends FunSuite {
  7.  
  8.   test("listFrom") {
  9.     assertResult(Element(3, Element(2, Element(1, Empty())))) {
  10.       listFrom(3)
  11.     }
  12.   }
  13.  
  14.   test("listFromEdge") {
  15.     assertResult(Empty()) {
  16.       listFrom(0)
  17.     }
  18.   }
  19.  
  20.   test("sumIntList") {
  21.     assertResult(10) {
  22.       sumIntList(Element(1, Element(2, Element(3, Element(4, Empty())))))
  23.     }
  24.   }
  25.  
  26.   test("sumIntListEdge") {
  27.     assertResult(0) {
  28.       sumIntList(Empty())
  29.     }
  30.   }
  31.  
  32.   test("headEdge") {
  33.     assertThrows[NoSuchElementException] { // alternative: intercept[NoSuchElementException]
  34.       head(Empty())
  35.     }
  36.   }
  37.  
  38.   test("head") {
  39.     assertResult(1) {
  40.       head(Element(1, Element(2, Element(3, Empty()))))
  41.     }
  42.   }
  43.  
  44.   test("tailEdge") {
  45.     assertThrows[NoSuchElementException] { // alternative: intercept[NoSuchElementException]
  46.       tail(Empty())
  47.     }
  48.   }
  49.  
  50.   test("tail") {
  51.     assertResult(Element(2, Element(3, Empty()))) {
  52.       tail(Element(1, Element(2, Element(3, Empty()))))
  53.     }
  54.   }
  55.  
  56.  
  57.   test("Head empty") {
  58.     intercept[NoSuchElementException] {
  59.       head(Empty())
  60.     }
  61.   }
  62.  
  63.   test("Tail") {
  64.     assertResult(Element(3, Empty())) {
  65.       tail(Element(34, Element(3, Empty())))
  66.     }
  67.   }
  68.  
  69.  
  70.   test("Concat more elements xs.size() > ys.size()") {
  71.     assertResult(Element(34, Element(3, Element(6, Empty())))) {
  72.       concat(Element(34, Element(3, Empty())), Element(6, Empty()))
  73.     }
  74.   }
  75.  
  76.   test("Concat more elements xs.size() < ys.size()") {
  77.     assertResult(Element(3, Element(34, Element(6, Empty())))) {
  78.       concat(Element(3, Empty()), Element(34, Element(6, Empty())))
  79.     }
  80.   }
  81.  
  82.   test("Concat more elements xs.size() == ys.size()") {
  83.     assertResult(Element(1, Element(6, Empty()))) {
  84.       concat(Element(1, Empty()), Element(6, Empty()))
  85.     }
  86.   }
  87.  
  88.   test("Concat xs Nil") {
  89.     assertResult(Element(6, Empty())) {
  90.       concat(Empty(), Element(6, Empty()))
  91.     }
  92.   }
  93.  
  94.   test("Concat ys Nil") {
  95.     assertResult(Element(6, Empty())) {
  96.       concat(Element(6, Empty()), Empty())
  97.     }
  98.   }
  99.  
  100.   test("Concat both xs & ys Nils") {
  101.     assertResult(Empty()) {
  102.       concat(Empty(), Empty())
  103.     }
  104.   }
  105.  
  106.   test("take n > size()") {
  107.     assertResult(Element(34, Element(3, Element(6, Empty())))) {
  108.       take(10, Element(34, Element(3, Element(6, Empty()))))
  109.     }
  110.   }
  111.  
  112.   test("take n == size()") {
  113.     assertResult(Element(34, Element(3, Element(6, Empty())))) {
  114.       take(3, Element(34, Element(3, Element(6, Empty()))))
  115.     }
  116.   }
  117.  
  118.   test("take n < size()") {
  119.     assertResult(Element(34, Element(3, Empty()))) {
  120.       take(2, Element(34, Element(3, Element(6, Empty()))))
  121.      
  122.     }
  123.   }
  124.  
  125.   test("take n == 1") {
  126.     assertResult(Element(34, Empty())) {
  127.       take(1, Element(34, Element(3, Element(6, Empty()))))
  128.      
  129.     }
  130.   }
  131.  
  132.  
  133.   test("drop n == 0") {
  134.     assertResult(Element(34, Element(3, Element(6, Empty())))) {
  135.       drop(0, Element(34, Element(3, Element(6, Empty()))))
  136.     }
  137.   }
  138.  
  139.   test("drop n == 1") {
  140.     assertResult(Element(3, Element(6, Empty()))) {
  141.       drop(1, Element(34, Element(3, Element(6, Empty()))))
  142.     }
  143.   }
  144.  
  145.   test("drop n == size()") {
  146.     assertResult(Empty()) {
  147.       drop(3, Element(34, Element(3, Element(6, Empty()))))
  148.     }
  149.   }
  150.  
  151.    test("drop n > size()") { // same behavior as n == size()
  152.     assertResult(Empty()) {
  153.       drop(4, Element(34, Element(3, Element(6, Empty()))))
  154.     }
  155.   }
  156. }
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement