class Piggly::Tags::AbstractLoopTag
Tracks loops where coverage consists of iterating once, iterating more than once, passing through, and at least one full iteration
Attributes
count[R]
ends[R]
once[R]
pass[R]
twice[R]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Piggly::Tags::AbstractTag::new
# File lib/piggly/tags.rb, line 168 def initialize(*args) clear super end
states()
click to toggle source
# File lib/piggly/tags.rb, line 150 def self.states { # Never terminates normally (so @pass must be false) 0b0000 => "never evaluated", 0b0001 => "iterations always terminate early. loop always iterates more than once", 0b0010 => "iterations always terminate early. loop always iterates only once", 0b0011 => "iterations always terminate early", # Terminates normally (one of @pass, @once, @twice must be true) 0b1001 => "loop always iterates more than once", 0b1010 => "loop always iterates only once", 0b1011 => "loop never passes through", 0b1100 => "loop always passes through", 0b1101 => "loop never iterates only once", 0b1110 => "loop never iterates more than once", 0b1111 => "full coverage" } end
Public Instance Methods
==(other)
click to toggle source
# File lib/piggly/tags.rb, line 215 def ==(other) @id == other.id and @ends == other.ends and @pass == other.pass and @once == other.once and @twice == other.twice end
clear()
click to toggle source
# File lib/piggly/tags.rb, line 207 def clear @pass = false @once = false @twice = false @ends = false @count = 0 end
complete?()
click to toggle source
# File lib/piggly/tags.rb, line 194 def complete? @pass and @once and @twice and @ends end
description()
click to toggle source
# File lib/piggly/tags.rb, line 198 def description self.class.states.fetch(n = state, "unknown tag state: #{n}") end
state()
click to toggle source
Returns state represented as a 4-bit integer
# File lib/piggly/tags.rb, line 203 def state [@ends,@pass,@once,@twice].reverse.inject([0,0]){|(k,n), bit| [k + 1, n | (bit ? 1 : 0) << k] }.last end
style()
click to toggle source
# File lib/piggly/tags.rb, line 177 def style "l#{[@pass, @once, @twice, @ends].map{|b| b ? 1 : 0}}" end
to_f()
click to toggle source
# File lib/piggly/tags.rb, line 181 def to_f # Value space: # (1,2,X) - loop iterated at least twice and terminated normally # (1,X) - loop iterated only once and terminated normally # (0,X) - loop never iterated and terminated normally (pass-thru) # () - loop condition was never executed # # These combinations are ignored, because coverage will probably not reveal bugs # (1,2) - loop iterated at least twice but terminated early # (1) - loop iterated only once but terminated early 100 * (Util::Enumerable.count([@pass, @once, @twice, @ends]){|x| x } / 4.0) end
type()
click to toggle source
# File lib/piggly/tags.rb, line 173 def type :loop end