Skip to content

Commit f2fae67

Browse files
authored
test(values): add missing test case and improve code style
1 parent 7cc8638 commit f2fae67

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.values.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ bench( pkg+':values', function benchmark( b ) {
4545
b.tic();
4646
for ( i = 0; i < b.iterations; i++ ) {
4747
iter = arr.values();
48-
4948
for ( value of iter ) {
5049
if ( isnan( value ) ) {
5150
b.fail( 'should not return NaN' );

lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -860,22 +860,22 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
860860
* @throws {TypeError} `this` must be a typed array instance
861861
* @returns {Object} iterator for array elements
862862
*/
863-
setReadOnly(TypedArray.prototype, 'values', function values() {
863+
setReadOnly( TypedArray.prototype, 'values', function values() {
864864
var iterator;
865865
var index = 0;
866866
var value;
867867
var isLE = this._isLE;
868868
var buf = this._buffer;
869869
var len = this._length;
870870

871-
if (!isTypedArray(this)) {
872-
throw new TypeError(format('invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[dtype[0]], CTOR_NAME));
871+
if ( !isTypedArray( this ) ) {
872+
throw new TypeError(format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) );
873873
}
874874

875875
iterator = {
876876
'next': function next() {
877-
if (index < len) {
878-
value = buf[GETTER](index * BYTES_PER_ELEMENT, isLE);
877+
if ( index < len ) {
878+
value = buf[ GETTER ]( index * BYTES_PER_ELEMENT, isLE );
879879
index += 1;
880880
return {
881881
'value': value,
@@ -888,7 +888,7 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
888888
}
889889
};
890890

891-
iterator[Symbol.iterator] = function iterator() {
891+
iterator[ Symbol.iterator ] = function iterator() {
892892
return this;
893893
};
894894

lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.values.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24+
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2425
var isFunction = require( '@stdlib/assert/is-function' );
2526
var factory = require( './../lib' );
2627

@@ -43,11 +44,18 @@ tape( 'the `values` method returns an iterator function', function test( t ) {
4344
t.end();
4445
});
4546

47+
tape( 'attached to the prototype of the returned function is a `values` method', function test( t ) {
48+
var ctor = factory( 'float64' );
49+
t.strictEqual( hasOwnProp( ctor.prototype, 'values' ), true, 'has `values` method on the prototype' );
50+
t.strictEqual( isFunction( ctor.prototype.values ), true, '`values` is a function' );
51+
t.end();
52+
});
53+
4654
tape( 'the `values` iterator stops when all elements are iterated', function test( t ) {
4755
var iterator;
4856
var result;
4957
var ctor = factory( 'float64' );
50-
var arr = new ctor( 'little-endian', [1.0, 2.0, 3.0, 4.0, 5.0] );
58+
var arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
5159

5260
iterator = arr.values();
5361

@@ -108,7 +116,7 @@ tape( 'the `values` iterator returns the correct value for typed arrays with dif
108116
var iterator;
109117
var result;
110118
var ctor = factory( 'float64' );
111-
var arr = new ctor( 'little-endian', [10.5, 20.5, 30.5] );
119+
var arr = new ctor( 'little-endian', [ 10.5, 20.5, 30.5 ] );
112120

113121
iterator = arr.values();
114122

@@ -142,21 +150,21 @@ tape( 'the `values` iterator works with `for...of` loop', function test( t ) {
142150
var values = [];
143151
var value;
144152
var ctor = factory( 'float64' );
145-
var arr = new ctor( 'little-endian', [1.0, 2.0, 3.0, 4.0, 5.0] );
153+
var arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
146154

147155
for ( value of arr.values() ) {
148156
values.push( value );
149157
}
150158

151-
t.deepEqual( values, [1.0, 2.0, 3.0, 4.0, 5.0], 'correctly iterates over values' );
159+
t.deepEqual( values, [ 1.0, 2.0, 3.0, 4.0, 5.0 ], 'correctly iterates over values' );
152160
t.end();
153161
});
154162

155163
tape( 'the `values` iterator supports providing an execution context', function test( t ) {
156164
var iterator;
157165
var result;
158166
var ctor = factory( 'float64' );
159-
var arr = new ctor( 'little-endian', [1.0, 2.0, 3.0, 4.0, 5.0] );
167+
var arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
160168
var ctx = {
161169
'threshold': 3
162170
};
@@ -198,10 +206,10 @@ tape( 'the `values` iterator throws an error when `this` is not a typed array',
198206
];
199207

200208
var ctor = factory( 'float64' );
201-
var arr = new ctor( 'little-endian', [1.0, 2.0, 3.0, 4.0] );
209+
var arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0 ] );
202210
var i;
203211

204-
for (i = 0; i < values.length; i++ ) {
212+
for ( i = 0; i < values.length; i++ ) {
205213
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[i] );
206214
}
207215

0 commit comments

Comments
 (0)