




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





This quiz is closed book, closed notes. You have 50 minutes to complete it. It contains 28 questions and 8 pages (including this one), totaling 100 points. Before you start, please check your copy to make sure it is complete. Turn in all pages, together, when you are finished. Write your initials on the top of ALL pages. Please write neatly ; we cannot give credit for what we cannot read. Good luck!
Initials: Solutions 1 TRUE/FALSE
1 True/False
(2 points each) Circle the correct answer. T is true, F is false.
Suppose that there are two different implementations C1 and C2 of a given ADT, and the implementations have different representation invariants.
Initials: Solutions 3 COMPARING IMPLEMENTATIONS AND SPECIFICATIONS
3 Comparing implementations and specifications
(a) returns an integer ≥ its argument (b) returns a non-negative integer ≥ its argument (c) returns argument + 1 (d) returns argument^2 (e) returns Integer.MAX VALUE
Consider these implementations:
(i) return arg * 2; (ii) return Math.abs(arg); (iii) return arg + 5; (iv) return arg * arg; (v) return Integer.MAX VALUE;
Place a check mark in each box for which the implementation satisfies the specification. If the imple- mentation does not satisfy the invariant, leave the box blank. Ignore overflow. Specification Impl. (a) (b) (c) (d) (e) (i) (ii) yes yes (iii) yes (iv) yes yes yes (v) yes yes yes
Initials: Solutions 3 COMPARING IMPLEMENTATIONS AND SPECIFICATIONS
A @requires x > 0 @return y such that |eˆy - x| <= 0.
B @return y such that |eˆy - x| <= 0. @throws IllegalArgumentException if x <= 0
C @requires x > 0 @return y such that |eˆy - x| <= 0.
D @return y such that |eˆy - x| <= 0.001 if x > 0 and Double.NEGATIVE_INFINITY if x <= 0
For each of the following pairs of specifications, circle the stronger specification, or circle “neither” if the two specifications are either equivalent or incomparable.
(i) A B neither (ii) A C neither (iii) A D neither (iv) B C neither (v) B D neither (vi) C D neither
Initials: Solutions 4 SHORT ANSWER
(a) In one sentence, what property should be true of each partition? Each partition is uniform with respect to failure; that is, the program should either fail for every input in the partition, or succeed for every input in the partition. Partial credit was given for mentioning heuristics, such as code coverage — but recall that those heuristics are intended to approximate the real answer given here. The theory behind partition testing explains why those heuristics tend to work. Note that this question asked for a property of each partition, not a property of the set of partitions. Also, saying that the partitions should be distinct and exhaustive is merely restating the definition. (b) In one sentence, explain why violating that property can mean that the test suite fails to detect (some) errors. If a failing input exists, but every partition contains at least one succeeding input (which means that some partition contains both types of input), then the arbitrary choice could choose only succeeding tests and miss errors. (c) In one sentence, state how the property can be violated but the suite is still guaranteed to find all errors. If, for every distinct defect in the program, some partition contains only inputs that fail be- cause of that defect, then the test suite will catch all defects. A common incorrect answer is to test all inputs. This is guaranteed to find all errors, but it redefines the partitions to have one input per partition, in which case the uniformity condition on each partition is satisfied. It isn’t right to answer that you could over-partition, so that the partitions you use are sub- partitions of the coarsest (most efficient) partitions that satisfy the uniformity requirement. Another incorrect answer was boundary testing. This is a heuristic that aims to over-partition, but it provides no guarantees.
(a) A special value may be hard to distinguish from a real result. (b) Special values are error-prone: the programmer may forget to check them. (c) An exception can carry arbitrary data that may be useful in describing the problem. (d) It can simplify the program logic.
Many people said an exception implements the “fail fast” paradigm. But special values can do this just as easily: the library returns a special value as soon as there is a problem, and the client checks for it. Likewise, exceptions do not prevent any more (or fewer) problems than special values, if each is used correctly. By contrast, exceptions give you “guaranteed fail”, which is different but also valuable.
Initials: Solutions 4 SHORT ANSWER
This enables testing whether the class uses static variables, suffers representation exposure, or has other undesired dependences/interference between distinct Graph objects. An inadequate answer is that it tests whether the same node is in multiple graphs. Nodes associated with the same name might be in multiple graphs, but that is a different matter. The test file format does not permit comparison of Graph objects, so that is not the reason either.
(a) Good: It leverages our intuitions about what paths are the right ones between any two points. An incorrect answer is that it is like the real-world data that the system will eventually use. The purpose of testing is to create test cases that reveal errors, not to simulate use. (b) Bad: Reality may not contain (or it may be difficult to find) the corner cases that you wish to test, such as multiple paths of similar length, longer paths with a smaller number of segments, each type of turn, each type of road, multiple ZIP codes, etc. Another acceptable answer is that creating a realistic graph requires a lot of work to have it correspond closely enough to reality. If the graph is only somewhat like reality, then testers’ intuitions may mislead them. An incorrect answer is that a larger and more complex graph is needed. Testing on complex data just makes it harder for you to understand the errors! It is better for you to carefully craft specific test cases, rather than to throw heaps of data at your program.