C0, C1 and C2 Coverage

Here are a few reminders I got from rcov‘s page:

  • C0: coverage of lines of code
  • C1: coverage of branches
  • C2: coverage of paths

So, if you’d have a Drinker class like so:

class Drinker
def drink beer, wine
result = 0

if beer then result = 1
else result = -1
end

if wine then result = 2
else result = -2
end

result
end
end

And a test suite like so:

require 'test/unit'
require File.dirname(__FILE__) + "/drinker"

class DrinkerTest < Test::Unit::TestCase
def setup
@dude = Drinker.new
end

def test_drink_both_beer_and_wine
assert_equal(2, @dude.drink(true, true))
end

def test_drink_nothing
assert_equal(-2, @dude.drink(false, false))
end
end

then you would have:

  • 100% C0 coverage (all lines have been ‘executed’)
  • 100% C1 coverage (all branches of conditions have been traversed)
  • 50% C2 coverage (2 paths out of 4 taken)

More details here.

Advertisements

2 comments

  1. This comment has been removed by the author.

  2. Does rcov support c1 & c2 coverage?

Got a comment?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: