-
Notifications
You must be signed in to change notification settings - Fork 10k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use binary search in getVisibleElements()
- Loading branch information
1 parent
50fe7c8
commit 351909a
Showing
3 changed files
with
99 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | ||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ | ||
/* globals expect, it, describe, binarySearchFirstItem */ | ||
|
||
'use strict'; | ||
|
||
describe('ui_utils', function() { | ||
|
||
describe('binary search', function() { | ||
function isTrue(boolean) { | ||
return boolean; | ||
} | ||
function isGreater3(number) { | ||
return number > 3; | ||
} | ||
|
||
it('empty array', function() { | ||
expect(binarySearchFirstItem([], isTrue)).toEqual(-1); | ||
}); | ||
it('single boolean entry', function() { | ||
expect(binarySearchFirstItem([false], isTrue)).toEqual(-1); | ||
expect(binarySearchFirstItem([true], isTrue)).toEqual(0); | ||
}); | ||
it('three boolean entries', function() { | ||
expect(binarySearchFirstItem([true, true, true], isTrue)).toEqual(0); | ||
expect(binarySearchFirstItem([false, true, true], isTrue)).toEqual(1); | ||
expect(binarySearchFirstItem([false, false, true], isTrue)).toEqual(2); | ||
expect(binarySearchFirstItem([false, false, false], isTrue)).toEqual(-1); | ||
}); | ||
it('three numeric entries', function() { | ||
expect(binarySearchFirstItem([0, 1, 2], isGreater3)).toEqual(-1); | ||
expect(binarySearchFirstItem([2, 3, 4], isGreater3)).toEqual(2); | ||
expect(binarySearchFirstItem([4, 5, 6], isGreater3)).toEqual(0); | ||
}); | ||
}); | ||
}); | ||
|
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