[Plot] Add test cases
Add test cases for plot line management, WTD-806.
This commit is contained in:
@@ -14,14 +14,14 @@ define(
|
|||||||
return end - start;
|
return end - start;
|
||||||
},
|
},
|
||||||
getDomainValue: function (index) {
|
getDomainValue: function (index) {
|
||||||
return series.getDomainValue(index - start, domain);
|
return series.getDomainValue(index + start, domain);
|
||||||
},
|
},
|
||||||
getRangeValue: function (index) {
|
getRangeValue: function (index) {
|
||||||
return series.getRangeValue(index - start, range);
|
return series.getRangeValue(index + start, range);
|
||||||
},
|
},
|
||||||
split: function () {
|
split: function () {
|
||||||
var mid = Math.floor((end + start) / 2);
|
var mid = Math.floor((end + start) / 2);
|
||||||
return end > start ?
|
return ((end - start) > 1) ?
|
||||||
[
|
[
|
||||||
new PlotSeriesWindow(
|
new PlotSeriesWindow(
|
||||||
series,
|
series,
|
||||||
@@ -34,7 +34,7 @@ define(
|
|||||||
series,
|
series,
|
||||||
domain,
|
domain,
|
||||||
range,
|
range,
|
||||||
mid + 1,
|
mid,
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
] : [];
|
] : [];
|
||||||
|
|||||||
@@ -85,6 +85,31 @@ define(
|
|||||||
).toEqual([ -35, 3, -33, 9, -28, 8, -27, 11]);
|
).toEqual([ -35, 3, -33, 9, -28, 8, -27, 11]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("expands buffer when needed to accommodate more data", function () {
|
||||||
|
var i;
|
||||||
|
|
||||||
|
// Initial underlying buffer should be twice initial size...
|
||||||
|
// (Since each pair will take up two elements)
|
||||||
|
expect(buffer.getBuffer().length).toEqual(20);
|
||||||
|
|
||||||
|
// Should be able to insert 6 series of 6 points each
|
||||||
|
// (After that, we'll hit the test max of 40)
|
||||||
|
for (i = 1; i < 15; i += 1) {
|
||||||
|
expect(buffer.insertPoint(i * 10, Math.sin(i), i))
|
||||||
|
.toBeTruthy();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Buffer should have expanded in the process
|
||||||
|
expect(buffer.getBuffer().length).toEqual(40);
|
||||||
|
|
||||||
|
// Push to maximum size just to make sure...
|
||||||
|
for (i = 1; i < 150; i += 1) {
|
||||||
|
buffer.insertPoint(i * 10, Math.sin(i), i);
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(buffer.getBuffer().length).toEqual(80);
|
||||||
|
});
|
||||||
|
|
||||||
it("ensures a maximum size", function () {
|
it("ensures a maximum size", function () {
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ define(
|
|||||||
|
|
||||||
mockBuffer = jasmine.createSpyObj(
|
mockBuffer = jasmine.createSpyObj(
|
||||||
'buffer',
|
'buffer',
|
||||||
['findInsertionIndex', 'insert', 'insertPoint']
|
['findInsertionIndex', 'insert', 'insertPoint', 'trim']
|
||||||
);
|
);
|
||||||
mockSeries = jasmine.createSpyObj(
|
mockSeries = jasmine.createSpyObj(
|
||||||
'series',
|
'series',
|
||||||
@@ -31,10 +31,10 @@ define(
|
|||||||
return testSeries.length;
|
return testSeries.length;
|
||||||
});
|
});
|
||||||
mockSeries.getDomainValue.andCallFake(function (i) {
|
mockSeries.getDomainValue.andCallFake(function (i) {
|
||||||
return testSeries[i][0];
|
return (testSeries[i] || [])[0];
|
||||||
});
|
});
|
||||||
mockSeries.getRangeValue.andCallFake(function (i) {
|
mockSeries.getRangeValue.andCallFake(function (i) {
|
||||||
return testSeries[i][1];
|
return (testSeries[i] || [])[1];
|
||||||
});
|
});
|
||||||
|
|
||||||
// Function like PlotLineBuffer, to aid in testability
|
// Function like PlotLineBuffer, to aid in testability
|
||||||
@@ -98,6 +98,17 @@ define(
|
|||||||
expect(testRangeBuffer).toEqual([42, 1, 200, 12321]);
|
expect(testRangeBuffer).toEqual([42, 1, 200, 12321]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("attempts to remove points when insertion fails", function () {
|
||||||
|
// Verify precondition - normally doesn't try to trim
|
||||||
|
line.addPoint(1, 2);
|
||||||
|
expect(mockBuffer.trim).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
// But if insertPoint fails, it should trim
|
||||||
|
mockBuffer.insertPoint.andReturn(false);
|
||||||
|
line.addPoint(2, 3);
|
||||||
|
expect(mockBuffer.trim).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -6,6 +6,68 @@ define(
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("A plot's window on a telemetry series", function () {
|
describe("A plot's window on a telemetry series", function () {
|
||||||
|
var mockSeries,
|
||||||
|
testSeries,
|
||||||
|
window;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
testSeries = [
|
||||||
|
[ 0, 42 ],
|
||||||
|
[ 10, 1 ],
|
||||||
|
[ 20, 4 ],
|
||||||
|
[ 30, 9 ],
|
||||||
|
[ 40, 3 ]
|
||||||
|
];
|
||||||
|
|
||||||
|
mockSeries = jasmine.createSpyObj(
|
||||||
|
'series',
|
||||||
|
['getPointCount', 'getDomainValue', 'getRangeValue']
|
||||||
|
);
|
||||||
|
|
||||||
|
mockSeries.getPointCount.andCallFake(function () {
|
||||||
|
return testSeries.length;
|
||||||
|
});
|
||||||
|
mockSeries.getDomainValue.andCallFake(function (i) {
|
||||||
|
return testSeries[i][0];
|
||||||
|
});
|
||||||
|
mockSeries.getRangeValue.andCallFake(function (i) {
|
||||||
|
return testSeries[i][1];
|
||||||
|
});
|
||||||
|
|
||||||
|
window = new PlotSeriesWindow(
|
||||||
|
mockSeries,
|
||||||
|
"testDomain",
|
||||||
|
"testRange",
|
||||||
|
1,
|
||||||
|
testSeries.length
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("provides a window upon a data series", function () {
|
||||||
|
expect(window.getPointCount()).toEqual(4);
|
||||||
|
expect(window.getDomainValue(0)).toEqual(10);
|
||||||
|
expect(window.getRangeValue(0)).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("looks up using specific domain/range keys", function () {
|
||||||
|
window.getDomainValue(0);
|
||||||
|
window.getRangeValue(0);
|
||||||
|
expect(mockSeries.getDomainValue)
|
||||||
|
.toHaveBeenCalledWith(1, 'testDomain');
|
||||||
|
expect(mockSeries.getRangeValue)
|
||||||
|
.toHaveBeenCalledWith(1, 'testRange');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("can be split into smaller windows", function () {
|
||||||
|
var windows = window.split();
|
||||||
|
expect(windows.length).toEqual(2);
|
||||||
|
expect(windows[0].getPointCount()).toEqual(2);
|
||||||
|
expect(windows[1].getPointCount()).toEqual(2);
|
||||||
|
expect(windows[0].getDomainValue(0)).toEqual(10);
|
||||||
|
expect(windows[1].getDomainValue(0)).toEqual(30);
|
||||||
|
expect(windows[0].getRangeValue(0)).toEqual(1);
|
||||||
|
expect(windows[1].getRangeValue(0)).toEqual(9);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user