Gecoder C0 Coverage Information - RCov

lib/gecoder/interface/constraints/int/domain.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/gecoder/interface/constraints/int/domain.rb 80 42
100.00%
100.00%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 module Gecode::Int
2   class IntConstraintReceiver
3     # Creates a domain constraint using the specified domain, specified
4     # as an enumeration of integers. The integer operand is constrained
5     # to take a value in the domain.  Domains should be specified as
6     # ranges if possible.
7     # 
8     # ==== Examples 
9     # 
10     #   # +x+ must be in the range 1..10
11     #   x.must_be.in 1..10
12     #   
13     #   # +x+ must not be in the range -5...5
14     #   x.must_not_be.in -5...5
15     #   
16     #   # Specifies the above, but reifies the constraint with the boolean 
17     #   # operand +bool+ and specified +value+ as strength.
18     #   x.must_not_be.in(-5...5, :reify => bool, :strength => :value)
19     #
20     #   # +x+ must be in the enumeration [3,5,7].
21     #   x.must_be.in [3,5,7]
22     #   
23     #   # +x+ must not be in the enumeration [5,6,7,17].
24     #   x.must_not_be.in [5,6,7,17]
25     #   
26     #   # Specifies the above, but reifies the constraint with the boolean 
27     #   # operand +bool+ and specified +value+ as strength.
28     #   x.must_not_be.in([5,6,7,17], :reify => bool, :strength => :value)
29     #
30     def in(domain, options = {})
31       @params.update(Gecode::Util.decode_options(options))
32       @params[:domain] = domain
33       if domain.kind_of? Range
34         @model.add_constraint Domain::RangeDomainConstraint.new(@model, @params)
35       elsif domain.kind_of?(Enumerable) and domain.all?{ |e| e.kind_of? Fixnum }
36         @model.add_constraint Domain::EnumDomainConstraint.new(@model, 
37           @params)
38       else
39         raise TypeError, "Expected integer enumerable, got #{domain.class}."
40       end
41     end
42   end
43   
44   # A module that gathers the classes and modules used in domain constraints.
45   module Domain #:nodoc:
46     # Range domain constraints specify that an integer operand must be 
47     # contained within a specified range of integers.
48     class RangeDomainConstraint < Gecode::ReifiableConstraint #:nodoc:
49       def post
50         var, domain, reif_var = @params.values_at(:lhs, :domain, :reif)
51           
52         (params = []) << var.to_int_var.bind
53         last = domain.last
54         last -= 1 if domain.exclude_end?
55         params << domain.first << last
56         params << reif_var.to_bool_var.bind if reif_var.respond_to? :to_bool_var
57         params.concat propagation_options
58         
59         Gecode::Raw::dom(@model.active_space, *params)
60       end
61       negate_using_reification
62     end
63     
64     # Enum domain constraints specify that an integer operand must be contained
65     # in an enumeration of integers.
66     class EnumDomainConstraint < Gecode::ReifiableConstraint #:nodoc:
67       def post
68         var, domain, reif_var = @params.values_at(:lhs, :domain, :reif)
69         
70         (params = []) << var.to_int_var.bind
71         params << Gecode::Util.constant_set_to_int_set(domain)
72         params << reif_var.to_bool_var.bind if reif_var.respond_to? :to_bool_var
73         params.concat propagation_options
74         
75         Gecode::Raw::dom(@model.active_space, *params)
76       end
77       negate_using_reification
78     end
79   end
80 end

Generated on Thu Jan 08 13:27:03 +0100 2015 with rcov 1.0.0