Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ implements ReLinkContainer<T, P> {
return res; //todo behaviour of flag different to add??
}

override delete(mode: DeletionMode = DeletionMode.RELAXED): void {
while (this._instance.length > 0) {
this.remove(this._instance[0], mode);
}
}

removeFromInverse(item: T, mode: DeletionMode = DeletionMode.RELAXED): boolean {
if(this.inverseName !== undefined) {
for (const child of [...this._instance]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {Middle2WithChildren, ReChild3, RootWithChildren} from "./referencables-with-children";
import {DeletionMode} from "../../utils/deletion-mode";

describe('ReContainer delete tests', () => {
it("should relaxed delete re-tree-container correctly", () =>{
let root = new RootWithChildren();
let child1 = new ReChild3();
let child2 = new ReChild3();
let middle = new Middle2WithChildren();
root.link3.push(child1,child2);
middle.child3.push(child1,child2);
expect(root.link3.length).toBe(2);
expect(child1.link1).toContain(root);
expect(child2.link1).toContain(root);
expect(middle.child3.length).toBe(2);
expect(child1.parentPointer).toEqual(middle);
expect(child2.parentPointer).toEqual(middle);
middle.child3.delete();
expect(root.link3.length).toBe(2);
expect(middle.child3.length).toBe(0);
expect(child1.parentPointer).toBeUndefined();
expect(child2.parentPointer).toBeUndefined();
})

it("should cascade delete re-tree-container correctly", () =>{
let root = new RootWithChildren();
let child1 = new ReChild3();
let child2 = new ReChild3();
let middle = new Middle2WithChildren();
root.link3.push(child1,child2);
middle.child3.push(child1,child2);
expect(root.link3.length).toBe(2);
expect(child1.link1).toContain(root);
expect(child2.link1).toContain(root);
expect(middle.child3.length).toBe(2);
expect(child1.parentPointer).toEqual(middle);
expect(child2.parentPointer).toEqual(middle);
middle.child3.delete();
expect(root.link3.length).toBe(2);
expect(middle.child3.length).toBe(0);
expect(child1.parentPointer).toBeUndefined();
expect(child2.parentPointer).toBeUndefined();
})

it("should delete re-list-container correctly", () =>{
let root = new RootWithChildren();
let child1 = new ReChild3();
let child2 = new ReChild3();
let middle = new Middle2WithChildren();
root.link3.push(child1,child2);
middle.child3.push(child1,child2);
expect(root.link3.length).toBe(2);
expect(child1.link1).toContain(root);
expect(child2.link1).toContain(root);
expect(middle.child3.length).toBe(2);
expect(child1.parentPointer).toEqual(middle);
expect(child2.parentPointer).toEqual(middle);
root.link3.delete();
expect(root.link3.length).toBe(0);
expect(middle.child3.length).toBe(2);
expect(child1.parentPointer).toBeDefined();
expect(child2.parentPointer).toBeDefined();
})
});