-
-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model refactor api expr to circ #1238
Changes from 28 commits
a4fb430
2cc1949
daf7d00
e698b47
4085471
b290cf7
f237b81
a319216
2e74a00
19f1f60
89267df
320bbf8
818cfb6
2c8b5c4
82d736c
c38943c
7168f31
1227b7a
4d12152
c49e0bd
1fdb90d
258df28
0f0859b
ba6df30
274499c
095f0da
bb321ff
3ef208b
0078640
32ffb96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {Graph} from "math/Graph"; | ||
import {Circuit} from "./Circuit"; | ||
|
||
/** | ||
* This function converts the provided circuit to a graph where the nodes are components and edges are wires. | ||
* Both are represented by guids rather than object references. | ||
* | ||
* @param circuit The circuit to convert to a graph. | ||
* @returns The provided circuit as a graph. | ||
*/ | ||
export function CreateGraph(circuit: Circuit): Graph<string, string> { | ||
const graph = new Graph<string, string>(); | ||
|
||
const objs = circuit.getComponents(); | ||
for (const obj of objs) { | ||
graph.createNode(obj.id); | ||
} | ||
const wires = circuit.getWires(); | ||
for (const wire of wires) { | ||
graph.createEdge(wire.p1.parent.id, wire.p2.parent.id, wire.id); | ||
} | ||
|
||
return graph; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Checks if the substring of a given input starting at a given index is equal to a given sequence. | ||
* | ||
* @param input The input string that a substring of will be examined. | ||
* @param index The starting index of input to compare at. | ||
* @param sequence The sequence to check equality with. | ||
* @returns True if input has a substring starting at index that matches sequence, false otherwise. | ||
*/ | ||
export function SubStrEquals(input: string, index: number, sequence: string): boolean { | ||
return input.slice(index, index + sequence.length) === sequence; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import crypto from "node:crypto"; | ||
import {Result} from "core/utils/Result"; | ||
import crypto from "node:crypto"; | ||
|
||
|
||
// Define crypto for Jest for uuid generation | ||
|
@@ -11,6 +12,8 @@ declare global { | |
interface Matchers<R> { | ||
toApproximatelyEqual(expected: unknown, epsilon?: number): CustomMatcherResult; | ||
toBeCloseToAngle(otherAngle: number, epsilon?: number): CustomMatcherResult; | ||
toBeOk(): CustomMatcherResult; | ||
toIncludeError(message: string): CustomMatcherResult; | ||
// toBeConnectedTo(a: DigitalComponent, options?: {depth?: number}): CustomMatcherResult; | ||
} | ||
} | ||
|
@@ -81,40 +84,52 @@ expect.extend({ | |
}; | ||
}, | ||
|
||
// toBeConnectedTo(source: unknown, target: DigitalComponent, options = { depth: Infinity }) { | ||
// if (!(source instanceof DigitalComponent)) | ||
// throw new Error("toBeConnectedTo can only be used with DigitalComponents!"); | ||
|
||
// const { depth } = options; | ||
|
||
// const visited = new Set<DigitalComponent>(); | ||
// function bfs(layer: DigitalComponent[], depth: number): boolean { | ||
// if (depth === 0 || layer.length === 0) | ||
// return false; | ||
|
||
// const queue = [] as DigitalComponent[]; | ||
// for (const cur of layer) { | ||
// visited.add(cur); | ||
|
||
// const connections = [ | ||
// ...cur.getOutputs().map((w) => w.getOutputComponent()), | ||
// ...cur.getInputs().map((w) => w.getInputComponent()), | ||
// ].filter((c) => !visited.has(c)); | ||
|
||
// if (connections.includes(target)) | ||
// return true; | ||
|
||
// queue.push(...connections); | ||
// } | ||
// return bfs(queue, depth-1); | ||
// } | ||
|
||
// const pass = bfs([source], depth); | ||
toBeOk(received: unknown) { | ||
if (!received || typeof received !== "object" || !("ok" in received)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just say |
||
return { | ||
message: () => "supplied value is not a Result", | ||
pass: false, | ||
} | ||
} | ||
const result = received as Result; | ||
if (result.ok) { | ||
return { | ||
message: () => "expected Result to be Ok", | ||
pass: true, | ||
} | ||
} | ||
return { | ||
message: () => `expected Result to not have errors:\n - ${ | ||
result.error.errors | ||
.map((err) => err.message) | ||
.join("\n - ") | ||
}`, | ||
pass: false, | ||
} | ||
}, | ||
|
||
// return { | ||
// message: () => `expected ${source.getName()} to ${pass ? "" : "not "}be connected to ${target.getName()}` + | ||
// ` within ${options.depth} connections`, | ||
// pass, | ||
// }; | ||
// }, | ||
toIncludeError(received: unknown, message: string) { | ||
if (!received || typeof received !== "object" || !("ok" in received)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
return { | ||
message: () => "supplied value is not a Result", | ||
pass: false, | ||
} | ||
} | ||
const result = received as Result; | ||
if (result.ok) { | ||
return { | ||
message: () => "expected Result to be not be Ok", | ||
pass: false, | ||
} | ||
} | ||
return { | ||
message: () => `expected Result to contain an error including the text "${message}", ` + | ||
`instead includes:\n - ${ | ||
result.error.errors | ||
.map((err) => err.message) | ||
.join("\n - ") | ||
}`, | ||
pass: result.error.errors.some((error) => error.message.includes(message)), | ||
} | ||
}, | ||
}); |
TGCrystal marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// TODO[model_refactor_api](trevor): Get this working for expression to circuit frontend | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not get this working now ? |
||
// import {Vector} from "Vector"; | ||
|
||
// import {CreateGraph, IOObjectSet} from "./ComponentUtils"; | ||
|
||
|
||
// const ORGANIZE_SEP_X = 4; | ||
// const ORGANIZE_SEP_Y = 3; | ||
|
||
// function OrganizeCore(groups: IOObjectSet, start: Vector, depths: number[][]): void { | ||
// // Depths is a 2d array where the index of the inner array indicates the depth of all of the nodes inside that array | ||
// const components = groups.getComponents(); | ||
|
||
// depths.forEach((nodes, depth) => | ||
// nodes.forEach((node, index) => | ||
// // extra space for labels | ||
// components[node].setPos(start.add(ORGANIZE_SEP_X*(depth - (depths.length - 1)/2) + ORGANIZE_SEP_X/2, | ||
// -ORGANIZE_SEP_Y*(index - (nodes.length - 1)/2))) | ||
// ) | ||
// ); | ||
// } | ||
|
||
// /** | ||
// * Organizes the components so that components at greater depth are further to the right, | ||
// * using the getMaxNodeDepths function of Graph to accomplish this. | ||
// * | ||
// * @param groups The components to organize. | ||
// * @param start The top left coordinate where the organization should start. | ||
// */ | ||
// export function OrganizeMaxDepth(groups: IOObjectSet, start: Vector): void { | ||
// OrganizeCore(groups, start, CreateGraph(groups).getMaxNodeDepths()); | ||
// } | ||
|
||
// /** | ||
// * Organizes the components so that components at greater depth are further to the right, | ||
// * using the getMinNodeDepths function of Graph to accomplish this. | ||
// * | ||
// * @param groups The components to organize. | ||
// * @param start The top left coordinate where the organization should start. | ||
// */ | ||
// export function OrganizeMinDepth(groups: IOObjectSet, start: Vector): void { | ||
// OrganizeCore(groups, start, CreateGraph(groups).getMinNodeDepths()); | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move this file into
app/core/utils
I think