Sha256: a1054f69037b57973c05a6378a89ad722efc10059d19d0ae76b321377efb2bcc

Contents?: true

Size: 975 Bytes

Versions: 5

Compression:

Stored size: 975 Bytes

Contents

require File.dirname(__FILE__) + '/spec_helper.rb'

require "generate_complex_number.rb"

MPFR.set_default_prec(256)

ARITHMETIC_NUM_OF_CALCULATE = 1000

def check_mpc_arithmetic_op(arg1, arg2, error = 10e-10, &block)
  ruby_res = yield(Complex(*(arg1.map{ |a| a.to_f })), Complex(*(arg2.map{ |a| a.to_f })))
  mpc_res = yield(MPC.new(*arg1), MPC.new(*arg2))
  (MPFR.new(ruby_res.real) - mpc_res.real).abs.should < error
  (MPFR.new(ruby_res.imag) - mpc_res.imag).abs.should < error
end

describe MPC, "when calculating" do
  it "should be complex number" do
    args = GenerateComplex.float_arguments(ARITHMETIC_NUM_OF_CALCULATE)
    args.each_index do |i|
      if i > 0
        check_mpc_arithmetic_op(args[i-1], args[i]){ |a, b| a + b }
        check_mpc_arithmetic_op(args[i-1], args[i]){ |a, b| a - b }
        check_mpc_arithmetic_op(args[i-1], args[i]){ |a, b| a * b }
        check_mpc_arithmetic_op(args[i-1], args[i]){ |a, b| a / b }
      end
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby-mpc-0.0.6 spec/mpc/arithmetic_op_spec.rb
ruby-mpc-0.0.5 spec/mpc/arithmetic_op_spec.rb
ruby-mpc-0.0.4 spec/mpc/arithmetic_op_spec.rb
ruby-mpc-0.0.3 spec/mpc/arithmetic_op_spec.rb
ruby-mpc-0.0.2 spec/mpc/arithmetic_op_spec.rb