Permalink
Browse files

better tests

  • Loading branch information...
1 parent 8554aca commit 3dbc5da8e8e0eebb6fd32c3c1352f93a29f0d80e @rlidwka committed Aug 29, 2012
Showing with 106 additions and 42 deletions.
  1. +16 −10 tests/act_funcs.js
  2. +39 −13 tests/algs_rate.js
  3. +35 −11 tests/fann_arrs.js
  4. +16 −8 tests/neu_count.js
View
26 tests/act_funcs.js
@@ -1,14 +1,20 @@
-
+var assert = require('assert');
var fann = require('../build/Release/fann');
var net = new fann.standard(1,10,1);
-console.log(net.activation_function(1, 0));
-console.log(net.activation_function(1, 0, 'sin'));
-console.log(net.activation_function(1, 1, 'cos'));
-console.log(net.activation_function(1, 0));
-console.log(net.activation_function(1, 1));
+// default activation function
+assert.equal(net.activation_function(1, 0), 'sigmoid_stepwise');
+
+// set custom activation function and return it
+assert.equal(net.activation_function(1, 0, 'sin'), 'sin');
+assert.equal(net.activation_function(1, 1, 'cos'), 'cos');
+
+// check if these activation functions are stored
+assert.equal(net.activation_function(1, 0), 'sin');
+assert.equal(net.activation_function(1, 1), 'cos');
-console.log(net.activation_function_hidden('sigmoid'));
-console.log(net.activation_function_output('elliot'));
-console.log(net.activation_function(1, 0));
-console.log(net.activation_function(2, 0));
+// activation functions for hidden and output layers
+assert.equal(net.activation_function_hidden('sigmoid'), 'sigmoid');
+assert.equal(net.activation_function_output('elliot'), 'elliot');
+assert.equal(net.activation_function(1, 0), 'sigmoid');
+assert.equal(net.activation_function(2, 0), 'elliot');
View
52 tests/algs_rate.js
@@ -1,28 +1,54 @@
-
+var assert = require('assert');
var fann = require('../build/Release/fann');
var net = new fann.standard(1,10,1);
-console.log(fann);
-console.log(net);
+/*
+ * Training algorithms
+ */
+// wrong algorithm, shouldn't change
net.training_algorithm = "back";
-console.log(net.training_algorithm, net.training_algorithm == 'RPROP');
+assert.equal(net.training_algorithm, 'rprop');
+
+// but this should
net.training_algorithm = "incremental";
-console.log(net.training_algorithm, net.training_algorithm == 'INCREMENTAL');
+assert.equal(net.training_algorithm, 'incremental');
+
+// set first alg in the list
net.training_algorithm = 1;
-console.log(net.training_algorithm, net.training_algorithm == 'BATCH');
+assert.equal(net.training_algorithm, 'batch');
+
+// should drop prefix
net.training_algorithm = "FANN_TRAIN_INCREMENTAL";
-console.log(net.training_algorithm, net.training_algorithm == 'INCREMENTAL');
+assert.equal(net.training_algorithm, 'incremental');
+
+/*
+ * Learning rates
+ */
-console.log(net.learning_rate, Math.abs(net.learning_rate-0.7) < 0.01);
+// should default to 0.7
+assert(Math.abs(net.learning_rate-0.7) < 0.0001);
+
+// trying to change it
net.learning_rate = '123';
-console.log(net.learning_rate, net.learning_rate == 123);
+assert.equal(net.learning_rate, 123);
+
+// wrong rate, change to NaN
net.learning_rate = 'hi!';
-console.log(net.learning_rate, isNaN(net.learning_rate));
+assert(isNaN(net.learning_rate));
+
+/*
+ * Learning momentum
+ */
-console.log(net.learning_momentum, net.learning_momentum == 0);
+// should default to 0
+assert.equal(net.learning_momentum, 0);
+
+// trying to change it
net.learning_momentum = '123';
-console.log(net.learning_momentum, net.learning_momentum == 123);
+assert.equal(net.learning_momentum, 123);
+
+// wrong momentum, change to NaN
net.learning_momentum = 'hi!';
-console.log(net.learning_momentum, isNaN(net.learning_rate));
+assert(isNaN(net.learning_rate));
View
46 tests/fann_arrs.js
@@ -1,19 +1,43 @@
-
+var assert = require('assert');
var fann = require('../build/Release/fann');
var net = new fann.standard(1,10,1);
-console.log(fann.get_all_activation_functions());
-console.log(net.get_all_activation_functions());
+// activation functions
+var expected = [
+ 'linear',
+ 'threshold',
+ 'threshold_symmetric',
+ 'sigmoid',
+ 'sigmoid_stepwise',
+ 'sigmoid_symmetric',
+ 'sigmoid_symmetric_stepwise',
+ 'gaussian',
+ 'gaussian_symmetric',
+ 'gaussian_stepwise',
+ 'elliot',
+ 'elliot_symmetric',
+ 'linear_piece',
+ 'linear_piece_symmetric',
+ 'sin_symmetric',
+ 'cos_symmetric',
+ 'sin',
+ 'cos' ]
+//console.log(fann.get_all_activation_functions());
+assert.deepEqual(net.get_all_activation_functions(), expected);
-console.log(fann.get_all_training_algorithms());
-console.log(net.get_all_training_algorithms());
+var expected = [ 'incremental', 'batch', 'rprop', 'quickprop' ]
+//console.log(fann.get_all_training_algorithms());
+assert.deepEqual(net.get_all_training_algorithms(), expected);
-console.log(fann.get_all_stop_functions());
-console.log(net.get_all_stop_functions());
+var expected = [ 'mse', 'bit' ]
+//console.log(fann.get_all_stop_functions());
+assert.deepEqual(net.get_all_stop_functions(), expected);
-console.log(fann.get_all_error_functions());
-console.log(net.get_all_error_functions());
+var expected = [ 'linear', 'tanh' ]
+//console.log(fann.get_all_error_functions());
+assert.deepEqual(net.get_all_error_functions(), expected);
-console.log(fann.get_all_network_types());
-console.log(net.get_all_network_types());
+var expected = [ 'layer', 'shortcut' ]
+//console.log(fann.get_all_network_types());
+assert.deepEqual(net.get_all_network_types(), expected);
View
24 tests/neu_count.js
@@ -1,13 +1,21 @@
-
+var assert = require('assert');
var fann = require('../build/Release/fann');
var net = new fann.shortcut([1,2,3,4]);
-console.log(net.get_num_input());
-console.log(net.get_num_output());
-console.log(net.get_total_neurons());
-console.log(net.get_total_connections());
-console.log(net.get_network_type());
+// 1 input layer and 4 output
+assert.equal(net.get_num_input(), 1);
+assert.equal(net.get_num_output(), 4);
+
+// total 1+2+3+4 + 1 = 11 neurons
+assert.equal(net.get_total_neurons(), 11);
+
+// 44 connections, I don't remember why
+assert.equal(net.get_total_connections(), 44);
+
+// network type
+assert.equal(net.get_network_type(), 'shortcut');
-console.log(net.get_layer_array());
-console.log(net.get_bias_array());
+// arrays
+assert.deepEqual(net.get_layer_array(), [1,2,3,4]);
+assert.deepEqual(net.get_bias_array(), [1,0,0,0]);

0 comments on commit 3dbc5da

Please sign in to comment.