Advertisement
VladNitu

Tests #2

Feb 15th, 2023
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 2.79 KB | None | 0 0
  1. //test: StudentTest
  2.  
  3. import Solution._
  4. import org.scalatest.FunSuite
  5.  
  6. class StudentTest extends FunSuite {
  7.  
  8.   test("height") {
  9.     assertResult(4) {
  10.       val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
  11.       height(tree)
  12.     }
  13.   }
  14.  
  15.   test("insert-1 Empty") {
  16.     assertResult(Node(5, Leaf(), Leaf())) {
  17.       insert(5, Leaf())
  18.     }
  19.   }
  20.  
  21.   test("insert-2 element that is already contained") {
  22.     assertResult(Node(5, Leaf(), Leaf())) {
  23.       insert(5, Node(5, Leaf(), Leaf()))
  24.     }
  25.   }
  26.  
  27.   test("insert-3 e < element") {
  28.     assertResult(Node(5, Node(2, Node(1, Leaf(), Leaf()), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))) {
  29.  
  30.       val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
  31.       insert(1, tree)
  32.     }
  33.   }
  34.  
  35.   test("insert-4 e > element") {
  36.     assertResult(Node(5,Node(2,Leaf(),Leaf()),Node(7,Node(6,Leaf(),Leaf()),Node(9,Node(8,Leaf(),Leaf()),Node(11,Leaf(),Leaf()))))) {
  37.  
  38.       val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
  39.       insert(8, tree)
  40.     }
  41.   }
  42.  
  43.   test("contains_true root") {
  44.     assertResult(true) {
  45.       val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
  46.       contains(5, tree)
  47.     }
  48.   }
  49.  
  50.   test("contains_true inner") {
  51.     assertResult(true) {
  52.       val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
  53.       contains(7, tree)
  54.     }
  55.   }
  56.  
  57.   test("contains_true leaf") {
  58.     assertResult(true) {
  59.       val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
  60.       contains(6, tree)
  61.     }
  62.   }
  63.  
  64.   test("contains_false > root") {
  65.     assertResult(false) {
  66.       val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
  67.       contains(100, tree)
  68.     }
  69.   }
  70.  
  71.   test("contains_false < root") {
  72.     assertResult(false) {
  73.       val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
  74.       contains(1, tree)
  75.     }
  76.   }
  77.  
  78.   test("size basic") {
  79.     assertResult(6) {
  80.       val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
  81.       size(tree)
  82.     }
  83.   }
  84.  
  85.   test("size empty") {
  86.     assertResult(0) {
  87.       val tree = Leaf()
  88.       size(tree)
  89.     }
  90.   }
  91.  
  92.   test("size only root") {
  93.     assertResult(1) {
  94.       val tree = Node(5, Leaf(), Leaf())
  95.       size(tree)
  96.     }
  97.   }
  98.  
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement