# [_p_max_]
# p の最大値を4以上の整数で指定します。
# 素数を指定することは出来ません。
+ # [_p_minus_]
+ # 真を指定すると、p の値として負の値も生成します。
# [_q_min_]
# q の最小値を0以上の整数で指定します。
# [_q_max_]
option :r_max, 20
option :p_min, 0
option :p_max, 12
+ option :p_minus, true
option :q_min, 0
option :q_max, 40
end
def generate_p
- min = [options[:p_min], -options[:p_max]].max
- minus = min < 0 ? true : false
- create_integer(min, options[:p_max], minus) {|pa|
+ create_integer(options[:p_min], options[:p_max], options[:p_minus]) {|pa|
!Prime.prime?(pa)
}
end
before do
@options = {
:r_min => r_min, :r_max => r_max,
- :p_min => p_min, :p_max => p_max,
+ :p_min => p_min, :p_max => p_max, :p_minus => false,
:q_min => q_min, :q_max => q_max,
}
subject.__send__(:options=, @options)
it { (@options[:r_min]..@options[:r_max]).should include(subject.__send__(:generate_r)) }
it { (@options[:p_min]..@options[:p_max]).should include(subject.__send__(:generate_p)) }
+ it do
+ subject.__send__(:options=, subject.__send__(:options).merge(:p_minus => true))
+ (-@options[:p_min]..@options[:p_max]).should include(subject.__send__(:generate_p))
+ subject.__send__(:options=, subject.__send__(:options).merge(:p_minus => false))
+ end
it { @squares.should include(subject.__send__(:rational_q)) }
it { @squares.should_not include(subject.__send__(:irrational_q)) }
['225 x^2 - 120 x + 31', ['4/15+root(15)i/15', '4/15-root(15)i/15']],
['x^2 + 7 x + 16', ['-7/2+root(15)i/2', '-7/2-root(15)i/2']],
['49 x^2 - 84 x + 64', ['6/7+2root(7)i/7', '6/7-2root(7)i/7']],
+ ['(x + 2)^2', ['-2']],
].each do |exp, ans|
it exp do