Skip to content

Commit

Permalink
create error conditions to test for string input in mean/median calcu…
Browse files Browse the repository at this point in the history
…lations
  • Loading branch information
yochannah committed Jan 11, 2024
1 parent b98d6b6 commit 2b7bd8f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
12 changes: 6 additions & 6 deletions test/data_prep/fake_times_to_close.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module.exports = [4081119000, 29822000, 33893000, 15058000, 35052000,
14909000,2295000, 337983000, 576754000, 176219000, 585000, 444506000,
500000, 3038000, 105000, 8512000, 622553000, 257980000,
500000, 3038000, "105000", 8512000, 622553000, 257980000,
170753000, 2128000, 79324000, 356000, 41285000, 301570000,
874669000, 655254000, 69869000, 207105000, 261634000, 3989000,
84161000, 14965000, 19015000, 149495000, 67029000, 62000,
77736000, 81983000, 177978000, 93900000, 253107000, 1459332000,
4957000, 201000, 111000, 61607000, 4081119000, 29822000, 33893000,
15058000, 35052000, 14909000,
2295000, 337983000, 576754000, 176219000, 585000, 444506000,
2295000, 337983000, 576754000, "176219000", 585000, 444506000,
500000, 3038000, 105000, 8512000, 622553000, 257980000,
170753000, 2128000, 79324000, 356000, 41285000, 301570000,
874669000, 655254000, 69869000, 207105000, 261634000, 3989000,
84161000, 14965000, 19015000, 149495000, 67029000, 62000,
77736000, 81983000, 177978000, 93900000, 253107000, 1459332000,
4957000, 201000, 111000, 61607000, 81983000, 177978000, 93900000,
253107000, 1459332000,4957000, 201000, 111000
84161000, 14965000, 19015000, "149495000", 67029000, 62000,
77736000, 81983000, 177978000, "93900000", 253107000, 1459332000,
4957000, 201000, "111000", 61607000, 81983000, 177978000, 93900000,
253107000, "1459332000",4957000, 201000, "111000"
];
22 changes: 22 additions & 0 deletions test/data_prep/fake_times_to_close_string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = [
'4081119000', '29822000', '33893000', '15058000', '35052000',
'14909000', '2295000', '337983000', '576754000', '176219000',
'585000', '444506000', '500000', '3038000', '105000',
'8512000', '622553000', '257980000', '170753000', '2128000',
'79324000', '356000', '41285000', '301570000', '874669000',
'655254000', '69869000', '207105000', '261634000', '3989000',
'84161000', '14965000', '19015000', '149495000', '67029000',
'62000', '77736000', '81983000', '177978000', '93900000',
'253107000', '1459332000', '4957000', '201000', '111000',
'61607000', '4081119000', '29822000', '33893000', '15058000',
'35052000', '14909000', '2295000', '337983000', '576754000',
'176219000', '585000', '444506000', '500000', '3038000',
'105000', '8512000', '622553000', '257980000', '170753000',
'2128000', '79324000', '356000', '41285000', '301570000',
'874669000', '655254000', '69869000', '207105000', '261634000',
'3989000', '84161000', '14965000', '19015000', '149495000',
'67029000', '62000', '77736000', '81983000', '177978000',
'93900000', '253107000', '1459332000', '4957000', '201000',
'111000', '61607000', '81983000', '177978000', '93900000',
'253107000', '1459332000', '4957000', '201000', '111000'
];
4 changes: 2 additions & 2 deletions test/data_prep/generate_fake_pr_or_issue.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

const headers = require("./fake_header"),
closeTimes = require("./fake_times_to_close");
closeTimes = require("./fake_times_to_close_string");

function isClosed(state, i) {
//this function returns boolean false for open if state is open,
Expand Down Expand Up @@ -36,7 +36,7 @@ function fakeIssues(howMany, isPrOrIssue, state) {
response = {
id: new Date().valueOf() +i, //this is hacky, if we ever care about ids
//right now we don't really. But be aware.
created_at: now - closeTimes[i],
created_at: (now - closeTimes[i])+"", // simulates strings. Should be handled gracefully.
closed: isClosed(state,i),
pr_or_issue: prOrIssue,
}
Expand Down
19 changes: 16 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ghGetter.fullRun('fakerepo', 'fakeorg', myMocktokit).then(function(result) { //
let hammerTime = result.timeToMerge.timeToClose;
describe('should return mean time to close correctly', function() {
it('for PRs', function() {
assert.equal(hammerTime.pr.mean.ms, 37195311);
assert.strictEqual(hammerTime.pr.mean.ms, 37195311);
});
it('for issues', function() {
assert.equal(hammerTime.issue.mean.ms, 104784230);
Expand All @@ -63,7 +63,10 @@ ghGetter.fullRun('fakerepo', 'fakeorg', myMocktokit).then(function(result) { //
assert.equal(hammerTime.pr.median.ms, 2295000);
});
it('for issues', function() {
assert.equal(hammerTime.issue.median.ms, 176219000);
assert.strictEqual(hammerTime.issue.median.ms, 176219000);
});
it('should cast string-numbers into real numbers', function(){
return true;
});
});
});
Expand All @@ -76,7 +79,7 @@ ghGetter.fullRun('fakerepo', 'fakeorg', myMocktokit).then(function(result) { //
it('Should return a middle value with an odd number of entries', function() {
var testArr = [5, 2, 1, 3, 4],
median = ghGetter.calculateMedian(testArr);
assert.equal(median, 3);
assert.strictEqual(median, 3);
})
it('Should return a mean of the middle two value with an even number of entries', function() {
var testArr = [6, 1, 5, 4, 2, 3],
Expand All @@ -88,6 +91,16 @@ ghGetter.fullRun('fakerepo', 'fakeorg', myMocktokit).then(function(result) { //
emptyMedian = ghGetter.calculateMedian(emptyArr);
assert.equal(emptyMedian, null);
});
it('Should cast strings into ints', function() {
var stringArr = ["900", "100", "10", "3", "1", "2", "9"],
stringMedian = ghGetter.calculateMedian(stringArr);
assert.strictEqual(stringMedian, 2); // numeric median
//9, whether string or int... only returns if the
//array was sorted alphabetically. Neither of these
// next results is okay
assert.notStrictEqual(stringMedian, 9)
assert.notStrictEqual(stringMedian, "9")
});
});
describe('Calculate mean', function() {
it('Should correctly calculate the mean of an array', function() {
Expand Down

0 comments on commit 2b7bd8f

Please sign in to comment.