-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- workspaces
- pre-template-literals
- pre-prettier-v3
- pre-prettier
- pre-let-const
- post-workspaces
- post-template-literals
- post-prettier-v3
- post-prettier
- post-let-const
- cesium-workspaces
- 1.125
- 1.124
- 1.123.1
- 1.123
- 1.122
- 1.121.1
- 1.121
- 1.120
- 1.119
- 1.118.2
- 1.118.1
- 1.118
- 1.117
- 1.116
- 1.115
- 1.114
- 1.113
- 1.112
- 1.111
- 1.111-release
- 1.110.1
- 1.110
- 1.109
- 1.108
- 1.107.2
- 1.107.1
- 1.107
- 1.106.1
- 1.106
- 1.105.2
- 1.105.1
- 1.105
- 1.104
- 1.103
- 1.102
- 1.101
- 1.100
- 1.99
- 1.98.1
- 1.98
- 1.97
- 1.96
- 1.95
- 1.94.3
- 1.94.2
- 1.94.1
- 1.94
- 1.93
- 1.92
- 1.91
- 1.90
- 1.89
- 1.88
- 1.87.1
- 1.87
- 1.86.1
- 1.86
- 1.85
- 1.84
- 1.83
- 1.82
- 1.81
- 1.80
- 1.79.1
- 1.79
- 1.78
- 1.77
- 1.76
- 1.75
- 1.74
- 1.73
- 1.72
- 1.71
- 1.70.1
- 1.70
- 1.69
- 1.68
- 1.67
- 1.66
- 1.65
- 1.64
- 1.63.1
- 1.63
- 1.62
- 1.61
- 1.60
- 1.59
- 1.58.1
- 1.58
- 1.57
- 1.56.1
- 1.56
- 1.55
- 1.54
- 1.53
- 1.52
- 1.51
- 1.50
- 1.49
Showing
6 changed files
with
234 additions
and
441 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,174 @@ | ||
defineSuite([ | ||
'Core/Heap' | ||
], function( | ||
Heap) { | ||
'use strict'; | ||
|
||
var length = 100; | ||
|
||
function checkHeap(heap, comparator) { | ||
var array = heap.internalArray; | ||
var pass = true; | ||
var length = heap.length; | ||
for (var i = 0; i < length; ++i) { | ||
var left = 2 * (i + 1) - 1; | ||
var right = 2 * (i + 1); | ||
if (left < heap.length) { | ||
pass = pass && (comparator(array[i], array[left]) <= 0); | ||
} | ||
if (right < heap.length) { | ||
pass = pass && (comparator(array[i], array[right]) <= 0); | ||
} | ||
} | ||
return pass; | ||
} | ||
|
||
// min heap | ||
function comparator(a, b) { | ||
return a - b; | ||
} | ||
|
||
it('maintains heap property on insert', function() { | ||
var heap = new Heap({ | ||
comparator : comparator | ||
}); | ||
var pass = true; | ||
for (var i = 0; i < length; ++i) { | ||
heap.insert(Math.random()); | ||
pass = pass && checkHeap(heap, comparator); | ||
} | ||
|
||
expect(pass).toBe(true); | ||
}); | ||
|
||
it('maintains heap property on pop', function() { | ||
var heap = new Heap({ | ||
comparator : comparator | ||
}); | ||
var i; | ||
for (i = 0; i < length; ++i) { | ||
heap.insert(Math.random()); | ||
} | ||
var pass = true; | ||
for (i = 0; i < length; ++i) { | ||
heap.pop(); | ||
pass = pass && checkHeap(heap, comparator); | ||
} | ||
expect(pass).toBe(true); | ||
}); | ||
|
||
it('limited by maximum length', function() { | ||
var heap = new Heap({ | ||
comparator : comparator | ||
}); | ||
heap.maximumLength = length / 2; | ||
var pass = true; | ||
for (var i = 0; i < length; ++i) { | ||
heap.insert(Math.random()); | ||
pass = pass && checkHeap(heap, comparator); | ||
} | ||
expect(pass).toBe(true); | ||
expect(heap.length <= heap.maximumLength).toBe(true); | ||
// allowed one extra slot for swapping | ||
expect(heap.internalArray.length).toBeLessThanOrEqualTo(heap.maximumLength + 1); | ||
}); | ||
|
||
it('pops in sorted order', function() { | ||
var heap = new Heap({ | ||
comparator : comparator | ||
}); | ||
var i; | ||
for (i = 0; i < length; ++i) { | ||
heap.insert(Math.random()); | ||
} | ||
var curr = heap.pop(); | ||
var pass = true; | ||
for (i = 0; i < length - 1; ++i) { | ||
var next = heap.pop(); | ||
pass = pass && (comparator(curr, next) <= 0); | ||
curr = next; | ||
} | ||
expect(pass).toBe(true); | ||
}); | ||
|
||
it('insert returns the removed element when maximumLength is set', function() { | ||
var heap = new Heap({ | ||
comparator : comparator | ||
}); | ||
heap.maximumLength = length; | ||
|
||
var i; | ||
var max = 0.0; | ||
var min = 1.0; | ||
var values = new Array(length); | ||
for (i = 0; i < length; ++i) { | ||
var value = Math.random(); | ||
max = Math.max(max, value); | ||
min = Math.min(min, value); | ||
values[i] = value; | ||
} | ||
|
||
// Push 99 values | ||
for (i = 0; i < length - 1; ++i) { | ||
heap.insert(values[i]); | ||
} | ||
|
||
// Push 100th, nothing is removed so it returns undefined | ||
var removed = heap.insert(values[length - 1]); | ||
expect(removed).toBeUndefined(); | ||
|
||
// Insert value, an element is removed | ||
removed = heap.insert(max - 0.1); | ||
expect(removed).toBeDefined(); | ||
|
||
// If this value is the least priority it will be returned | ||
removed = heap.insert(max + 0.1); | ||
expect(removed).toBe(max + 0.1); | ||
}); | ||
|
||
it('resort', function() { | ||
function comparator(a, b) { | ||
return a.distance - b.distance; | ||
} | ||
|
||
var i; | ||
var heap = new Heap({ | ||
comparator : comparator | ||
}); | ||
for (i = 0; i < length; ++i) { | ||
heap.insert({ | ||
distance : i / (length - 1), | ||
id : i | ||
}); | ||
} | ||
|
||
// Check that elements are initially sorted | ||
var element; | ||
var elements = []; | ||
var currentId = 0; | ||
while (heap.length > 0) { | ||
element = heap.pop(); | ||
elements.push(element); | ||
expect(element.id).toBeGreaterThanOrEqualTo(currentId); | ||
currentId = element.id; | ||
} | ||
|
||
// Add back into heap | ||
for (i = 0; i < length; ++i) { | ||
heap.insert(elements[i]); | ||
} | ||
|
||
// Invert priority | ||
for (i = 0; i < length; ++i) { | ||
elements[i].distance = 1.0 - elements[i].distance; | ||
} | ||
|
||
// Resort and check the the elements are popped in the opposite order now | ||
heap.resort(); | ||
while (heap.length > 0) { | ||
element = heap.pop(); | ||
expect(element.id).toBeLessThanOrEqualTo(currentId); | ||
currentId = element.id; | ||
} | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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