From db486d5d9a762532f5c7bd45920b01ab63cd08bd Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 12 Jun 2023 09:24:56 -0500 Subject: clean up network_compute and add input validation --- src/mind/topology.test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/mind/topology.test.js') diff --git a/src/mind/topology.test.js b/src/mind/topology.test.js index fbe1862..b272040 100644 --- a/src/mind/topology.test.js +++ b/src/mind/topology.test.js @@ -210,3 +210,23 @@ test('memory and input', () => { [ Math.tanh( 2-1 ) ], ]); }); + + +test('input and state must be the correct size', () => { + const n = network(2, 1, 1) + .connect(0, 2, 1) + .connect(1, 2, 1) + .connect(2, 3, 1); + + // wrong input size + expect(() => n.compute([], [4])).toThrow(); + expect(() => n.compute([1], [4])).toThrow(); + expect(() => n.compute([1, 1, 1], [4])).toThrow(); + + // wrong state size + expect(() => n.compute([1, 1], [])).toThrow(); + expect(() => n.compute([1, 1], [4, 4])).toThrow(); + + // prove correct sizes work + n.compute([1, 1], [4]); +}); -- cgit v1.2.1