Idea: Write constraints in separate modules and then include the modules in the respective place. =begin it 'should handle relation with integer variables' do fail end it 'should handle propagation strength domain' do fail end it 'should handle propagation strength val' do fail end it 'should handle propagation strength range' do fail end it 'should raise error for unknown propagation strengths' do fail end it 'should handle reification' do fail end =end =begin it 'should handle variables as right hand side' do (@x + @y).must == @z sol = @model.solution x = sol.x.val y = sol.y.val z = sol.z.val (x + y).should equal(z) end it 'should handle multiplication with a constant' do Gecode::Raw.should_receive(:linear).once.with(@model.active_space, an_instance_of(Gecode::Raw::IntVarArray), Gecode::Raw::IRT_EQ, 1, Gecode::Raw::ICL_DEF).and_return{ |s, arr, irt, res, strength| arr } ((10*@x + @y).must == 1).should contain_vars_with_domains(@x_dom, @y_dom) end it 'should handle addition with a constant' do end it 'should handle relation...' do end =end module CustomVarMatchers class ContainVarsWithDomains def initialize(*expected_domains) @expected_domains = expected_domains end def matches?(target) @target = target return false unless @target.kind_of? Gecode::Raw::IntVarArray return false unless @target.size == @expected_domains.size @target.size do |i| var = @target.at(i) detected = @expected_domains.detect do |domain| variable_has_domain?(var, domain) end unless detected.nil? @expected_domains.delete(@expected_domains.index(detected)) else return false end end return true end def failure_message "expected #{@target.inspect} to contain variables with domains " + @expected_vars.inspect end def negative_failure_message "expected #{@target.inspect} to not contain variables with domains " + @expected_vars.inspect end private def variable_has_domain?(target, expected) return false unless target.size == expected.size expected.each do |element| return false unless target.in(element) end return true end end # Tests whether an integer variables array contains variables with the # expected domains (in any order given). def contain_domains(expected) ContainVarsWithDomains.new(expected) end end Spec::Runner.configure do |config| config.include(CustomVarMatchers) end Left: * Sorted * Arithmetic xs.occurrences_of(y).must == z xs.occurrences_of(3).must >= 5 xs.count(y).must == z xs.number_of(y).must == z ys.sorted.must == xs ys.sorted_with(zs).must == xs ys.sort.must == xs ys.must_be.xs.sorted ys.must_be.sort(xs) ys.sort.must_be.xs