Skip to content

Commit

Permalink
Fix suggestions, update branch
Browse files Browse the repository at this point in the history
  • Loading branch information
TGCrystal committed Feb 6, 2024
1 parent 0078640 commit 32ffb96
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Graph} from "math/Graph";
import {Circuit} from "./Circuit";
import {Circuit} from "../public/api/Circuit";

/**
* This function converts the provided circuit to a graph where the nodes are components and edges are wires.
Expand Down
16 changes: 2 additions & 14 deletions src/app/tests/Extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,7 @@ expect.extend({
};
},

toBeOk(received: unknown) {
if (!received || typeof received !== "object" || !("ok" in received)) {
return {
message: () => "supplied value is not a Result",
pass: false,
}
}
toBeOk(received: Result) {
const result = received as Result;
if (result.ok) {
return {
Expand All @@ -108,13 +102,7 @@ expect.extend({
}
},

toIncludeError(received: unknown, message: string) {
if (!received || typeof received !== "object" || !("ok" in received)) {
return {
message: () => "supplied value is not a Result",
pass: false,
}
}
toIncludeError(received: Result, message: string) {
const result = received as Result;
if (result.ok) {
return {
Expand Down
6 changes: 3 additions & 3 deletions src/app/tests/FirstAvailable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("FirstAvailable", () => {
test("All ports available", () => {
const circuit = CreateCircuit();

const c = circuit.placeComponentAt(V(0, 0), "Multiplexer");
const c = circuit.placeComponentAt("Multiplexer", V(0, 0));

// Case: 'output' port group
expect(c.firstAvailable("outputs")?.id).toEqual(c.ports["outputs"][0].id);
Expand All @@ -20,8 +20,8 @@ describe("FirstAvailable", () => {
test("Only some/no ports are available", () => {
const circuit = CreateCircuit();

const s1 = circuit.placeComponentAt(V(-5, 5), "Switch");
const c1 = circuit.placeComponentAt(V(0, 0), "ANDGate");
const s1 = circuit.placeComponentAt("Switch", V(-5, 5));
const c1 = circuit.placeComponentAt("ANDGate", V(0, 0));

s1.ports["outputs"][0].connectTo(c1.ports["inputs"][0]);

Expand Down
10 changes: 5 additions & 5 deletions src/app/tests/PlaceComponentAt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ describe("PlaceComponentAt", () => {
test("Basic Placement", () => {
const circuit = CreateCircuit();

const c = circuit.placeComponentAt(V(0, 0), "ANDGate");
const c = circuit.placeComponentAt("ANDGate", V(0, 0));

expect(circuit.getObjs()).toHaveLength(4); // 2 inputs, 1 output, 1 component
expect(c.pos).toEqual(V(0, 0));
});
test("Multiple Placements", () => {
const circuit = CreateCircuit();

const s1 = circuit.placeComponentAt(V(-5, 5), "Switch");
const s2 = circuit.placeComponentAt(V(-5, -5), "Switch");
const c1 = circuit.placeComponentAt(V(0, 0), "ANDGate");
const l1 = circuit.placeComponentAt(V(5, 0), "LED");
const s1 = circuit.placeComponentAt("Switch", V(-5, 5));
const s2 = circuit.placeComponentAt("Switch", V(-5, -5));
const c1 = circuit.placeComponentAt("ANDGate", V(0, 0));
const l1 = circuit.placeComponentAt("LED", V(5, 0));

expect(circuit.getObjs()).toHaveLength(2 + 2 + 4 + 2);
expect(s1.pos).toEqual(V(-5, 5));
Expand Down
10 changes: 5 additions & 5 deletions src/app/tests/SelectionsMidpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("SelectionsMidpoint", () => {
test("Single Selection", () => {
// Create and place new component
const circuit = CreateCircuit();
const s1 = circuit.placeComponentAt(V(0, 0), "ANDGate");
const s1 = circuit.placeComponentAt("ANDGate", V(0, 0));

// Select created component
s1.isSelected = true;
Expand All @@ -25,10 +25,10 @@ describe("SelectionsMidpoint", () => {
test("Multiple Selections", () => {
// Create and place new components
const circuit = CreateCircuit();
const s1 = circuit.placeComponentAt(V(-5, 5), "Switch");
const s2 = circuit.placeComponentAt(V(-5, -5), "Switch");
const c1 = circuit.placeComponentAt(V(0, 0), "ANDGate");
const l1 = circuit.placeComponentAt(V(6, 0), "LED");
const s1 = circuit.placeComponentAt("Switch", V(-5, 5));
const s2 = circuit.placeComponentAt("Switch", V(-5, -5));
const c1 = circuit.placeComponentAt("ANDGate", V(0, 0));
const l1 = circuit.placeComponentAt("LED", V(6, 0));

// Select created components
s1.isSelected = true;
Expand Down
43 changes: 0 additions & 43 deletions src/site/pages/digital/src/utils/ComponentOrganizers.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function treeToCircuitCore(node: InputTree, inputs: Map<string, DigitalComponent
const newGate = ((node.kind === "binop" && node.isNot)
? NegatedTypeToGate[node.type]
: TypeToGate[node.type]);
const newComp = circuit.placeComponentAt(V(0, 0), newGate);
const newComp = circuit.placeComponentAt(newGate, V(0, 0));
const newNode = newComp.firstAvailable("outputs");
if (!newNode)
throw new Error(`Port not found on newly created ${newComp.kind}`);
Expand Down Expand Up @@ -106,15 +106,15 @@ export function TreeToCircuit(tree: InputTree, inputs: ReadonlyMap<string, strin
output: string): DigitalCircuit {
const circuit = CreateCircuit();

const outputComp = circuit.placeComponentAt(V(0, 0), output);
const outputComp = circuit.placeComponentAt(output, V(0, 0));
outputComp.name = "Output";
const outputNode = outputComp.firstAvailable("inputs");
if (!outputNode)
throw new Error(`Input port not found on output ${outputComp.kind}`);

const inputMap = new Map<string, DigitalComponent>();
inputs.forEach((type, input) => {
const c = circuit.placeComponentAt(V(0, 0), type);
const c = circuit.placeComponentAt(type, V(0, 0));
c.name = input;
inputMap.set(input, c);
});
Expand Down

0 comments on commit 32ffb96

Please sign in to comment.