Skip to content

Commit d8d35ac

Browse files
✨ feat(IntegerRing): Add .has() method.
1 parent 624ced5 commit d8d35ac

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/IntegerRing.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,9 @@ export class IntegerRing {
9999
return new Integer( this.base , -1 , [ 1 ] ) ;
100100
}
101101

102+
has ( x ) {
103+
if ( x instanceof Integer ) return true ;
104+
return Number.isInteger(x) ;
105+
}
106+
102107
}

test/src/ZZ/has.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import test from 'ava' ;
2+
3+
import { ZZ } from '../../../src' ;
4+
5+
const has = ( t , x ) => t.true( ZZ.has(x) ) ;
6+
has.title = ( providedTitle , x ) => `ZZ contains ${x.toString()}.`
7+
8+
const hasnot = ( t , x ) => t.false( ZZ.has(x) ) ;
9+
hasnot.title = ( providedTitle , x ) => `ZZ does not contain ${JSON.stringify(x)}.`
10+
11+
test( has , -1 ) ;
12+
test( has , 0 ) ;
13+
test( has , 1 ) ;
14+
15+
test( has , ZZ.from(-1234) ) ;
16+
17+
test( has , ZZ.from('98213037479498473209740509327409327492744596398574') ) ;
18+
test( has , ZZ.from('-98213037479849847320974050937409327492744596398574') ) ;
19+
20+
test( has , ZZ.from('3b', 16) ) ;
21+
22+
test( hasnot , '98213037479498473209740509327409327492744596398574' ) ;
23+
test( hasnot , '-98213037479849847320974050937409327492744596398574' ) ;
24+
25+
test( hasnot , '0' ) ;
26+
test( hasnot , 'ff' ) ;
27+
test( hasnot , 'fdsalkjflsakjfd' ) ;
28+
29+
test( hasnot , [] ) ;
30+
test( hasnot , {} ) ;
31+
test( hasnot , '' ) ;
32+
test( hasnot , false ) ;
33+
test( hasnot , true ) ;
34+
test( hasnot , 0.1 ) ;
35+
test( hasnot , -0.5 ) ;
36+
test( hasnot , Math.PI ) ;
37+
test( hasnot , Math.E ) ;

0 commit comments

Comments
 (0)