Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Add testing for map subtract
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Loring committed Jan 15, 2016
1 parent 2ececd6 commit 8eadace
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/debuglet.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,13 @@ Debuglet.prototype.updateActiveBreakpoints_ = function(breakpoints) {
});

// Remove completed breakpoints that the server no longer cares about.
mapSubtract(this.completedBreakpointMap_, updatedBreakpointMap)
Debuglet.mapSubtract(this.completedBreakpointMap_, updatedBreakpointMap)
.forEach(function(breakpoint){
delete this.completedBreakpointMap_[breakpoint.id];
}, this);

// Remove active breakpoints that the server no longer care about.
mapSubtract(this.activeBreakpointMap_, updatedBreakpointMap)
Debuglet.mapSubtract(this.activeBreakpointMap_, updatedBreakpointMap)
.forEach(this.removeBreakpoint_, this);
};

Expand Down Expand Up @@ -396,17 +396,16 @@ Debuglet.prototype.stop = function() {

/**
* Performs a set subtract. Returns A - B given maps A, B.
* TODO(ofrobots): we need unit tests for this
* @return {Array.<Breakpoint>} A array containing elements from A that are not
* in B.
*/
function mapSubtract(A, B) {
Debuglet.mapSubtract = function mapSubtract(A, B) {
var removed = [];
for (var key in A) {
if (!B[key]) {
removed.push(A[key]);
}
}
return removed;
}
};

11 changes: 11 additions & 0 deletions test/standalone/test-debuglet.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,16 @@ describe(__filename, function(){

debuglet.start();
});

describe('map subtract', function() {
it('should be correct', function() {
var a = { a: 1, b: 2 };
var b = { a: 1 };
assert.deepEqual(Debuglet.mapSubtract(a, b), [2]);
assert.deepEqual(Debuglet.mapSubtract(b, a), []);
assert.deepEqual(Debuglet.mapSubtract(a, {}), [1, 2]);
assert.deepEqual(Debuglet.mapSubtract({}, b), []);
});
});
});

0 comments on commit 8eadace

Please sign in to comment.