Skip to content

Commit 018d957

Browse files
🔍 test: Cover idivmod.
1 parent 3cfd14b commit 018d957

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/src/Integer/divmod.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import test from 'ava' ;
2+
3+
import { ZZ , ZeroDivisionError } from '../../../src' ;
4+
5+
function macro ( t , a , b , q , r ) {
6+
const A = ZZ.from(a) ;
7+
const B = ZZ.from(b) ;
8+
const [Q, R] = A.idivmod(B) ;
9+
10+
t.is(q.toString(), Q.toString()) ;
11+
t.is(r.toString(), R.toString()) ;
12+
t.is(q.toString(), A.toString()) ;
13+
}
14+
15+
macro.title = ( providedTitle , a , b , q , r ) => `${a} idivmod ${b} = [${q}, ${r}]` ;
16+
17+
test( 'x.idivmod(0) throws' , t => { t.throws( () => ZZ.from(-123).idivmod(ZZ.from(0)) , { instanceOf: ZeroDivisionError } )})
18+
19+
test(macro, 3, 2, 1, 1) ;
20+
test(macro, '123', 2, 61, 1) ;
21+
test(macro, 15, 7, 2, 1) ;
22+
test(macro, 17, 7, 2, 3) ;
23+
test(macro, 18, 7, 2, 4) ;
24+
test(macro, 20, 7, 2, 6) ;
25+
test(macro, 21, 7, 3, 0) ;
26+
test(macro, 22, 7, 3, 1) ;
27+
test(macro, 27, 7, 3, 6) ;

0 commit comments

Comments
 (0)