Skip to content

Commit

Permalink
added test (#97)
Browse files Browse the repository at this point in the history
* added test

* format

---------

Co-authored-by: Nigel@SudioMac <[email protected]>
  • Loading branch information
nleck and nigelleck authored May 13, 2023
1 parent 257d7ba commit 53ea13d
Show file tree
Hide file tree
Showing 2 changed files with 219 additions and 1 deletion.
80 changes: 79 additions & 1 deletion test/CRISPR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Deno.test("REMOVE", () => {
}
});

Deno.test("CRISPR-multi-outputs", () => {
Deno.test("CRISPR-multi-outputs1", () => {
const json: NetworkInternal = {
nodes: [
{ type: "hidden", squash: "LOGISTIC", bias: -1, index: 3, uuid: "h1" },
Expand Down Expand Up @@ -208,3 +208,81 @@ Deno.test("CRISPR-multi-outputs", () => {
Deno.writeTextFileSync("test/data/CRISPR/.actual-sane.json", actualTXT);
assertEquals(actualTXT, expectedTXT, "should have converted");
});

Deno.test("CRISPR-multi-outputs2", () => {
const json: NetworkInternal = {
nodes: [
{ type: "hidden", squash: "LOGISTIC", bias: -1, index: 3, uuid: "h1" },
// { type: "hidden", squash: "LOGISTIC", bias: -0.5, index: 4, uuid: "h2" },
// { type: "hidden", squash: "LOGISTIC", bias: 0, index: 5, uuid: "h3" },
// { type: "hidden", squash: "LOGISTIC", bias: 0.5, index: 6, uuid: "h4" },
// { type: "hidden", squash: "MEAN", bias: -0.25, index: 7, uuid: "h5" },
{
type: "output",
squash: "IDENTITY",
index: 4,
uuid: "h6",
bias: 0,
},
{
type: "output",
squash: "IDENTITY",
index: 5,
uuid: "h7",
bias: 0,
},
{
type: "output",
squash: "LOGISTIC",
index: 6,
uuid: "h8",
bias: 0,
},
],
connections: [
{ from: 1, to: 3, weight: 0.1 },
{ from: 2, to: 4, weight: 0.2 },
{ from: 3, to: 5, weight: 0.3 },
// { from: 3, to: 4, weight: 0.3 },
{ from: 2, to: 6, weight: 0.4 },
// { from: 5, to: 10, weight: 0.4 },
// { from: 1, to: 6, weight: 0.5 },
// { from: 4, to: 7, weight: 0.7 },
// { from: 6, to: 8, weight: 0.8 },
// { from: 7, to: 9, weight: 0.9 },
],
input: 3,
output: 3,
};
const network = Network.fromJSON(json);
Deno.writeTextFileSync(
"test/data/CRISPR/.network-sane2.json",
JSON.stringify(network.internalJSON(), null, 2),
);
network.validate();
const crispr = new CRISPR(network);
const dnaTXT = Deno.readTextFileSync("test/data/CRISPR/DNA-SANE.json");

const networkSANE = Network.fromJSON(crispr.apply(JSON.parse(dnaTXT)));
networkSANE.validate();
const expectedJSON = JSON.parse(
Deno.readTextFileSync("test/data/CRISPR/expected-sane2.json"),
);

const expectedTXT = JSON.stringify(
Network.fromJSON(expectedJSON).internalJSON(),
null,
2,
);

Deno.writeTextFileSync("test/data/CRISPR/.expected-sane2.json", expectedTXT);

const actualTXT = JSON.stringify(
networkSANE.internalJSON(),
null,
2,
);

Deno.writeTextFileSync("test/data/CRISPR/.actual-sane2.json", actualTXT);
assertEquals(actualTXT, expectedTXT, "should have converted");
});
140 changes: 140 additions & 0 deletions test/data/CRISPR/expected-sane2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"nodes": [
{
"type": "hidden",
"index": 3,
"uuid": "h1",
"bias": -1,
"squash": "LOGISTIC"
},
{
"type": "hidden",
"index": 4,
"uuid": "h6",
"bias": 0,
"squash": "IDENTITY"
},
{
"type": "hidden",
"index": 5,
"uuid": "h7",
"bias": 0,
"squash": "IDENTITY"
},
{
"type": "hidden",
"index": 6,
"uuid": "h8",
"bias": 0,
"squash": "LOGISTIC"
},
{
"type": "output",
"index": 7,
"uuid": "ed56a8a6-001-4a53-9eab-583c499d231b",
"bias": -0.0001,
"squash": "MINIMUM",
"tags": [
{
"name": "CRISPR",
"value": "Sane Output"
}
]
},
{
"type": "output",
"index": 8,
"uuid": "ed56a8a6-002-4a53-9eab-583c499d231b",
"bias": 0,
"squash": "MEAN",
"tags": [
{
"name": "CRISPR",
"value": "Sane Output"
}
]
},
{
"type": "output",
"index": 9,
"uuid": "ed56a8a6-003-4a53-9eab-583c499d231b",
"bias": 0.0001,
"squash": "MAXIMUM",
"tags": [
{
"name": "CRISPR",
"value": "Sane Output"
}
]
}
],
"connections": [
{
"weight": 0.1,
"from": 1,
"to": 3
},
{
"weight": 0.2,
"from": 2,
"to": 4
},
{
"weight": 0.4,
"from": 2,
"to": 6
},
{
"weight": 0.3,
"from": 3,
"to": 5
},
{
"weight": 1,
"from": 4,
"to": 7
},
{
"weight": 1,
"from": 4,
"to": 8
},
{
"weight": 1,
"from": 4,
"to": 9
},
{
"weight": 1,
"from": 5,
"to": 7
},
{
"weight": 1,
"from": 5,
"to": 8
},
{
"weight": 1,
"from": 5,
"to": 9
},
{
"weight": 1,
"from": 6,
"to": 7
},
{
"weight": 1,
"from": 6,
"to": 8
},
{
"weight": 1,
"from": 6,
"to": 9
}
],
"input": 3,
"output": 3
}

0 comments on commit 53ea13d

Please sign in to comment.