assertionQuestions

assertionQuestions - 2009 November 23 Assertions...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
2009 November 23 Assertions & Verification Example Test Questions 1. A Give a general template for refining an operation into a sequence and state what questions a designer must answer to verify the sequence is a correct refinement. B Give a general template for refining an operation into a choice and state what questions a designer must answer to verify the choice is a correct refinement. C Give a general template for redefining an operation into a loop and state what questions a designer must answer to verify the loop is a correct refinement. 2. Explain what is meant by strong and weak assertions. 3. There are 5 types of assertions that can be used in program design. Describe each type of assertion and how that assertion type is used in the design of programs. 4. Give the best precondition, postcondition and loop invariant for the following algorithm to do a binary search on an array A[1 . . N]. Your work should use as much mathematical notation as possible to capture the relevant information. low 1 high N Result 0 while Result = 0 and low high do mid (low + high)/2 if A[mid] = k then Result mid elseif A[mid] < k then low mid + 1 else high mid - 1 fi end while 5. What would be the best precondition, postcondition and loop invariant for the following algorithm to find a span of dash characters in an array. charPointer := 1 loop exit when textLine(charPointer) not equal dashChar charPointer := charPointer + 1 end loop 6. What would be the best precondition, postcondition and loop invariant for the following correct algorithm to find the maximum integer and its index in the array A[1. .N]. max := 0 ; maxIndex := 0 j := 1 while j <= N do if max < A[j] then max = A[j] ; maxIndex := j end if
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2009 November 23 Assertion & Verification Example Test Questions Page 2 of 8 j := j + 1 end while 7. Prove the following algorithm to sum the odd integers in the range 1 to N inclusive is correct. Clearly show the correspondence with the questions a designer must ask when verifying a loop is the correct refinement of an operation. Precondition: N > 0 Postcondition: sum = { j :1. . N | odd ( j ) j } " Loop invariant: sum = { j :1. . p | odd ( j ) j } " sum := 0 p := 0 while p < N p := p + 1 if odd(p) then sum := sum + p fi end while 8. What is a loop invariant? When is it used? How is it used? Why is it used? Where is it used? 9. Given a loop, pre & post conditions and loop invariant prove the loop is correct or is incorrect. 10. Given pre & post conditions and a loop invariant create the corresponding program text in Eiffel. 11. What would be the best loop invariant and variant for the following algorithm. require x = a * a from invariant ??? variant
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/14/2012 for the course CSE 3214 taught by Professor Ross during the Winter '12 term at York University.

Page1 / 8

assertionQuestions - 2009 November 23 Assertions...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online