Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Ternary Operators
Pjotrtje
#1 Posted : Thursday, March 26, 2015 7:37:10 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/21/2015(UTC)
Posts: 7
Location: Netherlands

Was thanked: 1 time(s) in 1 post(s)
Hey Remco,

We are still evaluating NCrunch. And I run into the same problem as listed below:

http://forum.ncrunch.net...ndition-is-covered.aspx

We also have in our code a lot of:

var x = hasXxx
? x1
: x2;

And the codecoverage says "Green" the first of the 3 rows. And no information about the 2 below it. Even if hasXxx is always true.

The best would of cource be 3 coloured dots. If that is not possible then a 'non green dot' would be nice. Better incomplete information than a 'false possitive' coverage indicator. Maybe that is possible?

You end that old topic with "This isn't to say it will never happen, and the value of such a feature is definitely clear - I'm just trying to be realistic about the odds :)".
You also say: "To be able to perform this with the added complexity of needing to break each line down into separate statements without impacting performance is a significant technical challenge with a very high price tag attached to it."

For me personally 50% slower and good indications would be an improvement. Cores are getting cheap!

Love to hear your thoughts!
Greets,
Pieter
Remco
#2 Posted : Thursday, March 26, 2015 10:46:42 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Hi Pieter,

Thanks for posting!

When using the ternary expression you've provided, it looks as though the compiler treats this as a single physical statement.

You'll notice this if you try to set a breakpoint on the second or third line of the statement. It'll just land at the top.

This creates a brick wall for NCrunch, as NCrunch relies on the debug data emitted by the compiler, there is no way it can differentiate between the two different values and report on them separately. As far as NCrunch is concerned, it might as well be a single method call. This means that providing what you're asking for would be impossible without making changes to the compiler itself.

I realise this is a different answer to what I've provided in the forum post you've quoted me on. When I wrote that post, I was under the assumption that placing the ternary operator across lines would allow NCrunch to break it up line-by-line. It seems this isn't the case, which means that even the moonshot solution I was contemplating back then would not be able to solve this problem.

Sorry, I realise this isn't the answer you wanted. I'm just being realistic.


Cheers,

Remco
Pjotrtje
#3 Posted : Friday, March 27, 2015 2:19:43 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/21/2015(UTC)
Posts: 7
Location: Netherlands

Was thanked: 1 time(s) in 1 post(s)
Hey,
Too bad. Visual Studio code coverage tool does seem to be accurate though.

Nevertheless, forme the big problem is not that NCrunch cannot determine whether a Ternary Operators is completely tested. But that it shows that it IS completely tested.

I have no clue how your algorith is. But it is not possible that when the line contains a Ternary Operators it shows "inconclusive"? The real question is, can you determine 'a line' contains a Ternary Operator?

"Sorry, I realise this isn't the answer you wanted. I'm just being realistic."
No worries, I appreciate the honesty and clarity!

Greets,
Pieter
Remco
#4 Posted : Friday, March 27, 2015 10:35:16 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Pjotrtje;7129 wrote:
Hey,
Too bad. Visual Studio code coverage tool does seem to be accurate though.


Interesting .. I do wonder how they've done that.

Pjotrtje;7129 wrote:

I have no clue how your algorith is. But it is not possible that when the line contains a Ternary Operators it shows "inconclusive"? The real question is, can you determine 'a line' contains a Ternary Operator?


Not easily. A ternary operator itself is a language-level construction that doesn't have a direct representation inside MSIL. C# basically just translates it into branches/conditions. NCrunch itself is language independent - it doesn't parse C# in any form, instead it relies on interpretation from MSIL. So it might be possible to infer the existence of a ternary operator by looking at the IL and taking a guess ... but then to show any kind of visual data about it would likely still require some form of parsing.

Pjotrtje
#5 Posted : Wednesday, April 1, 2015 7:33:19 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/21/2015(UTC)
Posts: 7
Location: Netherlands

Was thanked: 1 time(s) in 1 post(s)
Ok.

Than I just have te remember that a green dot in front of:

var x1 = x2 == x3
? x4
: x5;

or

var x1 = x2
?? x3
?? x4;


Does not mean it is completely covered but only the line is 'touched' during a test. Not perfect, but do-able :).
1 user thanked Pjotrtje for this useful post.
Remco on 4/1/2015(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.047 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download