Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Assertions

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An assert statement can be used to check a control-flow invariant to verify which of the following?

a. A particular assumption is true when the flow of control enters a method.
b. The flow of control does not reach a particular point in the program.
c. The normal flow of control has reached a particular point in the program.
d. The normal flow of control has reached the end of a method.
e. The default case of a switch statement is not reached.
f. The else block of an if/else statement is not reached.

Question from Dan's tests..the answer says b,e,f are true..I feel that a is also true.. So can someone explain me why option a is not considered.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a school of thought which says that preconditions should not be checked by assertions. A precondition could be that the state of the object is valid when a method is called, or that the values of the arguments passed to the method are valid . An example is checking that the value passed to a square root method is non-negative. Because assertions can be turned off at runtime the check for a non-negative argument will not occur and the program may crash or silently produce nonsense when supplied with an invalid value. The correct technique, according to Sun, is to throw an exception when an invalid argument value is passed or the state of the object on which the method is called is invalid.

For the SCJP remember this: do not check method arguments with assertions.
 
Swati Udas
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok! That's clear now..
Thank You.
 
See where your hand is? Not there. It's next to this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic