Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

better tests

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

0 notes on commit 3dbc5da

Please sign in to comment.
Something went wrong with that request. Please try again.