Skip to content

Commit dda5d1a

Browse files
committed
Update fixtures and associated tests
1 parent 7de506a commit dda5d1a

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

lib/node_modules/@stdlib/math/base/special/logaddexp/test/fixtures/python/data.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

lib/node_modules/@stdlib/math/base/special/logaddexp/test/fixtures/python/runner.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,31 @@
2929
DIR = os.path.dirname(FILE)
3030

3131

32-
def gen(x, name):
32+
def gen(x, y, name):
3333
"""Generate fixture data and write to file.
3434
3535
# Arguments
3636
3737
* `x`: domain
38+
* `y`: domain
3839
* `name::str`: filepath of the output file
3940
4041
# Examples
4142
4243
``` python
43-
python> x = arange(-100.0, 100.0, 1)
44-
python> gen(x, './data.json')
44+
python> x = np.linspace(-100.0, 100.0, 1)
45+
python> y = np.linspace(100.0, -100.0, 1)
46+
python> gen(x, y, 'data.json')
4547
```
4648
"""
47-
data = [{"input": [a, b], "expected": np.logaddexp(a, b)} for a in x for b in x]
49+
z = np.logaddexp(x, y)
50+
51+
# Store data to be written to file as a dictionary:
52+
data = {
53+
"x": x.tolist(),
54+
"y": y.tolist(),
55+
"expected": z.tolist()
56+
}
4857

4958
# Based on the script directory, create an output filepath:
5059
filepath = os.path.join(DIR, name)
@@ -56,8 +65,9 @@ def gen(x, name):
5665

5766
def main():
5867
"""Generate fixture data."""
59-
x = np.arange(-100.0, 100.0, 0.5)
60-
gen(x, "data.json")
68+
x = (np.random.random(1000) * 200.0) - 100.0
69+
y = (np.random.random(1000) * 200.0) - 100.0
70+
gen(x, y, "data.json")
6171

6272

6373
if __name__ == "__main__":

lib/node_modules/@stdlib/math/base/special/logaddexp/test/test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,25 @@ tape( 'the function returns `-infinity` if both arguments are `-infinity`', func
102102
});
103103

104104
tape( 'the function accurately computes the natural logarithm of exp(x) + exp(y)', function test( t ) {
105+
var expected;
105106
var delta;
106107
var tol;
107-
var ex;
108-
var i;
109-
var v;
110-
var y;
111108
var x;
109+
var y;
110+
var v;
111+
var i;
112112

113-
for ( i = 0; i < data.length; i++ ) {
114-
x = data[ i ].input[ 0 ];
115-
y = data[ i ].input[ 1 ];
116-
ex = data[ i ].expected;
117-
v = logaddexp( x, y );
118-
if ( v === ex ) {
119-
t.strictEqual( v, ex, 'returns expected value when provided '+x+' and '+y );
113+
x = data.x;
114+
y = data.y;
115+
expected = data.expected;
116+
for ( i = 0; i < expected.length; i++ ) {
117+
v = logaddexp( x[ i ], y[ i ] );
118+
if ( v === expected[ i ] ) {
119+
t.strictEqual( v, expected[ i ], 'returns expected value when provided '+x[ i ]+' and '+y[ i ] );
120120
} else {
121-
delta = abs( ex - v );
122-
tol = EPS * abs( ex );
123-
t.ok( delta <= tol, 'within tolerance. x: '+x+'. y: '+y+'. actual: '+v+'. expected: '+ex+'. Δ: '+delta+'. tol: '+tol+'.' );
121+
delta = abs( expected[ i ] - v );
122+
tol = EPS * abs( expected[ i ] );
123+
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. y: '+y[ i ]+'. actual: '+v+'. expected: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
124124
}
125125
}
126126
t.end();

0 commit comments

Comments
 (0)