upTreeTraversal finished, fixed a bug in fixture parser where every node had parent set to 0

unfinished test that checks agains that error
This commit is contained in:
2026-07-20 18:15:50 +02:00
parent e89cec47d9
commit 46f9e05d63
4 changed files with 29 additions and 3 deletions
+24 -1
View File
@@ -1,8 +1,9 @@
import { FileSystem } from "@core/filesystem/filesystem";
import { TreeNodeType, type DirectoryNode, type FileNode, type TreeNode } from "@core/filesystem/treenode";
import { createImmutableBuffer } from "@core/util/immutable_buffer";
import { dnTraverseTree } from "@core/util/tree_traversal";
import { buildTestFS, type FixtureNode } from "@tests/helpers/filesystems_fixture";
import { describe, expect, it } from "vitest";
import { describe, expect, it, test } from "vitest";
const testTree: FixtureNode = {
inode: 0,
@@ -35,6 +36,28 @@ const testTree: FixtureNode = {
const fs = buildTestFS(testTree);
test("walks down the tree to check if every node has the parent set correctly", () => {
const result = dnTraverseTree(fs, 0);
const out: boolean[] = [];
let parentInode = 0;
for (const inode of result) {
const node = fs.getNode(inode) as TreeNode;
if (node.parent !== parentInode) {
console.log(node.inode);
out.push(false);
}
parentInode = node.parent;
}
console.log(out, result);
expect(out.includes(false)).toBe(false);
});
describe("FileSystem.init", () => {
const map: Map<number, TreeNode> = new Map();
const time = Date.now();
+3 -1
View File
@@ -50,7 +50,9 @@ 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]);
expect(result, `Checking the result ${result} to be [7, 6, 5, 4, 3, 2, 1, 0]`).toEqual([
7, 6, 5, 4, 3, 2, 1, 0,
]);
});
test("returns empty array for a non existent inode", () => {