File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ export class UInt64 {
7979 }
8080 return true ;
8181 }
82+
8283 /**
8384 * Constructor
8485 * @param uintArray
@@ -135,4 +136,15 @@ export class UInt64 {
135136 public equals ( other : UInt64 ) : boolean {
136137 return this . lower === other . lower && this . higher === other . higher ;
137138 }
139+
140+ /**
141+ * Compares two UInt64
142+ * @param other
143+ * @returns {number } - -1, 0, 1
144+ */
145+ public compare ( other : UInt64 ) : number {
146+ const long_a = Long . fromBits ( this . lower , this . higher , true ) ;
147+ const long_b = Long . fromBits ( other . lower , other . higher , true ) ;
148+ return long_a . compare ( long_b ) ;
149+ }
138150}
Original file line number Diff line number Diff line change @@ -93,6 +93,26 @@ describe('Uint64', () => {
9393 } ) ;
9494 } ) ;
9595
96+ describe ( 'compare' , ( ) => {
97+ it ( 'should return -1 - unsigned' , ( ) => {
98+ const value = UInt64 . fromNumericString ( '1' ) ;
99+ const other = UInt64 . fromNumericString ( '2' ) ;
100+ expect ( value . compare ( other ) ) . to . be . equal ( - 1 ) ;
101+ } ) ;
102+
103+ it ( 'should return 0 - unsigned' , ( ) => {
104+ const value = UInt64 . fromNumericString ( '1' ) ;
105+ const other = UInt64 . fromNumericString ( '1' ) ;
106+ expect ( value . compare ( other ) ) . to . be . equal ( 0 ) ;
107+ } ) ;
108+
109+ it ( 'should return 1 - unsigned' , ( ) => {
110+ const value = UInt64 . fromNumericString ( '2' ) ;
111+ const other = UInt64 . fromNumericString ( '1' ) ;
112+ expect ( value . compare ( other ) ) . to . be . equal ( 1 ) ;
113+ } ) ;
114+ } ) ;
115+
96116 describe ( 'fromHex' , ( ) => {
97117 it ( 'should create from hexadecimal notation' , ( ) => {
98118 hexTestCases . forEach ( ( testCase ) => {
You can’t perform that action at this time.
0 commit comments