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 {
79
79
}
80
80
return true ;
81
81
}
82
+
82
83
/**
83
84
* Constructor
84
85
* @param uintArray
@@ -135,4 +136,15 @@ export class UInt64 {
135
136
public equals ( other : UInt64 ) : boolean {
136
137
return this . lower === other . lower && this . higher === other . higher ;
137
138
}
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
+ }
138
150
}
Original file line number Diff line number Diff line change @@ -93,6 +93,26 @@ describe('Uint64', () => {
93
93
} ) ;
94
94
} ) ;
95
95
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
+
96
116
describe ( 'fromHex' , ( ) => {
97
117
it ( 'should create from hexadecimal notation' , ( ) => {
98
118
hexTestCases . forEach ( ( testCase ) => {
You can’t perform that action at this time.
0 commit comments