@@ -30,7 +30,8 @@ var EPS = require( '@stdlib/constants/float64/eps' );
30
30
31
31
// FIXTURES //
32
32
33
- var data = require ( './fixtures/julia/data.json' ) ;
33
+ var data1 = require ( './fixtures/julia/data1.json' ) ;
34
+ var data2 = require ( './fixtures/julia/data2.json' ) ;
34
35
35
36
36
37
// VARIABLES //
@@ -51,13 +52,13 @@ tape( 'main export is a function', opts, function test( t ) {
51
52
52
53
tape ( 'if provided `NaN` for any parameter, the function returns `NaN`' , opts , function test ( t ) {
53
54
var v = median ( NaN , 1.0 , 0.5 ) ;
54
- t . equal ( isnan ( v ) , true , 'returns NaN ' ) ;
55
+ t . equal ( isnan ( v ) , true , 'returns expected value ' ) ;
55
56
56
57
v = median ( 0.0 , NaN , 0.5 ) ;
57
- t . equal ( isnan ( v ) , true , 'returns NaN ' ) ;
58
+ t . equal ( isnan ( v ) , true , 'returns expected value ' ) ;
58
59
59
60
v = median ( 0.0 , 10.0 , NaN ) ;
60
- t . equal ( isnan ( v ) , true , 'returns NaN ' ) ;
61
+ t . equal ( isnan ( v ) , true , 'returns expected value ' ) ;
61
62
62
63
t . end ( ) ;
63
64
} ) ;
@@ -66,21 +67,21 @@ tape( 'if provided parameters not satisfying `a <= c <= b`, the function returns
66
67
var y ;
67
68
68
69
y = median ( - 1.0 , - 1.1 , - 1.0 ) ;
69
- t . equal ( isnan ( y ) , true , 'returns NaN ' ) ;
70
+ t . equal ( isnan ( y ) , true , 'returns expected value ' ) ;
70
71
71
72
y = median ( 3.0 , 2.0 , 2.5 ) ;
72
- t . equal ( isnan ( y ) , true , 'returns NaN ' ) ;
73
+ t . equal ( isnan ( y ) , true , 'returns expected value ' ) ;
73
74
74
75
y = median ( 0.0 , 1.0 , - 1.0 ) ;
75
- t . equal ( isnan ( y ) , true , 'returns NaN ' ) ;
76
+ t . equal ( isnan ( y ) , true , 'returns expected value ' ) ;
76
77
77
78
y = median ( 0.0 , 1.0 , 2.0 ) ;
78
- t . equal ( isnan ( y ) , true , 'returns NaN ' ) ;
79
+ t . equal ( isnan ( y ) , true , 'returns expected value ' ) ;
79
80
80
81
t . end ( ) ;
81
82
} ) ;
82
83
83
- tape ( 'the function returns the median of a triangular distribution' , opts , function test ( t ) {
84
+ tape ( 'the function returns the median of a triangular distribution if provided parameters satisfy `c < (a + b) / 2` ' , opts , function test ( t ) {
84
85
var expected ;
85
86
var delta ;
86
87
var tol ;
@@ -90,10 +91,37 @@ tape( 'the function returns the median of a triangular distribution', opts, func
90
91
var i ;
91
92
var y ;
92
93
93
- expected = data . expected ;
94
- a = data . a ;
95
- b = data . b ;
96
- c = data . c ;
94
+ expected = data1 . expected ;
95
+ a = data1 . a ;
96
+ b = data1 . b ;
97
+ c = data1 . c ;
98
+ for ( i = 0 ; i < expected . length ; i ++ ) {
99
+ y = median ( a [ i ] , b [ i ] , c [ i ] ) ;
100
+ if ( y === expected [ i ] ) {
101
+ t . equal ( y , expected [ i ] , 'a: ' + a [ i ] + ', b: ' + b [ i ] + ', c: ' + c [ i ] + ', y: ' + y + ', expected: ' + expected [ i ] ) ;
102
+ } else {
103
+ delta = abs ( y - expected [ i ] ) ;
104
+ tol = 1.0 * EPS * abs ( expected [ i ] ) ;
105
+ t . ok ( delta <= tol , 'within tolerance. a: ' + a [ i ] + '. b: ' + b [ i ] + '. c: ' + c [ i ] + '. y: ' + y + '. E: ' + expected [ i ] + '. Δ: ' + delta + '. tol: ' + tol + '.' ) ;
106
+ }
107
+ }
108
+ t . end ( ) ;
109
+ } ) ;
110
+
111
+ tape ( 'the function returns the median of a triangular distribution if provided parameters satisfy `c >= (a + b) / 2`' , opts , function test ( t ) {
112
+ var expected ;
113
+ var delta ;
114
+ var tol ;
115
+ var a ;
116
+ var b ;
117
+ var c ;
118
+ var i ;
119
+ var y ;
120
+
121
+ expected = data2 . expected ;
122
+ a = data2 . a ;
123
+ b = data2 . b ;
124
+ c = data2 . c ;
97
125
for ( i = 0 ; i < expected . length ; i ++ ) {
98
126
y = median ( a [ i ] , b [ i ] , c [ i ] ) ;
99
127
if ( y === expected [ i ] ) {
0 commit comments