resolve gene type issues

This commit is contained in:
Michael Peters 2024-08-09 13:49:34 -07:00
parent 7997fa435b
commit 85c6731036
2 changed files with 10 additions and 2 deletions

View File

@ -185,6 +185,8 @@ import IOSet from './ioset';
export type NodeID = string; export type NodeID = string;
// NOTE: the types here aren't perfect but they are better than the
// complete nightmare that they could be...
export interface RawEdge { export interface RawEdge {
src_id: NodeID; src_id: NodeID;
dst_id: NodeID; dst_id: NodeID;
@ -274,8 +276,8 @@ export class Network<EdgeT extends Edge<Node<EdgeT>>> {
interface Gene { interface Gene {
innovation: number; innovation: number;
src: NodeID; src_id: NodeID;
dst: NodeID; dst_id: NodeID;
weight: number; weight: number;
enabled: boolean; enabled: boolean;
} }

View File

@ -33,6 +33,7 @@ function testEdgesToNodesBasic() {
Array.from(nodeA.dsts).map(e => e.dst.id), Array.from(nodeA.dsts).map(e => e.dst.id),
['C', 'D', 'E'], ['C', 'D', 'E'],
); );
const nodeB = nodes.get('B')!; const nodeB = nodes.get('B')!;
assert(nodeB.id === 'B'); assert(nodeB.id === 'B');
assert(nodeB.srcs.size === 0); assert(nodeB.srcs.size === 0);
@ -41,6 +42,7 @@ function testEdgesToNodesBasic() {
Array.from(nodeB.dsts).map(e => e.dst.id), Array.from(nodeB.dsts).map(e => e.dst.id),
['D'], ['D'],
); );
const nodeC = nodes.get('C')!; const nodeC = nodes.get('C')!;
assert(nodeC.id === 'C'); assert(nodeC.id === 'C');
assert(nodeC.srcs.size === 1); assert(nodeC.srcs.size === 1);
@ -53,6 +55,7 @@ function testEdgesToNodesBasic() {
Array.from(nodeC.dsts).map(e => e.dst.id), Array.from(nodeC.dsts).map(e => e.dst.id),
['E'], ['E'],
); );
const nodeD = nodes.get('D')!; const nodeD = nodes.get('D')!;
assert(nodeD.id === 'D'); assert(nodeD.id === 'D');
assert(nodeD.srcs.size === 2); assert(nodeD.srcs.size === 2);
@ -60,11 +63,13 @@ function testEdgesToNodesBasic() {
Array.from(nodeD.srcs).map(e => e.src.id), Array.from(nodeD.srcs).map(e => e.src.id),
['A', 'B'], ['A', 'B'],
); );
assert(nodeD.dsts.size === 2); assert(nodeD.dsts.size === 2);
assertArrayEqual( assertArrayEqual(
Array.from(nodeD.dsts).map(e => e.dst.id), Array.from(nodeD.dsts).map(e => e.dst.id),
['E', 'F'], ['E', 'F'],
); );
const nodeE = nodes.get('E')!; const nodeE = nodes.get('E')!;
assert(nodeE.id === 'E'); assert(nodeE.id === 'E');
assert(nodeE.srcs.size === 3); assert(nodeE.srcs.size === 3);
@ -72,6 +77,7 @@ function testEdgesToNodesBasic() {
Array.from(nodeE.srcs).map(e => e.src.id), Array.from(nodeE.srcs).map(e => e.src.id),
['A', 'C', 'D'], ['A', 'C', 'D'],
); );
assert(nodeE.dsts.size === 0); assert(nodeE.dsts.size === 0);
const nodeF = nodes.get('F')!; const nodeF = nodes.get('F')!;
assert(nodeF.id === 'F'); assert(nodeF.id === 'F');