Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Oct 5, 2023
1 parent d7770e1 commit 43bdd3c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 163 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
[npm-image]: http://img.shields.io/npm/v/@stdlib/assert-has-uint8clampedarray-support.svg
[npm-url]: https://npmjs.org/package/@stdlib/assert-has-uint8clampedarray-support

[test-image]: https://github.com/stdlib-js/assert-has-uint8clampedarray-support/actions/workflows/test.yml/badge.svg?branch=v0.1.1
[test-url]: https://github.com/stdlib-js/assert-has-uint8clampedarray-support/actions/workflows/test.yml?query=branch:v0.1.1
[test-image]: https://github.com/stdlib-js/assert-has-uint8clampedarray-support/actions/workflows/test.yml/badge.svg?branch=main
[test-url]: https://github.com/stdlib-js/assert-has-uint8clampedarray-support/actions/workflows/test.yml?query=branch:main

[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/assert-has-uint8clampedarray-support/main.svg
[coverage-url]: https://codecov.io/github/stdlib-js/assert-has-uint8clampedarray-support?branch=main
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
},
"devDependencies": {
"@stdlib/array-uint8c": "^0.1.0",
"@stdlib/assert-is-boolean": "^0.1.0",
"@stdlib/assert-is-browser": "^0.1.0",
"@stdlib/assert-is-windows": "^0.1.0",
"@stdlib/assert-is-boolean": "^0.1.1",
"@stdlib/assert-is-browser": "^0.1.1",
"@stdlib/assert-is-windows": "^0.1.1",
"@stdlib/bench": "^0.1.0",
"@stdlib/math-base-special-round": "^0.1.0",
"@stdlib/process-exec-path": "^0.1.0",
"@stdlib/math-base-special-round": "^0.1.1",
"@stdlib/process-exec-path": "^0.1.1",
"proxyquire": "^2.0.0",
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
"istanbul": "^0.4.1",
Expand Down
160 changes: 4 additions & 156 deletions test/dist/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,165 +21,13 @@
// MODULES //

var tape = require( 'tape' );
var proxyquire = require( 'proxyquire' );
var round = require( '@stdlib/math-base-special-round' );
var Uint8ClampedArray = require( '@stdlib/array-uint8c' );
var detect = require( './../../dist' );


// VARIABLES //

var hasUint8ClampedArray = ( typeof Uint8ClampedArray === 'function' );
var main = require( './../../dist' );


// TESTS //

tape( 'main export is a function', function test( t ) {
tape( 'main export is defined', function test( t ) {
t.ok( true, __filename );
t.strictEqual( typeof detect, 'function', 'main export is a function' );
t.end();
});

tape( 'feature detection result is a boolean', function test( t ) {
t.strictEqual( typeof detect(), 'boolean', 'detection result is a boolean' );
t.end();
});

tape( 'if `Uint8ClampedArray` is supported, detection result is `true`', function test( t ) {
var mocked;
if ( hasUint8ClampedArray ) {
t.strictEqual( detect(), true, 'detection result is `true`' );
} else {
t.strictEqual( detect(), false, 'detection result is `false`' );
}
mocked = proxyquire( './../dist/main.js', {
'./uint8clampedarray.js': Mock,
'@stdlib/assert-is-uint8clampedarray': isArray
});
t.strictEqual( mocked(), true, 'detection result is `true` (mocked)' );

t.strictEqual( main !== void 0, true, 'main export is defined' );
t.end();

function isArray() {
return true;
}

function Mock( arr ) {
var out = [];
var v;
var i;

for ( i = 0; i < arr.length; i++ ) {
v = arr[ i ];
if ( v < 0 ) {
v = 0;
} else if ( v > 255 ) {
v = 255;
}
out.push( round( v ) );
}
return out;
}
});

tape( 'if `Uint8ClampedArray` is not supported, detection result is `false`', function test( t ) {
var mocked;
if ( hasUint8ClampedArray ) {
t.strictEqual( detect(), true, 'detection result is `true`' );
} else {
t.strictEqual( detect(), false, 'detection result is `false`' );
}
mocked = proxyquire( './../dist/main.js', {
'./uint8clampedarray.js': {}
});
t.strictEqual( mocked(), false, 'detection result is `false`' );

mocked = proxyquire( './../dist/main.js', {
'./uint8clampedarray.js': Mock1
});
t.strictEqual( mocked(), false, 'detection result is `false`' );

mocked = proxyquire( './../dist/main.js', {
'./uint8clampedarray.js': Mock2,
'@stdlib/assert-is-uint8clampedarray': isArray
});
t.strictEqual( mocked(), false, 'detection result is `false`' );

mocked = proxyquire( './../dist/main.js', {
'./uint8clampedarray.js': Mock3,
'@stdlib/assert-is-uint8clampedarray': isArray
});
t.strictEqual( mocked(), false, 'detection result is `false`' );

mocked = proxyquire( './../dist/main.js', {
'./uint8clampedarray.js': Mock4
});
t.strictEqual( mocked(), false, 'detection result is `false`' );

mocked = proxyquire( './../dist/main.js', {
'./uint8clampedarray.js': Mock5
});
t.strictEqual( mocked(), false, 'detection result is `false`' );

t.end();

function isArray() {
return true;
}

function Mock1() {
// Not a typed array:
return [];
}

function Mock2( arr ) {
var out = [];
var v;
var i;

// Does not clamp...
for ( i = 0; i < arr.length; i++ ) {
v = arr[ i ];
out.push( round( v ) );
}
return out;
}

function Mock3( arr ) {
var out = [];
var v;
var i;

// Does not clamp...
for ( i = 0; i < arr.length; i++ ) {
v = arr[ i ];
if ( v < 0 ) {
v = 0;
}
out.push( round( v ) );
}
return out;
}

function Mock4() {
throw new Error( 'beep' );
}

function Mock5( arr ) {
var out = [];
var v;
var i;

// Does not round to nearest...
for ( i = 0; i < arr.length; i++ ) {
v = arr[ i ];
if ( v < 0 ) {
v = 0;
} else if ( v > 255 ) {
v = 255;
}
out.push( v );
}
return out;
}
});

0 comments on commit 43bdd3c

Please sign in to comment.