upTraverseTree algo implementation start, doesnt work currently. basic test of the function written
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { traverseTree } from "@core/util/tree_traversal";
|
||||
import { dnTraverseTree, upTraverseTree } from "@core/util/tree_traversal";
|
||||
import { buildTestFS, type FixtureNode } from "@tests/helpers/filesystems_fixture";
|
||||
import { depth7Tree } from "@tests/helpers/tree_fixture";
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
const testTree: FixtureNode = {
|
||||
@@ -32,14 +33,27 @@ const testTree: FixtureNode = {
|
||||
};
|
||||
|
||||
const fs = buildTestFS(testTree);
|
||||
const fsTwo = buildTestFS(depth7Tree);
|
||||
|
||||
describe("traverseTree", () => {
|
||||
test("successfully traverses the tree in depth-first pre-order", () => {
|
||||
const result = traverseTree(fs, 0);
|
||||
describe("dnTraverseTree", () => {
|
||||
test("successfully traverses down the tree in depth-first pre-order", () => {
|
||||
const result = dnTraverseTree(fs, 0);
|
||||
expect(result, `Checking the result ${result} to be [0, 1, 2, 3]`).toEqual([0, 2, 3, 1]);
|
||||
});
|
||||
|
||||
test("returns empty array for a non existent root inode", () => {
|
||||
expect(traverseTree(fs, 999)).toEqual([]);
|
||||
expect(dnTraverseTree(fs, 999)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("upTraverseTree", () => {
|
||||
test("successfully traverses up the tree", () => {
|
||||
const result = upTraverseTree(fsTwo, 7);
|
||||
console.log(result);
|
||||
//expect(result, `Checking the result ${result} to be [0, 1, 2, 3]`).toEqual([0, 2, 3, 1]);
|
||||
});
|
||||
|
||||
test("returns empty array for a non existent inode", () => {
|
||||
expect(dnTraverseTree(fs, 999)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import type { FixtureNode } from "./filesystems_fixture";
|
||||
|
||||
export const depth7Tree: FixtureNode = {
|
||||
inode: 0,
|
||||
name: "root",
|
||||
type: "Dir",
|
||||
children: [
|
||||
{
|
||||
inode: 1,
|
||||
name: "d1",
|
||||
type: "Dir",
|
||||
children: [
|
||||
{
|
||||
inode: 2,
|
||||
name: "d2",
|
||||
type: "Dir",
|
||||
children: [
|
||||
{
|
||||
inode: 3,
|
||||
name: "d3",
|
||||
type: "Dir",
|
||||
children: [
|
||||
{
|
||||
inode: 4,
|
||||
name: "d4",
|
||||
type: "Dir",
|
||||
children: [
|
||||
{
|
||||
inode: 5,
|
||||
name: "d5",
|
||||
type: "Dir",
|
||||
children: [
|
||||
{
|
||||
inode: 6,
|
||||
name: "d6",
|
||||
type: "Dir",
|
||||
children: [
|
||||
{
|
||||
inode: 7,
|
||||
name: "deep_file.txt",
|
||||
type: "File",
|
||||
content: "Deepest node at depth 7",
|
||||
children: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user