summaryrefslogtreecommitdiff
path: root/src/mind/topology.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/mind/topology.test.js')
-rw-r--r--src/mind/topology.test.js118
1 files changed, 94 insertions, 24 deletions
diff --git a/src/mind/topology.test.js b/src/mind/topology.test.js
index 421eb17..5aab350 100644
--- a/src/mind/topology.test.js
+++ b/src/mind/topology.test.js
@@ -1,31 +1,101 @@
'use strict';
-import { Point } from './topology';
+import { network } from './topology';
-test('Point works correctly', () => {
- const p = Point(0, 1);
- expect(p.layer).toBe(0);
- expect(p.index).toBe(1);
- expect(() => p.layer = 5).toThrow();
+
+test('basic network functionality', () => {
+ const n = network(0, 5, 0);
+ expect(n).toEqual({
+ input_count: 0,
+ output_count: 0,
+ adjacency: [ [], [], [], [], [] ],
+ weight: [],
+ });
+
+ expect(() => n.adjacency = []).toThrow();
+ expect(() => n.weight = []).toThrow();
+
+ const nn = n.connect(0, 1, -2);
+ expect(nn).toEqual({
+ input_count: 0,
+ output_count: 0,
+ adjacency: [
+ [ 1 ],
+ [ -1 ],
+ [ 0 ],
+ [ 0 ],
+ [ 0 ]
+ ],
+ weight: [ -2 ],
+ });
+
+ expect(() => nn.adjacency = []).toThrow();
+ expect(() => nn.weight = []).toThrow();
+
+ const nnn = nn.connect(2, 4, 3);
+ expect(nnn).toEqual({
+ input_count: 0,
+ output_count: 0,
+ adjacency: [
+ [ 1, 0 ],
+ [ -1, 0 ],
+ [ 0, 1 ],
+ [ 0, 0 ],
+ [ 0, -1 ]
+ ],
+ weight: [ -2, 3 ],
+ });
+
+ expect(() => nnn.adjacency = []).toThrow();
+ expect(() => nnn.weight = []).toThrow();
+});
+
+
+test(
+'networks are restricted from sinking to inputs or sourcing from outputs',
+() => {
+ const n = network(2, 2, 2);
+
+ expect(n.connect(1,2,0)).toEqual({
+ input_count: 2,
+ output_count: 2,
+ adjacency: [
+ [ 0 ],
+ [ 1 ],
+ [ -1 ],
+ [ 0 ],
+ [ 0 ],
+ [ 0 ],
+ ],
+ weight: [ 0 ],
+ });
+ expect(() => n.connect(2, 1, 0)).toThrow();
+
+ expect(n.connect(3, 4, 2)).toEqual({
+ input_count: 2,
+ output_count: 2,
+ adjacency: [
+ [ 0 ],
+ [ 0 ],
+ [ 0 ],
+ [ 1 ],
+ [ -1 ],
+ [ 0 ],
+ ],
+ weight: [ 2 ],
+ });
+ expect(() => n.connect(4, 3, 2)).toThrow();
});
-test('Point equality works correctly', () => {
- const a00 = Point(0, 0);
- const b00 = Point(0, 0);
- const a01 = Point(0, 1);
- const b01 = Point(0, 1);
- const a10 = Point(1, 0);
- const b10 = Point(1, 0);
- const a11 = Point(1, 1);
- const b11 = Point(1, 1);
-
- expect(a00 == b00).toBeTruthy();
- expect(a01 == b01).toBeTruthy();
- expect(a10 == b10).toBeTruthy();
- expect(a11 == b11).toBeTruthy();
-
- expect(a00 == a01).toBeFalsy();
- expect(a00 == a10).toBeFalsy();
- expect(a00 == a11).toBeFalsy();
+test('self-connections work correctly', () => {
+ const n = network(0, 1, 0).connect(0, 0, 2.0);
+ expect(n).toEqual({
+ input_count: 0,
+ output_count: 0,
+ adjacency: [
+ [ 2 ],
+ ],
+ weight: [ 2 ],
+ });
});