Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/gecoder/interface/constraints/bool_enum_constraints.rb | 84 | 27 | 100.00%
|
100.00%
|
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.
1 # A module containing constraints that have enumerations of boolean |
2 # operands as left hand side. |
3 module Gecode::BoolEnum #:nodoc: |
4 # A BoolEnumOperand is a enumeration of BoolOperand on which the |
5 # constraints defined in BoolEnumConstraintReceiver can be placed. |
6 # |
7 # Enumerations of boolean operands can be created either by using |
8 # Gecode::Mixin#bool_var_array and Gecode::Mixin#bool_var_matrix, or |
9 # by wrapping an existing enumeration containing BoolOperand using |
10 # Gecode::Mixin#wrap_enum. The enumerations, no matter how they were |
11 # created, all respond to the properties defined by BoolEnumOperand. |
12 # |
13 # ==== Examples |
14 # |
15 # Produces an array of five boolean operands inside a problem formulation |
16 # using Gecode::Mixin#bool_var_array: |
17 # |
18 # bool_enum = bool_var_array(5) |
19 # |
20 # Uses Gecode::Mixin#wrap_enum inside a problem formulation to create |
21 # a BoolEnumOperand from an existing enumeration containing the |
22 # boolean operands +bool_operand1+ and +bool_operand2+: |
23 # |
24 # bool_enum = wrap_enum([bool_operand1, bool_operand2]) |
25 # |
26 #-- |
27 # Classes that mix in BoolEnumOperand must define #model and |
28 # #to_bool_enum . |
29 module BoolEnumOperand |
30 include Gecode::Operand |
31 |
32 def method_missing(method, *args) #:nodoc: |
33 if Gecode::BoolEnum::Dummy.instance_methods.include? method.to_s |
34 # Delegate to the bool enum. |
35 to_bool_enum.method(method).call(*args) |
36 else |
37 super |
38 end |
39 end |
40 |
41 private |
42 |
43 def construct_receiver(params) |
44 BoolEnumConstraintReceiver.new(@model, params) |
45 end |
46 end |
47 |
48 # BoolEnumConstraintReceiver contains all constraints that can be |
49 # placed on a BoolEnumOperand. |
50 # |
51 # Constraints are placed by calling BoolEnumOperand#must (or any other |
52 # of the variations defined in Operand), which produces a |
53 # BoolEnumConstraintReceiver from which the desired constraint can be |
54 # used. |
55 # |
56 # ==== Examples |
57 # |
58 # Constrains +bool_enum+, with three boolean operands, to take the |
59 # value of the tuples [false, true, false] or [true, false, true] |
60 # using BoolEnumConstraintReceiver#in: |
61 # |
62 # bool_enum.must_be.in [[false, true, false], [true, false, true]] |
63 # |
64 # Constrains +bool_enum+ to channel +int_operand+ using |
65 # BoolEnumConstraintReceiver#channel: |
66 # |
67 # bool_enum.must.channel int_operand |
68 # |
69 class BoolEnumConstraintReceiver < Gecode::ConstraintReceiver |
70 # Raises TypeError unless the left hand side is an bool enum |
71 # operand. |
72 def initialize(model, params) #:nodoc: |
73 super |
74 |
75 unless params[:lhs].respond_to? :to_bool_enum |
76 raise TypeError, 'Must have bool enum operand as left hand side.' |
77 end |
78 end |
79 end |
80 end |
81 |
82 require 'gecoder/interface/constraints/bool_enum/relation' |
83 require 'gecoder/interface/constraints/bool_enum/extensional' |
84 require 'gecoder/interface/constraints/bool_enum/channel' |
Generated on Thu Jan 08 13:27:03 +0100 2015 with rcov 1.0.0