Created
August 20, 2022 05:37
-
-
Save hawaijar/67fd4c69d441407fd8e9c5c159bd716a to your computer and use it in GitHub Desktop.
BinaryTreeTraversal Test cases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
BinaryTreeNode, | |
insertLevelOrder, | |
preOrder, | |
inOrder, | |
postOrder, | |
} from "../BinaryTree"; | |
let array1 = [1, 2, 3, 4, 5, 6, 7]; | |
let array2 = [1, 2, 3, 4, 5, 6, 6, 6, 6]; | |
let array3 = [12, 23, 12, 14, 14, 17, 90]; | |
let array4 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4]; | |
let array5 = [11, 22, 33, 1, 2, 3, 4, 5, 6, 7, 90, 100, 12]; | |
describe("preOrder - traversal", () => { | |
let root = insertLevelOrder(array1); | |
it("should display pre-order of array1", () => { | |
expect(preOrder(root)).toEqual([1, 2, 4, 5, 3, 6, 7]); | |
}); | |
it("should display pre-order of array2", () => { | |
root = insertLevelOrder(array2); | |
expect(preOrder(root)).toEqual([1, 2, 4, 6, 6, 5, 3, 6, 6]); | |
}); | |
it("should display pre-order of array3", () => { | |
root = insertLevelOrder(array3); | |
expect(preOrder(root)).toEqual([12, 23, 14, 14, 12, 17, 90]); | |
}); | |
it("should display pre-order of array4", () => { | |
root = insertLevelOrder(array4); | |
expect(preOrder(root)).toEqual([1, 2, 4, 8, 9, 5, 10, 1, 3, 6, 2, 3, 7, 4]); | |
}); | |
it("should display pre-order of array5", () => { | |
root = insertLevelOrder(array5); | |
expect(preOrder(root)).toEqual([ | |
11, 22, 1, 5, 6, 2, 7, 90, 33, 3, 100, 12, 4, | |
]); | |
}); | |
}); | |
describe("inOrder - traversal", () => { | |
let root = insertLevelOrder(array1); | |
it("should display in-order of array1", () => { | |
expect(inOrder(root)).toEqual([4, 2, 5, 1, 6, 3, 7]); | |
}); | |
it("should display in-order of array2", () => { | |
root = insertLevelOrder(array2); | |
expect(inOrder(root)).toEqual([6, 4, 6, 2, 5, 1, 6, 3, 6]); | |
}); | |
it("should display in-order of array3", () => { | |
root = insertLevelOrder(array3); | |
expect(inOrder(root)).toEqual([14, 23, 14, 12, 17, 12, 90]); | |
}); | |
}); | |
describe("postOrder - traversal", () => { | |
let root = insertLevelOrder(array1); | |
it("should display post-order of array1", () => { | |
expect(postOrder(root)).toEqual([4, 5, 2, 6, 7, 3, 1]); | |
}); | |
it("should display post-order of array2", () => { | |
root = insertLevelOrder(array2); | |
expect(postOrder(root)).toEqual([6, 6, 4, 5, 2, 6, 6, 3, 1]); | |
}); | |
it("should display post-order of array3", () => { | |
root = insertLevelOrder(array3); | |
expect(postOrder(root)).toEqual([14, 14, 23, 17, 90, 12, 12]); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment