Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Confusion in Assertion

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assertion can have either one or two expressions depending on whether you're using the "simple" or "the really simple".
The First Expression result in boolean value. And the second expression can be anything that result in a value..

i am confused in this expression 1 and expression 2 concept... also written in the book that if you see in the exam the statement referring to expression 2, That only means the statement would not be correct.... so can i treat that question as compilation fails code..?
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
".....The First Expression result in boolean value....."

but in the code assert(x=1):x; , the first expression (x=1) is not evaluated to boolean. So its a compile error.
Just note that the code inside () should be evaluated to a boolean value, then only it compiles.
 
Yogesh Bali
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much For the reply sir.. you are absolutely correct.. but the doubt in my mind is what if i was told in the question that assume it to be the expression 2 type.... and we know for expression 2 anything results to a value is accepted.. and here x=1 having a value 1.. so cant it be correct for the expression 2 type...

also help me is if i find in question that expression 2 statement.. should i think the statement is incorrect and so mark compilation fails for it..? as in the book they were saying to think it as a mistake in the statement..
 
Sridhar Gudipalli
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yogesh Bali wrote: but the doubt in my mind is what if i was told in the question that assume it to be the expression 2 type.... and we know for expression 2 anything results to a value is accepted.. and here x=1 having a value 1.. so cant it be correct for the expression 2 type...



Please refer the Exam Watch point in K&B book it says:
An assert expression must result in a boolean value, true or false?

Assume that the word 'expression' refers to expression1 of an assert, so the question statement is correct. If the statement were referring to expression2,
however, the statement would not be correct, since expression2 can have a result of any value, not just a boolean.

See the differences:
An assert expression (assume expression1) must result in a boolean value, true or false? - true
An assert expression (assume expression2) must result in a boolean value, true or false? - false, because it can be any value.
An assert expression (assume expression2) can result in a boolean value, true or false? - true



 
Yogesh Bali
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got your point boss..Thank you so much for the help.. i am happy and my misunderstanding about that exam watch point is now cleared.. and i am agreed with your every single statement sir.. as they were absolutely correct..
assume it to be the expression 2 type.. is correct then..

assert expression2 can return any value.. and used generally with only simple case and not with really simple case..
And assert expression always returns boolean is correct as here we were assuming it to be expression 1..
but if its mention that consider of expression2 then its answer is false a expression 2 can return any value.. Thank you Thank you Thank you sir...
my that exam watch point is now cleared and i had realized how wrong i was going.. will be careful to not to repeat the mistake in further topics.. thank you boss.. : )

 
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
The trailboss has a kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic