Skip to content

Commit c872535

Browse files
🔍 test(Integer): Cover predicate functions.
1 parent ab258bd commit c872535

File tree

2 files changed

+79
-3
lines changed

2 files changed

+79
-3
lines changed

src/Integer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,19 +371,19 @@ export class Integer {
371371
}
372372

373373
isnegative ( ) {
374-
return this.is_negative ;
374+
return this.is_negative === -1 ? true : false ;
375375
}
376376

377377
ispositive ( ) {
378378
return this.sign() > 0 ;
379379
}
380380

381381
isnonnegative ( ) {
382-
return !this.negative();
382+
return !this.isnegative();
383383
}
384384

385385
isnonpositive ( ) {
386-
return !this.positive() ;
386+
return !this.ispositive() ;
387387
}
388388

389389
parity ( ) {

test/src/Integer/predicates.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,79 @@ test( 'ZZ.from("0").isnonzero()' , t => { t.is( ZZ.from("0").isnonzero() , fal
5454
test( 'ZZ.from("-0").isnonzero()' , t => { t.is( ZZ.from("-0").isnonzero() , false ) ; } ) ;
5555
test( 'ZZ.from("1").isnonzero()' , t => { t.is( ZZ.from("1").isnonzero() , true ) ; } ) ;
5656
test( 'ZZ.from("2").isnonzero()' , t => { t.is( ZZ.from("2").isnonzero() , true ) ; } ) ;
57+
58+
59+
test( 'ZZ.$_1().ispositive()' , t => { t.is( ZZ.$_1().ispositive() , false ) ; } ) ;
60+
test( 'ZZ.$0().ispositive()' , t => { t.is( ZZ.$0().ispositive() , false ) ; } ) ;
61+
test( 'ZZ.$1().ispositive()' , t => { t.is( ZZ.$1().ispositive() , true ) ; } ) ;
62+
63+
test( 'ZZ.from(-2).ispositive()' , t => { t.is( ZZ.from(-2).ispositive() , false ) ; } ) ;
64+
test( 'ZZ.from(-1).ispositive()' , t => { t.is( ZZ.from(-1).ispositive() , false ) ; } ) ;
65+
test( 'ZZ.from(0).ispositive()' , t => { t.is( ZZ.from(0).ispositive() , false ) ; } ) ;
66+
test( 'ZZ.from(-0).ispositive()' , t => { t.is( ZZ.from(-0).ispositive() , false ) ; } ) ;
67+
test( 'ZZ.from(1).ispositive()' , t => { t.is( ZZ.from(1).ispositive() , true ) ; } ) ;
68+
test( 'ZZ.from(2).ispositive()' , t => { t.is( ZZ.from(2).ispositive() , true ) ; } ) ;
69+
70+
test( 'ZZ.from("-2").ispositive()' , t => { t.is( ZZ.from("-2").ispositive() , false ) ; } ) ;
71+
test( 'ZZ.from("-1").ispositive()' , t => { t.is( ZZ.from("-1").ispositive() , false ) ; } ) ;
72+
test( 'ZZ.from("0").ispositive()' , t => { t.is( ZZ.from("0").ispositive() , false ) ; } ) ;
73+
test( 'ZZ.from("-0").ispositive()' , t => { t.is( ZZ.from("-0").ispositive() , false ) ; } ) ;
74+
test( 'ZZ.from("1").ispositive()' , t => { t.is( ZZ.from("1").ispositive() , true ) ; } ) ;
75+
test( 'ZZ.from("2").ispositive()' , t => { t.is( ZZ.from("2").ispositive() , true ) ; } ) ;
76+
77+
78+
test( 'ZZ.$_1().isnegative()' , t => { t.is( ZZ.$_1().isnegative() , true ) ; } ) ;
79+
test( 'ZZ.$0().isnegative()' , t => { t.is( ZZ.$0().isnegative() , false ) ; } ) ;
80+
test( 'ZZ.$1().isnegative()' , t => { t.is( ZZ.$1().isnegative() , false ) ; } ) ;
81+
82+
test( 'ZZ.from(-2).isnegative()' , t => { t.is( ZZ.from(-2).isnegative() , true ) ; } ) ;
83+
test( 'ZZ.from(-1).isnegative()' , t => { t.is( ZZ.from(-1).isnegative() , true ) ; } ) ;
84+
test( 'ZZ.from(0).isnegative()' , t => { t.is( ZZ.from(0).isnegative() , false ) ; } ) ;
85+
test( 'ZZ.from(-0).isnegative()' , t => { t.is( ZZ.from(-0).isnegative() , false ) ; } ) ;
86+
test( 'ZZ.from(1).isnegative()' , t => { t.is( ZZ.from(1).isnegative() , false ) ; } ) ;
87+
test( 'ZZ.from(2).isnegative()' , t => { t.is( ZZ.from(2).isnegative() , false ) ; } ) ;
88+
89+
test( 'ZZ.from("-2").isnegative()' , t => { t.is( ZZ.from("-2").isnegative() , true ) ; } ) ;
90+
test( 'ZZ.from("-1").isnegative()' , t => { t.is( ZZ.from("-1").isnegative() , true ) ; } ) ;
91+
test( 'ZZ.from("0").isnegative()' , t => { t.is( ZZ.from("0").isnegative() , false ) ; } ) ;
92+
test( 'ZZ.from("-0").isnegative()' , t => { t.is( ZZ.from("-0").isnegative() , false ) ; } ) ;
93+
test( 'ZZ.from("1").isnegative()' , t => { t.is( ZZ.from("1").isnegative() , false ) ; } ) ;
94+
test( 'ZZ.from("2").isnegative()' , t => { t.is( ZZ.from("2").isnegative() , false ) ; } ) ;
95+
96+
97+
test( 'ZZ.$_1().isnonnegative()' , t => { t.is( ZZ.$_1().isnonnegative() , false ) ; } ) ;
98+
test( 'ZZ.$0().isnonnegative()' , t => { t.is( ZZ.$0().isnonnegative() , true ) ; } ) ;
99+
test( 'ZZ.$1().isnonnegative()' , t => { t.is( ZZ.$1().isnonnegative() , true ) ; } ) ;
100+
101+
test( 'ZZ.from(-2).isnonnegative()' , t => { t.is( ZZ.from(-2).isnonnegative() , false ) ; } ) ;
102+
test( 'ZZ.from(-1).isnonnegative()' , t => { t.is( ZZ.from(-1).isnonnegative() , false ) ; } ) ;
103+
test( 'ZZ.from(0).isnonnegative()' , t => { t.is( ZZ.from(0).isnonnegative() , true ) ; } ) ;
104+
test( 'ZZ.from(-0).isnonnegative()' , t => { t.is( ZZ.from(-0).isnonnegative() , true ) ; } ) ;
105+
test( 'ZZ.from(1).isnonnegative()' , t => { t.is( ZZ.from(1).isnonnegative() , true ) ; } ) ;
106+
test( 'ZZ.from(2).isnonnegative()' , t => { t.is( ZZ.from(2).isnonnegative() , true ) ; } ) ;
107+
108+
test( 'ZZ.from("-2").isnonnegative()' , t => { t.is( ZZ.from("-2").isnonnegative() , false ) ; } ) ;
109+
test( 'ZZ.from("-1").isnonnegative()' , t => { t.is( ZZ.from("-1").isnonnegative() , false ) ; } ) ;
110+
test( 'ZZ.from("0").isnonnegative()' , t => { t.is( ZZ.from("0").isnonnegative() , true ) ; } ) ;
111+
test( 'ZZ.from("-0").isnonnegative()' , t => { t.is( ZZ.from("-0").isnonnegative() , true ) ; } ) ;
112+
test( 'ZZ.from("1").isnonnegative()' , t => { t.is( ZZ.from("1").isnonnegative() , true ) ; } ) ;
113+
test( 'ZZ.from("2").isnonnegative()' , t => { t.is( ZZ.from("2").isnonnegative() , true ) ; } ) ;
114+
115+
116+
test( 'ZZ.$_1().isnonpositive()' , t => { t.is( ZZ.$_1().isnonpositive() , true ) ; } ) ;
117+
test( 'ZZ.$0().isnonpositive()' , t => { t.is( ZZ.$0().isnonpositive() , true ) ; } ) ;
118+
test( 'ZZ.$1().isnonpositive()' , t => { t.is( ZZ.$1().isnonpositive() , false ) ; } ) ;
119+
120+
test( 'ZZ.from(-2).isnonpositive()' , t => { t.is( ZZ.from(-2).isnonpositive() , true ) ; } ) ;
121+
test( 'ZZ.from(-1).isnonpositive()' , t => { t.is( ZZ.from(-1).isnonpositive() , true ) ; } ) ;
122+
test( 'ZZ.from(0).isnonpositive()' , t => { t.is( ZZ.from(0).isnonpositive() , true ) ; } ) ;
123+
test( 'ZZ.from(-0).isnonpositive()' , t => { t.is( ZZ.from(-0).isnonpositive() , true ) ; } ) ;
124+
test( 'ZZ.from(1).isnonpositive()' , t => { t.is( ZZ.from(1).isnonpositive() , false ) ; } ) ;
125+
test( 'ZZ.from(2).isnonpositive()' , t => { t.is( ZZ.from(2).isnonpositive() , false ) ; } ) ;
126+
127+
test( 'ZZ.from("-2").isnonpositive()' , t => { t.is( ZZ.from("-2").isnonpositive() , true ) ; } ) ;
128+
test( 'ZZ.from("-1").isnonpositive()' , t => { t.is( ZZ.from("-1").isnonpositive() , true ) ; } ) ;
129+
test( 'ZZ.from("0").isnonpositive()' , t => { t.is( ZZ.from("0").isnonpositive() , true ) ; } ) ;
130+
test( 'ZZ.from("-0").isnonpositive()' , t => { t.is( ZZ.from("-0").isnonpositive() , true ) ; } ) ;
131+
test( 'ZZ.from("1").isnonpositive()' , t => { t.is( ZZ.from("1").isnonpositive() , false ) ; } ) ;
132+
test( 'ZZ.from("2").isnonpositive()' , t => { t.is( ZZ.from("2").isnonpositive() , false ) ; } ) ;

0 commit comments

Comments
 (0)