Skip to content

Commit

Permalink
🔍 test: Increase coverage for _divmod.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed May 9, 2020
1 parent 2c4ac52 commit b18845e
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions test/src/api/idivmod.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'ava' ;
import { parse , _zeros , _idivmod , stringify } from '../../../src' ;
import { parse , _zeros , _idivmod , _divmod , stringify } from '../../../src' ;

function macro ( t , dividend , divisor , quotient , remainder ) {
function test_idivmod ( t , dividend , divisor , quotient , remainder ) {

const B = 10 ;

Expand All @@ -11,18 +11,51 @@ function macro ( t , dividend , divisor , quotient , remainder ) {

_idivmod( B , D , 0 , D.length , d , 0 , d.length , q , 0 , q.length ) ;

t.is( divisor , stringify( B , 10 , d , 0 , d.length ) ) ;

t.is(
quotient , stringify( B , 10 , q , 0 , q.length ) ,
dividend + ' / ' + divisor + ' = ' + quotient
) ;

t.is(
remainder , stringify( B , 10 , D , 0 , D.length ) ,
dividend + ' % ' + divisor + ' = ' + remainder
) ;

}

function test_divmod ( t , dividend , divisor , quotient , remainder ) {

const B = 10 ;

const D = parse( 10 , B , dividend ) ;
const d = parse( 10 , B , divisor ) ;
const q = _zeros( D.length ) ;
const R = _zeros( D.length ) ;

_divmod( B , D , 0 , D.length , d , 0 , d.length , q , 0 , q.length , R , 0 , R.length ) ;

t.is( dividend , stringify( B , 10 , D , 0 , D.length ) ) ;
t.is( divisor , stringify( B , 10 , d , 0 , d.length ) ) ;

t.is(
stringify( B , 10 , q , 0 , q.length ) , quotient ,
quotient , stringify( B , 10 , q , 0 , q.length ) ,
dividend + ' / ' + divisor + ' = ' + quotient
) ;

t.is(
stringify( B , 10 , D , 0 , D.length ) , remainder ,
remainder , stringify( B , 10 , R , 0 , R.length ) ,
dividend + ' % ' + divisor + ' = ' + remainder
) ;

}

function macro ( ...args ) {
test_idivmod( ...args ) ;
test_divmod( ...args ) ;
}

macro.title = ( title , D , d , q , r ) => `${title} ${D} / ${d} = ${q} % ${r}`.trim()


Expand Down

0 comments on commit b18845e

Please sign in to comment.