Skip to content

Commit 8bc9597

Browse files
authored
Merge branch 'master' into task/g381_repositoryInterfacesAndFactory
2 parents c39224a + a636a12 commit 8bc9597

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

src/infrastructure/Listener.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,8 @@ export class Listener implements IListener {
108108
this.webSocket = new WebSocket(this.url);
109109
}
110110
this.webSocket.onopen = () => {
111-
console.log('connection open');
112111
};
113112
this.webSocket.onerror = (err) => {
114-
console.log('WebSocket Error ');
115-
console.log(err);
116113
reject(err);
117114
};
118115
this.webSocket.onmessage = (msg) => {

src/model/UInt64.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,37 @@ export class UInt64 {
147147
const long_b = Long.fromBits(other.lower, other.higher, true);
148148
return long_a.compare(long_b);
149149
}
150+
151+
/**
152+
* UInt64 add operation
153+
* @param other
154+
* @returns {UInt64}
155+
*/
156+
public add(other: UInt64): UInt64 {
157+
const long_value = Long.fromBits(this.lower, this.higher, true);
158+
const long_b = Long.fromBits(other.lower, other.higher, true);
159+
return this.longToUint64(long_value.add(long_b));
160+
}
161+
162+
/**
163+
* UInt64 add operation
164+
* @param other
165+
* @returns {UInt64}
166+
*/
167+
public subtract(other: UInt64): UInt64 {
168+
const long_value = Long.fromBits(this.lower, this.higher, true);
169+
const long_b = Long.fromBits(other.lower, other.higher, true);
170+
if (long_value.compare(long_b) < 0) {
171+
throw new Error('Unsigned substraction result cannot be negative.');
172+
}
173+
return this.longToUint64(long_value.subtract(long_b));
174+
}
175+
176+
/**
177+
* Convert long value to UInt64
178+
* @param longValue long value
179+
*/
180+
private longToUint64(longValue: Long): UInt64 {
181+
return new UInt64([longValue.getLowBitsUnsigned(), longValue.getHighBitsUnsigned()]);
182+
}
150183
}

test/model/UInt64.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,41 @@ describe('Uint64', () => {
185185
expect(result).to.be.true;
186186
});
187187
});
188+
189+
describe('Operation', () => {
190+
it('should return added value', () => {
191+
const value = UInt64.fromUint(100);
192+
const other = UInt64.fromUint(1);
193+
const result = value.add(other);
194+
expect(result.compact()).to.be.equal(101);
195+
});
196+
it('should return added value', () => {
197+
const value = UInt64.fromUint(0);
198+
const other = UInt64.fromUint(0);
199+
const result = value.add(other);
200+
expect(result.compact()).to.be.equal(0);
201+
});
202+
203+
it('should return substract value', () => {
204+
const value = UInt64.fromUint(100);
205+
const other = UInt64.fromUint(1);
206+
const result = value.subtract(other);
207+
expect(result.compact()).to.be.equal(99);
208+
});
209+
210+
it('should return substract value', () => {
211+
const value = UInt64.fromUint(1);
212+
const other = UInt64.fromUint(1);
213+
const result = value.subtract(other);
214+
expect(result.compact()).to.be.equal(0);
215+
});
216+
217+
it('should return substract value', () => {
218+
const value = UInt64.fromUint(100);
219+
const other = UInt64.fromUint(1);
220+
expect(() => {
221+
other.subtract(value);
222+
}).to.throw(Error, 'Unsigned substraction result cannot be negative.');
223+
});
224+
});
188225
});

0 commit comments

Comments
 (0)