Skip to content

Commit

Permalink
Merge branch '29-using-vitest-for-unit-testing' of https://github.com…
Browse files Browse the repository at this point in the history
…/RAIRLab/Peirce-My-Heart into 29-using-vitest-for-unit-testing
  • Loading branch information
RyanR712 committed Oct 8, 2023
2 parents bbe7b0e + b165787 commit 96f26ff
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 33 deletions.
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "msedge",
"name": "Edge Vite Debug",
"request": "launch",
"url": "http://localhost:5173/",
"webRoot": "${workspaceFolder}/src"
},
{
"type": "chrome",
"request": "launch",
Expand Down
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"jamesoswald",
"peaceiris",
"peircemyheart",
"radx",
"rady",
"styleguidelines",
"Subrina",
"Tiwari",
Expand Down
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
"typescript": "~5.2.2",
"vite": "^4.4.9",
"vitest": "^0.34.6"
},
"dependencies": {
"nomial": "^1.0.11"
}
}
13 changes: 10 additions & 3 deletions src/AEG/AEGTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ export class AEGTree {
}

/**
* Checks whether the given node can be inserted into this tree
* without overlapping any bounding boxes.
* Method that checks whether the given node can be inserted into this tree
* at a given point without overlapping any bounding boxes.
* @param incomingNode The node to be inserted.
* @returns True, if the node can be inserted. Else, false
*/
public canInsert(incomingNode: AtomNode | CutNode): boolean {
console.log("checking can insert");
const currentCut: CutNode = this.sheet.getCurrentCut(incomingNode);
for (let i = 0; i < currentCut.children.length; i++) {
if (this.overlaps(incomingNode, currentCut.children[i])) {
Expand All @@ -81,7 +82,9 @@ export class AEGTree {
}

const currentCut: CutNode = this.sheet.getCurrentCut(incomingNode);
const originalChildren: (AtomNode | CutNode)[] = currentCut.children;
//const originalChildren: (AtomNode | CutNode)[] = currentCut.children;
//==============CHANGEDDDD=========
const originalChildren: (AtomNode | CutNode)[] = [...currentCut.children];
currentCut.children.push(incomingNode);

if (incomingNode instanceof CutNode) {
Expand Down Expand Up @@ -134,4 +137,8 @@ export class AEGTree {
}
}
}

public toString(): string {
return this.sheet.toFormulaString();
}
}
37 changes: 31 additions & 6 deletions src/AEG/CutNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import {Point} from "./Point";
* Class that defines a Cut in AEGTree.
* @author Anusha Tiwari
* @author Ryan Reilly
* @author James Oswald
*/
export class CutNode {
/**
* The boundary of this node.
*/
ellipse: Ellipse | null; //Null for sheet
ellipse: Ellipse | null; //Null for sheet of assertion

/**
* Contains the list of child nodes nested within this node.
Expand All @@ -35,9 +36,12 @@ export class CutNode {
*/
public getCurrentCut(newNode: CutNode | AtomNode): CutNode {
for (let i = 0; i < this.children.length; i++) {
if (this.children[i] instanceof CutNode && this.children[i].containsNode(newNode)) {
const child: CutNode | AtomNode = this.children[i];
if (child instanceof CutNode && this.children[i].containsNode(newNode)) {
//======DEBUGGG=======
console.log("current cut: " + this.children[i]);
//newNode can be placed at least one layer deeper
return this.getCurrentCut(this.children[i]);
return child.getCurrentCut(newNode);
}
}
return this; //we are at the deepest valid level that newNode can be placed
Expand Down Expand Up @@ -71,10 +75,12 @@ export class CutNode {
}

if (otherNode instanceof AtomNode) {
return this.ellipse.containsShape((otherNode as AtomNode).rect);
} else {
return this.ellipse.containsShape(otherNode.rect);
} else if (otherNode instanceof CutNode) {
//ELLIPSE TO BE IMPLEMENTED ACCURATELY
return this.ellipse.containsShape((otherNode as CutNode).ellipse as Ellipse);
return this.ellipse.containsShape(otherNode.ellipse as Ellipse);
} else {
throw Error("containsNode expected AtomNode or CutNode");
}
}

Expand Down Expand Up @@ -130,4 +136,23 @@ export class CutNode {
}
return str;
}

public toFormulaString(): string {
let formulaString = "";
for (const child of this.children) {
if (child instanceof AtomNode) {
formulaString += child.identifier;
} else if (child instanceof CutNode) {
formulaString += child.toFormulaString();
}
formulaString += " ";
}
formulaString = formulaString.slice(0, -1);
if (this.ellipse === null) {
formulaString = "[" + formulaString + "]";
} else {
formulaString = "(" + formulaString + ")";
}
return formulaString;
}
}
Loading

0 comments on commit 96f26ff

Please sign in to comment.