• R/O
  • HTTP
  • SSH
  • HTTPS

mint-lib: Commit

Math Interactive's library


Commit MetaInfo

Revision25870f4e8659f30c95f3f0d7ce28c5b3d9f2e3f7 (tree)
Time2010-04-19 02:22:00
AuthorTomohiro Nishimura <tomohiro68@gmai...>
CommiterTomohiro Nishimura

Log Message

improved problem that was generated by fractional_arithmetic

Change Summary

Incremental Difference

--- a/lib/mint/generator/fractional_arithmetic.rb
+++ b/lib/mint/generator/fractional_arithmetic.rb
@@ -43,17 +43,14 @@ module Mint::Generator
4343 result = []
4444 result << operand
4545 result << (operator = options[:operators].sample)
46- an, ad = result.first.scan(/(\d+)\/(\d+)/).first.map(&:to_i)
46+ an, ad = result.first.scan(/(-?\d+)\/(-?\d+)/).first.map(&:to_i)
4747 begin
4848 numerator = numerator_part
4949 denominator = denominator_part
50- res_numerator, res_denominator =
51- result_parts(
52- an, ad,
53- numerator, denominator,
54- operator
55- )
56- end while is_lowest_term?(res_numerator, res_denominator)
50+ res_numerator, res_denominator = result_parts(
51+ an, ad, numerator, denominator, operator
52+ )
53+ end while !is_lowest_term?(numerator, denominator) || is_lowest_term?(res_numerator, res_denominator)
5754 result << "(%s/%s)" % [numerator, denominator]
5855 result.join(' ')
5956 end
--- a/spec/generator/fractional_arithmetic_spec.rb
+++ b/spec/generator/fractional_arithmetic_spec.rb
@@ -56,6 +56,29 @@ module Mint::Generator
5656 end
5757 end
5858
59+ context 'better problem' do
60+ before do
61+ generator = Mint::Generator::Factory.create(:fractional_arithmetic)
62+ @solver = Mint::Solver::Maxima::Factory.create(:fractional_arithmetic)
63+ @problem = generator.generate.first
64+ end
65+
66+ 10.times do
67+ context 'for problem' do
68+ before do
69+ @a, @b, @c, @d = @problem.scan(/(-?\d+)\/(-?\d+) .+ \((-?\d+)\/(-?\d+)\)/)[0]
70+ end
71+ it('front') { @a.to_i.gcd(@b.to_i).should == 1 }
72+ it('rear') { @c.to_i.gcd(@d.to_i).should == 1 }
73+ end
74+
75+ it do
76+ a, b = @solver.solve(Mint::Builder.build(@problem)).to_s.scan(/(-?\d+) \/ (-?\d+)/)[0]
77+ a.to_i.gcd(b.to_i).should >= 1
78+ end
79+ end
80+ end
81+
5982 context 'need parenthesis' do
6083 %w[ * div ].each do |operator|
6184 context operator do
Show on old repository browser