Gecoder C0 Coverage Information - RCov

lib/gecoder/bindings.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/gecoder/bindings.rb 98 32
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 # Problems can be formulated and solved either through defining a new
2 # class that mixes in Gecode::Mixin or by using Gecode.solve et al.
3 # Gecode::Mixin describes how to formulate problems.
4 #
5 # ==== Examples 
6 #
7 # The following two examples show how to solve the following equation 
8 # system, using both ways to define and solve a problem.
9 #
10 # Equation system:
11 #   x + y = z
12 #   x = y - 3
13 #   0 <= x,y,z <= 9
14 #
15 # === Mixing in Gecode::Mixin
16 #
17 #   class EquationProblem 
18 #     include Gecode::Mixin
19 #
20 #     def initialize
21 #       variables_is_an int_var_array(3, 0..9)
22 #       x, y, z = variables
23 #
24 #       (x + y).must == z
25 #       x.must == y - 3
26 #
27 #       branch_on variables
28 #     end
29 #   end
30 #   puts EquationProblem.new.solve!.variables.join(' ')
31 #
32 # === Using Gecode.solve
33 #
34 #   solution = Gecode.solve do
35 #     variables_is_an int_var_array(3, 0..9)
36 #     x, y, z = variables
37 #
38 #     (x + y).must == z
39 #     x.must == y - 3
40 #
41 #     branch_on variables
42 #   end
43 #   puts solution.variables.values.join(' ')
44 # 
45 module Gecode
46   # Loads the binding libraries. This is done as a method in order to be easier
47   # to test. 
48   def self.load_bindings_lib #:nodoc:
49     # Workaround to get the precompiled DLLs into the DLL search path on 
50     # Windows.
51     dll_dir = File.dirname(__FILE__) + '/../../vendor/gecode/win32/lib'
52     if RUBY_PLATFORM =~ /mswin/ and File.exists? dll_dir
53       # Switch directory while loading libraries so that the DLLs are in the 
54       # work directory.
55       require 'fileutils'
56       FileUtils.cd dll_dir do
57         require 'gecode'
58       end
59     else
60       require 'gecode'
61     end
62   end  
63   
64   # Load the bindings library.
65   load_bindings_lib  
66   
67   # The Gecode::Raw module is what the interface should use to access methods
68   # in Gecode. The actual bindings are located in ::GecodeRaw.
69   
70   # Describes a layer that delegates to GecodeRaw only after having logged the 
71   # call.
72   module LoggingLayer #:nodoc:
73     require 'logger'
74   
75     def self.method_missing(name, *args)
76       logger.info{ "#{name}(#{args.join(', ')})" }
77       ::GecodeRaw.send(name, *args)
78     end
79     
80     def self.const_missing(name)
81       ::GecodeRaw.const_get(name)
82     end
83     
84     # Gets the logger, or creates one if none exists.
85     def self.logger
86       return @logger unless @logger.nil?
87       file = open('gecoder.log', File::WRONLY | File::APPEND | File::CREAT)
88       @logger = ::Logger.new(file)
89       @logger.datetime_format = "%Y-%m-%d %H:%M:%S"
90       @logger
91     end
92   end
93   
94   # We just make Gecode::Raw an alias of the real module.
95   Raw = ::GecodeRaw
96   # Log all calls via Gecode::Raw.
97   #Raw = LoggingLayer
98 end

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