Microsoft Interview Question for SDE-2s


Country: United States
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
3
of 3 vote

From function name and params I see that it is a function that checks whether provided date falls within a provided time range.

General 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.

- Vilius November 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Is there any sence in testing it with Max and Min DateTime?

- Saito December 13, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Since there are 6 independent if conditions in the code, test for false positives and false negatives for each condition and see whether the result of the function is correct or incorrect.

- Anonymous December 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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;

- Andrei Nicolae November 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Date.getTime() gives number of milliseconds
just check dateToTest milliseconds is between startDate and endDate's milliseconds

- Satish January 21, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- noone September 12, 2018 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More