Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //test: StudentTest
- import Solution._
- import org.scalatest.FunSuite
- class StudentTest extends FunSuite {
- test("height") {
- assertResult(4) {
- val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
- height(tree)
- }
- }
- test("insert-1 Empty") {
- assertResult(Node(5, Leaf(), Leaf())) {
- insert(5, Leaf())
- }
- }
- test("insert-2 element that is already contained") {
- assertResult(Node(5, Leaf(), Leaf())) {
- insert(5, Node(5, Leaf(), Leaf()))
- }
- }
- test("insert-3 e < element") {
- assertResult(Node(5, Node(2, Node(1, Leaf(), Leaf()), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))) {
- val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
- insert(1, tree)
- }
- }
- test("insert-4 e > element") {
- assertResult(Node(5,Node(2,Leaf(),Leaf()),Node(7,Node(6,Leaf(),Leaf()),Node(9,Node(8,Leaf(),Leaf()),Node(11,Leaf(),Leaf()))))) {
- val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
- insert(8, tree)
- }
- }
- test("contains_true root") {
- assertResult(true) {
- val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
- contains(5, tree)
- }
- }
- test("contains_true inner") {
- assertResult(true) {
- val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
- contains(7, tree)
- }
- }
- test("contains_true leaf") {
- assertResult(true) {
- val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
- contains(6, tree)
- }
- }
- test("contains_false > root") {
- assertResult(false) {
- val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
- contains(100, tree)
- }
- }
- test("contains_false < root") {
- assertResult(false) {
- val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
- contains(1, tree)
- }
- }
- test("size basic") {
- assertResult(6) {
- val tree = Node(5, Node(2, Leaf(), Leaf()), Node(7, Node(6, Leaf(), Leaf()), Node(9, Leaf(), Node(11, Leaf(), Leaf()))))
- size(tree)
- }
- }
- test("size empty") {
- assertResult(0) {
- val tree = Leaf()
- size(tree)
- }
- }
- test("size only root") {
- assertResult(1) {
- val tree = Node(5, Leaf(), Leaf())
- size(tree)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement