From 3c0ec9ad84b80076fea1964bedfcb74e0a4d9912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Ooms?= Date: Sat, 9 May 2020 22:26:31 +0200 Subject: [PATCH] :mag: test: Increase coverage for conversion. See #63. --- test/src/core/convert/convert.js | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/src/core/convert/convert.js diff --git a/test/src/core/convert/convert.js b/test/src/core/convert/convert.js new file mode 100644 index 00000000..636e9488 --- /dev/null +++ b/test/src/core/convert/convert.js @@ -0,0 +1,57 @@ +import test from 'ava' ; + +import { + _convert_to_larger_fast, + _convert_to_smaller_fast, + _log, + _zeros, +} from '../../../../src' ; + +function macro_larger ( t , f , _t , a , e ) { + + const [ z , x ] = _log( _t , f ) ; + + t.is(1, x); + + const b = _zeros(e.length) + + _convert_to_larger_fast( f , z , a , 0 , a.length , b , 0 , b.length ) ; + + t.deepEqual(e, b); + +} + +macro_larger.title = ( providedTitle , f , t , a , e ) => `_convert_to_larger_fast(${f}, ${t}, ${JSON.stringify(a)}) <${e.length}>` ; + +function macro_smaller ( t , f , _t , a , e ) { + + const [ z , x ] = _log( f , _t ) ; + + t.is(1, x); + + const b = _zeros(e.length) + + _convert_to_smaller_fast( _t , z , a , 0 , a.length , b , 0 , b.length ) ; + + t.deepEqual(e, b); + +} + +macro_smaller.title = ( providedTitle , f , t , a , e ) => `_convert_to_smaller_fast(${f}, ${t}, ${JSON.stringify(a)}) <${e.length}>` ; + +test( macro_larger , 16 , 256 , [ ] , [ ] ) ; +test( macro_larger , 16 , 256 , [ 15 ] , [ ] ) ; +test( macro_larger , 16 , 256 , [ 15 ] , [ 15 ] ) ; +test( macro_larger , 16 , 256 , [ 15 , 15 ] , [ 255 ] ) ; +test( macro_larger , 16 , 256 , [ 15 , 15 , 15 ] , [ 255 ] ) ; +test( macro_larger , 16 , 256 , [ 15 , 15 , 15 ] , [ 15 , 255 ] ) ; +test( macro_larger , 16 , 256 , [ 15 , 15 , 15 , 15 ] , [ 255 ] ) ; +test( macro_larger , 16 , 256 , [ 15 , 15 , 15 , 15 ] , [ 255 , 255 ] ) ; + +test( macro_smaller , 256 , 16 , [ ] , [ ] ) ; +test( macro_smaller , 256 , 16 , [ 255 ] , [ ] ) ; +test( macro_smaller , 256 , 16 , [ 255 ] , [ 15 ] ) ; +test( macro_smaller , 256 , 16 , [ 255 ] , [ 15 , 15 ] ) ; +test( macro_smaller , 256 , 16 , [ 255 , 255 ] , [ 15 , 15 ] ) ; +test( macro_smaller , 256 , 16 , [ 255 , 255 ] , [ 15 , 15 , 15 ] ) ; +test( macro_smaller , 256 , 16 , [ 255 , 255 ] , [ 15 , 15 , 15 , 15 ] ) ;