|
| 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