Wednesday, June 11, 2008

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.

2 comments:

Mahmoud Khaled said...
This comment has been removed by the author.
Mahmoud Khaled said...

Does rcov support c1 & c2 coverage?