Add message to assertions.

This commit is contained in:
Marc Jansen
2015-03-30 22:50:15 +02:00
parent 2c40d74a15
commit fb9ba22c30
45 changed files with 394 additions and 221 deletions

View File

@@ -63,7 +63,7 @@ ol.structs.PriorityQueue.DROP = Infinity;
/**
* FIXME empty desciption for jsdoc
* FIXME empty description for jsdoc
*/
ol.structs.PriorityQueue.prototype.assertValid = function() {
var elements = this.elements_;
@@ -73,8 +73,12 @@ ol.structs.PriorityQueue.prototype.assertValid = function() {
var i, priority;
for (i = 0; i < (n >> 1) - 1; ++i) {
priority = priorities[i];
goog.asserts.assert(priority <= priorities[this.getLeftChildIndex_(i)]);
goog.asserts.assert(priority <= priorities[this.getRightChildIndex_(i)]);
goog.asserts.assert(priority <= priorities[this.getLeftChildIndex_(i)],
'priority smaller than or equal to priority of left child (%s <= %s)',
priority, priorities[this.getLeftChildIndex_(i)]);
goog.asserts.assert(priority <= priorities[this.getRightChildIndex_(i)],
'priority smaller than or equal to priority of right child (%s <= %s)',
priority, priorities[this.getRightChildIndex_(i)]);
}
};
@@ -95,7 +99,8 @@ ol.structs.PriorityQueue.prototype.clear = function() {
*/
ol.structs.PriorityQueue.prototype.dequeue = function() {
var elements = this.elements_;
goog.asserts.assert(elements.length > 0);
goog.asserts.assert(elements.length > 0,
'must have elements in order to be able to dequeue');
var priorities = this.priorities_;
var element = elements[0];
if (elements.length == 1) {
@@ -107,7 +112,8 @@ ol.structs.PriorityQueue.prototype.dequeue = function() {
this.siftUp_(0);
}
var elementKey = this.keyFunction_(element);
goog.asserts.assert(elementKey in this.queuedElements_);
goog.asserts.assert(elementKey in this.queuedElements_,
'key %s is not listed as queued', elementKey);
delete this.queuedElements_[elementKey];
return element;
};
@@ -118,7 +124,8 @@ ol.structs.PriorityQueue.prototype.dequeue = function() {
* @param {T} element Element.
*/
ol.structs.PriorityQueue.prototype.enqueue = function(element) {
goog.asserts.assert(!(this.keyFunction_(element) in this.queuedElements_));
goog.asserts.assert(!(this.keyFunction_(element) in this.queuedElements_),
'key %s is already listed as queued', this.keyFunction_(element));
var priority = this.priorityFunction_(element);
if (priority != ol.structs.PriorityQueue.DROP) {
this.elements_.push(element);