summaryrefslogtreecommitdiff
path: root/test/unit_tests
diff options
context:
space:
mode:
authorTinWoodman92 <chrhodgden@gmail.com>2024-02-08 16:09:56 -0600
committerTinWoodman92 <chrhodgden@gmail.com>2024-02-08 16:09:56 -0600
commit62993dd59bbbfcdb07dbb5836d359fad6334f23e (patch)
tree4f0d310442c66050d0886eb82bebd9475e63803c /test/unit_tests
initial commit
Diffstat (limited to 'test/unit_tests')
-rw-r--r--test/unit_tests/activationFunctions.test.js23
-rw-r--r--test/unit_tests/binaryConverter.test.js33
-rw-r--r--test/unit_tests/layer.test.js15
-rw-r--r--test/unit_tests/nnetwork.test.js17
4 files changed, 88 insertions, 0 deletions
diff --git a/test/unit_tests/activationFunctions.test.js b/test/unit_tests/activationFunctions.test.js
new file mode 100644
index 0000000..b7fd570
--- /dev/null
+++ b/test/unit_tests/activationFunctions.test.js
@@ -0,0 +1,23 @@
+console.log('Hello from activationFunctions.test.js');
+
+console.log(activationFunctionList);
+
+let result;
+let testVector = [-2, -1, 0, 1, 2];
+testVector = math.matrix(testVector);
+let testMatrix = math.matrix([testVector, testVector]);
+
+result = activationFunctionList['sigmoid'].gx(testVector);
+console.log(result);
+result = activationFunctionList['sigmoid'].dg_dx(testVector);
+console.log(result);
+
+result = activationFunctionList['relu'].gx(testMatrix);
+console.log(result);
+result = activationFunctionList['relu'].dg_dx(testMatrix);
+console.log(result);
+
+result = activationFunctionList['identity'].gx(testMatrix);
+console.log(result);
+result = activationFunctionList['identity'].dg_dx(testMatrix);
+console.log(result);
diff --git a/test/unit_tests/binaryConverter.test.js b/test/unit_tests/binaryConverter.test.js
new file mode 100644
index 0000000..b6fb503
--- /dev/null
+++ b/test/unit_tests/binaryConverter.test.js
@@ -0,0 +1,33 @@
+const BinaryConverter = require('../../src/binaryConverter');
+const math = require('mathjs');
+
+//import BinaryConverter from 'binaryConverter';
+
+describe('Test BinaryConversion module', () => {
+
+ let testConverter;
+ let testVector;
+ let testInteger;
+
+ beforeEach(() => {
+ testConverter = new BinaryConverter(2);
+ testInteger = 2;
+ testVector = math.matrix([1, 0]);
+ });
+
+
+ test('convert integer to binary array', () => {
+ testConverter.integer = testInteger;
+ expect(testConverter.inputActivation).toEqual(testVector);
+ });
+
+ test('convert binary array to integer', () => {
+ testConverter.inputActivation = testVector;
+ expect(testConverter.integer).toEqual(testInteger);
+ });
+
+ test.todo('Random array initializes correct integer');
+
+});
+
+
diff --git a/test/unit_tests/layer.test.js b/test/unit_tests/layer.test.js
new file mode 100644
index 0000000..37402d3
--- /dev/null
+++ b/test/unit_tests/layer.test.js
@@ -0,0 +1,15 @@
+console.log('Hello from layer.test.js');
+
+let testLayer = new Layer(2, 3, 'relu');
+let testConv = new BinaryConverter(2);
+
+console.log(testLayer);
+console.log(testConv.randomInput());
+
+console.log(testLayer.forwardPropogation(testConv.inputActivation));
+
+testLayer = new Layer(2, 3, 'sigmoid');
+console.log(testLayer.forwardPropogation(testConv.inputActivation));
+
+testLayer = new Layer(2, 3, 'identity');
+console.log(testLayer.forwardPropogation(testConv.inputActivation));
diff --git a/test/unit_tests/nnetwork.test.js b/test/unit_tests/nnetwork.test.js
new file mode 100644
index 0000000..efc3f6e
--- /dev/null
+++ b/test/unit_tests/nnetwork.test.js
@@ -0,0 +1,17 @@
+console.log('Hello from nnetwork.test.js');
+
+let testConv = new BinaryConverter(2);
+let nodeCounts = [testConv._inputDigits, 3, testConv._outputDigits];
+let afns = ['identity', 'relu', 'identity'];
+
+let testNNetwork = new NNetwork(nodeCounts, afns, 0.1);
+
+console.log(testConv.randomInput());
+console.log(testNNetwork.forwardPropogation(testConv.inputActivation));
+console.log(testNNetwork.backPropogation(testConv.inputActivation, testConv.outputActivation));
+
+console.log(testConv.randomInput());
+console.log(testNNetwork.forwardPropogation(testConv.inputActivation));
+console.log(testNNetwork.backPropogation(testConv.inputActivation, testConv.outputActivation));
+
+testNNetwork.gradientDescent(); \ No newline at end of file