|
| 1 | +/* |
| 2 | + * Copyright 2019 NEM |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +import { expect } from 'chai'; |
| 17 | +import { UInt64 } from '../../../src/model/UInt64'; |
| 18 | +import { KeyGenerator } from '../../../src/core/format/KeyGenerator'; |
| 19 | + |
| 20 | +describe('key generator', () => { |
| 21 | + describe('generate key from string', () => { |
| 22 | + it('throws if input is empty', () => { |
| 23 | + expect(() => KeyGenerator.generateUInt64Key('')).to.throw(Error, 'Input must not be empty'); |
| 24 | + }) |
| 25 | + it('returns UInt64', () => { |
| 26 | + expect(KeyGenerator.generateUInt64Key('a')).to.be.instanceOf(UInt64); |
| 27 | + }) |
| 28 | + it('generates correct keys', () => { |
| 29 | + expect(KeyGenerator.generateUInt64Key('a').toHex()).to.equal('F524A0FBF24B0880'); |
| 30 | + }) |
| 31 | + it('generates keys deterministically', () => { |
| 32 | + expect(KeyGenerator.generateUInt64Key('abc').toHex()).to.equal('B225E24FA75D983A'); |
| 33 | + expect(KeyGenerator.generateUInt64Key('abc').toHex()).to.equal('B225E24FA75D983A'); |
| 34 | + expect(KeyGenerator.generateUInt64Key('def').toHex()).to.equal('B0AC5222678F0D8E'); |
| 35 | + expect(KeyGenerator.generateUInt64Key('def').toHex()).to.equal('B0AC5222678F0D8E'); |
| 36 | + expect(KeyGenerator.generateUInt64Key('abc').toHex()).to.equal('B225E24FA75D983A'); |
| 37 | + }) |
| 38 | + }) |
| 39 | +}); |
0 commit comments