|
| 1 | +'use strict' |
| 2 | + |
| 3 | +// MIT License |
| 4 | +// |
| 5 | +// Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com) |
| 6 | +// |
| 7 | +// Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | +// copy of this software and associated documentation files (the "Software"), |
| 9 | +// to deal in the Software without restriction, including without limitation |
| 10 | +// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | +// and/or sell copies of the Software, and to permit persons to whom the Software |
| 12 | +// is furnished to do so, subject to the following conditions: |
| 13 | +// |
| 14 | +// The above copyright notice and this permission notice shall be included in all |
| 15 | +// copies or substantial portions of the Software. |
| 16 | +// |
| 17 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 18 | +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
| 19 | +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 20 | +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 21 | +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 22 | +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | + |
| 24 | +import fnv1a from '../src/fnv1a' |
| 25 | + |
| 26 | +describe('fnv1a tests', () => { |
| 27 | + it('works for string', () => { |
| 28 | + expect(fnv1a('')).toEqual(2166136261) |
| 29 | + expect(fnv1a('🦄🌈')).toEqual(582881315) |
| 30 | + expect(fnv1a('h')).toEqual(3977000791) |
| 31 | + expect(fnv1a('he')).toEqual(1547363254) |
| 32 | + expect(fnv1a('hel')).toEqual(179613742) |
| 33 | + expect(fnv1a('hell')).toEqual(477198310) |
| 34 | + expect(fnv1a('hello')).toEqual(1335831723) |
| 35 | + expect(fnv1a('hello ')).toEqual(3801292497) |
| 36 | + expect(fnv1a('hello w')).toEqual(1402552146) |
| 37 | + expect(fnv1a('hello wo')).toEqual(3611200775) |
| 38 | + expect(fnv1a('hello wor')).toEqual(1282977583) |
| 39 | + expect(fnv1a('hello worl')).toEqual(2767971961) |
| 40 | + expect(fnv1a('hello world')).toEqual(3582672807) |
| 41 | + expect( |
| 42 | + fnv1a( |
| 43 | + 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.' |
| 44 | + ) |
| 45 | + ).toEqual(2964896417) |
| 46 | + }) |
| 47 | + |
| 48 | + it('works for buffer', () => { |
| 49 | + expect(fnv1a(Buffer.from(''))).toEqual(2166136261) |
| 50 | + expect(fnv1a(Buffer.from('🦄🌈'))).toEqual(2868248295) |
| 51 | + expect(fnv1a(Buffer.from('h'))).toEqual(3977000791) |
| 52 | + expect(fnv1a(Buffer.from('he'))).toEqual(1547363254) |
| 53 | + expect(fnv1a(Buffer.from('hel'))).toEqual(179613742) |
| 54 | + expect(fnv1a(Buffer.from('hell'))).toEqual(477198310) |
| 55 | + expect(fnv1a(Buffer.from('hello'))).toEqual(1335831723) |
| 56 | + expect(fnv1a(Buffer.from('hello '))).toEqual(3801292497) |
| 57 | + expect(fnv1a(Buffer.from('hello w'))).toEqual(1402552146) |
| 58 | + expect(fnv1a(Buffer.from('hello wo'))).toEqual(3611200775) |
| 59 | + expect(fnv1a(Buffer.from('hello wor'))).toEqual(1282977583) |
| 60 | + expect(fnv1a(Buffer.from('hello worl'))).toEqual(2767971961) |
| 61 | + expect(fnv1a(Buffer.from('hello world'))).toEqual(3582672807) |
| 62 | + expect( |
| 63 | + fnv1a( |
| 64 | + Buffer.from( |
| 65 | + 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.' |
| 66 | + ) |
| 67 | + ) |
| 68 | + ).toEqual(2964896417) |
| 69 | + }) |
| 70 | + |
| 71 | + it("can't hash objects", () => { |
| 72 | + expect(() => fnv1a({})).toThrow(Error) |
| 73 | + }) |
| 74 | +}) |
0 commit comments