File tree Expand file tree Collapse file tree 5 files changed +65
-2
lines changed Expand file tree Collapse file tree 5 files changed +65
-2
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export class HexQuantity extends EntityBase implements Entity {
14
14
}
15
15
16
16
valid ( ) : boolean {
17
- return Number . isInteger ( parseInt ( this . hexString , 16 ) )
17
+ var a = parseInt ( this . hexString , 16 ) ;
18
+ return ( a . toString ( 16 ) === this . hexString )
18
19
}
19
20
}
Original file line number Diff line number Diff line change
1
+
2
+ import { Entity } from '../interfaces/Entity'
3
+ import { EntityBase } from './EntityBase'
4
+ /*
5
+ * @see https://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hexadecimal-in-javascript
6
+ */
7
+ export class PositiveNumber extends EntityBase implements Entity {
8
+ public errorMessage :string = 'invalid'
9
+ private positiveNumber :any
10
+
11
+ constructor ( positiveNumber : any ) {
12
+ super ( )
13
+ this . positiveNumber = positiveNumber
14
+ }
15
+
16
+ valid ( ) : boolean {
17
+
18
+ let numerical = parseInt ( this . positiveNumber )
19
+
20
+ if ( numerical < 0 ) {
21
+ return false
22
+ }
23
+ return true
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ export enum operand { and = 'and' , or = 'or' }
Original file line number Diff line number Diff line change @@ -3,8 +3,22 @@ import test from 'ava'
3
3
import { HexQuantity } from '../../src/entities/HexQuantity'
4
4
5
5
test ( 'Instantiated' , ( t ) => {
6
- const hex = 'TRU5Z5MNWIEYP4F6DPH2T53IJWZIZ5GT1W '
6
+ const hex = '0x10FB78 '
7
7
const a = new HexQuantity ( hex )
8
8
t . truthy ( a )
9
9
} )
10
10
11
+ test . skip ( 'valid' , ( t ) => {
12
+ const hex = '10FB78'
13
+ const a = new HexQuantity ( hex )
14
+ t . truthy ( a . valid ( ) )
15
+ } )
16
+
17
+ test ( 'invalid' , ( t ) => {
18
+ const hex = 'bar'
19
+ const a = new HexQuantity ( hex )
20
+ t . falsy ( a . valid ( ) )
21
+ } )
22
+
23
+
24
+
Original file line number Diff line number Diff line change
1
+ import test from 'ava'
2
+
3
+ import { PositiveNumber } from '../../src/entities/PositiveNumber'
4
+
5
+
6
+ test ( '1 is valid' , t => {
7
+ const numerical = 1 ;
8
+ const n = new PositiveNumber ( numerical )
9
+ t . truthy ( n . valid ( ) )
10
+ } )
11
+
12
+ test ( '0 is valid' , t => {
13
+ const numerical = 0 ;
14
+ const n = new PositiveNumber ( numerical )
15
+ t . truthy ( n . valid ( ) )
16
+ } )
17
+
18
+ test ( '-1 is invalid' , t => {
19
+ const numerical = - 1 ;
20
+ const n = new PositiveNumber ( numerical )
21
+ t . falsy ( n . valid ( ) )
22
+ } )
You can’t perform that action at this time.
0 commit comments