Microsoft Interview Question
SDE-2sCountry: United States
Interview Type: Phone Interview
Try to give, as input, corner cases:
- give an incorrect dateTime for the dateToTest - in your case here, you do not use exceptions! Therefore, try to include a try-catch block inside the function's body (and include relevant messages sent to system err);
- try to see, maybe, what happens if you choose a date in the future;
- better formatting (just an advice): try to use switch with cases;
Test for code coverage and edge cases. Look for counterexamples at edges/transitions.
For example, consider input:
startDate: 2018/4/25
endDate: 2018/5/ 5
dateToTest: 2018/5/ 4
This input would create a false negative because of
if(startDate.Day > dateToTest.Day)
return false;
Thus, the code does not account for wraparound and it faulty
From function name and params I see that it is a function that checks whether provided date falls within a provided time range.
- Vilius November 13, 2014General tests would test the returned result when:
1 provided date falls within a provided range:
1. 3 cases should suffice:
1. date is same as lower bound
2. date is same as higher bound,
3. date isn't equal to neither of bounds, but falls within a range.
2. date is outside the provided range.
1. Provided date is before range stare.
2. Provided date is after range end
Now one thing to mention... I wouldn't trust the code I am testing (wuoldn't imply it is correct) so I would need to check what is the expected behaviour when, date is equal to one of the ranges.
Then we would need to test what happends when wrong data (params) are passed:
1. When each param passed is null.
2. When start range is after end range.
3. Both date range boundaries are equal.
My general approach would be to write tests as if I didn't know implementation (blackbox) and the n continue from there looking into the code.