-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
6 changed files
with
239 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { UniqueHeap } from '../unique-heap'; | ||
|
||
describe('Unique Heap', () => { | ||
interface Result { | ||
name: string; | ||
} | ||
|
||
function compare(a: Result, b: Result): boolean { | ||
return a.name < b.name; | ||
} | ||
|
||
test('it should return no results when empty', () => { | ||
const heap = new UniqueHeap<Result>(compare, 'name'); | ||
expect(heap.topK(5)).toEqual([]); | ||
}); | ||
|
||
test("doesn't insert duplicate results", () => { | ||
const heap = new UniqueHeap<Result>(compare, 'name'); | ||
|
||
heap.append({ name: 'name' }); | ||
heap.append({ name: 'name' }); | ||
|
||
expect(heap.topK(2)).toEqual([expect.objectContaining({ name: 'name' })]); | ||
}); | ||
|
||
test('it should return results in reverse sorted order', () => { | ||
const heap = new UniqueHeap<Result>(compare, 'name'); | ||
|
||
const names = [ | ||
'alpha', | ||
'beta', | ||
'gamma', | ||
'delta', | ||
'epsilon', | ||
'zeta', | ||
'eta', | ||
'theta', | ||
'iota', | ||
'kappa', | ||
'lambda', | ||
'mu', | ||
'nu', | ||
'xi', | ||
'omicron', | ||
'pi', | ||
'rho', | ||
'sigma', | ||
'tau', | ||
'upsilon', | ||
'phi', | ||
'chi', | ||
'psi', | ||
'omega', | ||
]; | ||
|
||
for (const name of names) { | ||
heap.append({ name }); | ||
} | ||
|
||
const results = heap.topK(5); | ||
|
||
expect(results).toEqual([ | ||
expect.objectContaining({ name: 'zeta' }), | ||
expect.objectContaining({ name: 'xi' }), | ||
expect.objectContaining({ name: 'upsilon' }), | ||
expect.objectContaining({ name: 'theta' }), | ||
expect.objectContaining({ name: 'tau' }), | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.