Sample solution For this one any decent pseudo-code or description is accepted, with the key points to capture outlined below. We'll need a driver to call completionProb (written in the same language and compiled together, assuming it's a compiled language):
|
Sample solution test cases | ||||
remaining | min | max | expected | rationale |
-1 | 1 | 2 | ? | erroneous val for remaining |
1 | -1 | 2 | ? | erroneous val for remaining |
1 | 2 | -1 | ? | erroneous val for remaining |
2 | 3 | 1 | ? | min > max, error? |
1 | 1 | 1 | ? | all equal (edge case) |
1 | 2 | 3 | ? | remaining < min |
2 | 1 | 3 | ? | remaining between min and max |
3 | 1 | 2 | ? | remaining > max |
? is shown for expected probabilities since I told you not to bother calculating those | ||||
a variety of other edge cases are likely, e.g. where two of three values are equal and where expected probability would be 0 (or very close to it) or 1 (or very close to it) | ||||
Note that testing for numbers that weren't reals (e.g. testing for text inputs) wouldn't make sense in a compiled/type-checked language since those couldn't possibly be passed as parameters to the function. |
Sample solution Now what we're actually testing is the driver from (1a), so we'll need a driver to drive it: call this one DD for short. We need to control the behaviour of completionProb to test how the driver works on good/bad implementations of completionProb, so we'll use a stub for completionProb that allows us to control what completionProb returns in any given test case, and we'll need to compile our (1a) driver with our completionProb stub. The stub might simply wait for the tester to specify (e.g. via stdin) what probability value it should return. We want DD to run the driver on a test case and compare the driver's pass/fail result to what we expect in this situation: if the driver is correct then should it be saying pass or fail in this instance? DD can be a script with the following behaviour:
|
Sample solution For our (1a) the only real change is in the order we enter the data values: before we entered the remaining, min, and max times and the expected result before calling completion prob, now we'd need to enter min, max, and expected before it calls completionProb and then enter the remaining value when the completionProb stub expects it. (Plus of course the driver would only be passing the two parameters instead of three.) For our (1b), since the remaining time is now taken as a text user input instead of being passed as a parameter (which would have been type-checked at compile time in the 1a version) we now have to worry about cases where the user enters non-numeric values instead of an actual real number. Presumably the specs for the function would need to be updated to indicate what completionProd is supposed to do if given non-numeric input for remaining time, and we would need to add test cases that checked completionProd correctly followed those new specs. |