Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assertion question from Dan's exam

 
shweta mathur
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.danchisholm.net/dec04/topic/section2/assertions2.html
Question 9

Which statements are true?
a. With assertions enabled it prints an AssertionError message.
b. With assertions enabled it prints nothing.
c. With assertions disabled it prints an AssertionError message.
d. With assertions disabled it prints nothing.
e. An assertion should not be placed at any location that the programmer believes will never be reached under normal operating conditions.
f. The assert statement is being used to check a control-flow invariant to verify that the control flow never reaches a point in the program.
g. A compiler error is generated.
h. None of the above.

According to the answers option "f" is correct
But in this code assert statement is placed at a place where it will always be called no matter what is the value of b1,b2,b3, since there are no return statements in the if-the-else statements.
I feel "f" may not be the correct option.
Dan can you pls confirm !
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shweta,
You are correct. The assert statement should be in an "else" block as shown below.

The correct answers are still A,D and F.
I will upload the correction.
Thank you!
 
shweta mathur
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dan !
Your questions are really interesting to work on !
Shweta
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic