Commit c57a4d9e authored by Wei-Meng Lee's avatar Wei-Meng Lee

Account for more edge cases

Also adjust code so we're handling these edge cases
the right way
parent ab1fe3ce
......@@ -53,13 +53,13 @@ export default class BurndownChartData {
// weight count on an given date. To mitigate this, we reset the current
// date's counters to 0 and carry forward the negative count to a future
// date until the total is positive again.
if (openIssuesCount <= 0 || openIssuesWeight <= 0) {
carriedIssuesCount = openIssuesCount;
carriedIssuesWeight = openIssuesWeight;
if (openIssuesCount + carriedIssuesCount < 0 || openIssuesWeight + carriedIssuesWeight < 0) {
carriedIssuesCount += openIssuesCount;
carriedIssuesWeight += openIssuesWeight;
openIssuesCount = 0;
openIssuesWeight = 0;
} else if (carriedIssuesCount < 0 || carriedIssuesWeight < 0) {
} else {
openIssuesCount += carriedIssuesCount;
openIssuesWeight += carriedIssuesWeight;
......
......@@ -87,23 +87,77 @@ describe('BurndownChartData', () => {
});
});
describe('when first two days of milestone have negative issue count', () => {
describe('when days in milestone have negative counts', () => {
describe('and the first two days have a negative count', () => {
beforeAll(() => {
milestoneEvents.length = 0;
milestoneEvents.push(
{ created_at: '2017-03-01T00:00:00.000Z', weight: 2, action: 'closed' },
{ created_at: '2017-03-01T00:00:00.000Z', weight: 2, action: 'closed' },
{ created_at: '2017-03-02T00:00:00.000Z', weight: 2, action: 'created' },
{ created_at: '2017-03-03T00:00:00.000Z', weight: 2, action: 'created' },
{ created_at: '2017-03-03T00:00:00.000Z', weight: 2, action: 'created' },
);
});
it('generates an array where the first two days counts are zero', () => {
expect(burndownChartData.generate()).toEqual([
['2017-03-01', 0, 0],
['2017-03-02', 0, 0],
['2017-03-03', 1, 2],
]);
});
});
describe('and the middle day has a negative count', () => {
// This scenario is unlikely to occur as this implies there are more
// closed issues than total issues, but we account for it anyway as a
// potential edge case.
beforeAll(() => {
milestoneEvents.length = 0;
milestoneEvents.push(
{ created_at: '2017-03-01T00:00:00.000Z', weight: 2, action: 'created' },
{ created_at: '2017-03-02T00:00:00.000Z', weight: 2, action: 'closed' },
{ created_at: '2017-03-02T00:00:00.000Z', weight: 2, action: 'closed' },
{ created_at: '2017-03-03T00:00:00.000Z', weight: 2, action: 'created' },
{ created_at: '2017-03-03T00:00:00.000Z', weight: 2, action: 'created' },
);
});
it('generates an array where the middle day count is zero', () => {
expect(burndownChartData.generate()).toEqual([
['2017-03-01', 1, 2],
['2017-03-02', 0, 0],
['2017-03-03', 1, 2],
]);
});
});
describe('and the last day has a negative count', () => {
// This scenario is unlikely to occur as this implies there are more
// closed issues than total issues, but we account for it anyway as a
// potential edge case.
beforeAll(() => {
milestoneEvents.length = 0;
milestoneEvents.push(
{ created_at: '2017-03-01T00:00:00.000Z', weight: 2, action: 'closed' },
{ created_at: '2017-03-02T00:00:00.000Z', weight: 2, action: 'created' },
{ created_at: '2017-03-02T00:00:00.000Z', weight: 2, action: 'closed' },
{ created_at: '2017-03-03T00:00:00.000Z', weight: 2, action: 'created' },
{ created_at: '2017-03-03T00:00:00.000Z', weight: 2, action: 'closed' },
);
});
it('sets first two dates data to 0 and carries forward negative total to the third day', () => {
it('generates an array where all counts are zero', () => {
expect(burndownChartData.generate()).toEqual([
['2017-03-01', 0, 0],
['2017-03-02', 0, 0],
['2017-03-03', 2, 4],
['2017-03-03', 0, 0],
]);
});
});
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment