# [factor_min] 整数部の最小値 (ex. 1)
# [factor_max] 整数部の最大値 (ex. 9)
#
- class FractionalExpression < Base
+ class FractionalExpressionArithmetic < Arithmetic
DEFAULT_OPERATORS = %w[+ - * div]
def generate_problem
# TODO: I wanna set option for expression order
defaults = {
- :term_number => 2, :operators => DEFAULT_OPERATORS, :x => ['x'],
+ :x => ['x'],
:numerator_term_number_min => 1, :numerator_term_number_max => 1,
:denominator_term_number_min => 1, :denominator_term_number_max => 1,
:factor_minus => false, :factor_min => 1, :factor_max => 9,
}
- targets = %w[factor denominator_term_number numerator_term_number]
- @options = min_max_order(options(defaults), targets)
- expression
+ do_generate(defaults)
end
- def expression
- result = []
- x = options[:x].sample
- options[:term_number].times do
- result << fraction(x)
- result << options[:operators].sample
- end
- # except last operator
- result[0..-2].join(" ")
+ def operand
+ @x ||= options[:x].sample
+ fraction(@x)
end
def fraction(x)
require File.dirname(__FILE__) + '/../spec_helper.rb'
module Mint
- describe Generator::FractionalExpression do
+ describe Generator::FractionalExpressionArithmetic do
- subject{ Generator::FractionalExpression.new }
+ subject{ Generator::FractionalExpressionArithmetic.new }
describe '2 terms' do
module Mint::Solver::Maxima
- describe FractionalExpression do
+ describe FractionalExpressionArithmetic do
- subject { FractionalExpression.new }
+ subject { FractionalExpressionArithmetic.new }
[
['(x + 2) / (x + 7) * -(x + 5) / (x + 8)', '-(x+2)(x+5)/((x+7)(x+8))'],