Sha256: d6fd8e9e0b1d784153f216b64bef90b1d06bdb7ce2eb12a498512be5e227dd62

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'helper'

include GMath3D

MiniTest::Unit.autorun

class UtilTestCase < MiniTest::Unit::TestCase
  def test_check_arg_type
    integerInstance = 1
    floatInstance = 3.1415
    stringInstance = 'string'

   # no exception raise
    Util3D.check_arg_type(Integer, integerInstance)
    Util3D.check_arg_type(Float, floatInstance)
    Util3D.check_arg_type(String, stringInstance)

    # exception raise
    assert_raises ArgumentError do
      Util3D.check_arg_type(Integer, floatInstance)
    end
    assert_raises ArgumentError do
      Util3D.check_arg_type(Integer, stringInstance)
    end
    assert_raises ArgumentError do
      Util3D.check_arg_type(Float, integerInstance)
    end
    assert_raises ArgumentError do
      Util3D.check_arg_type(Float, stringInstance)
    end
    assert_raises ArgumentError do
      Util3D.check_arg_type(String, integerInstance)
    end
    assert_raises ArgumentError do
      Util3D.check_arg_type(String, floatInstance)
    end
  end

  def test_array_methods
    point_ary = Array.new([Vector3.new(2,4,3),Vector3.new(-2,2.5,8),Vector3.new(9,0,-3)])
    assert_equal( Vector3.new(9, 6.5, 8), point_ary.sum)
    assert_equal( Vector3.new(3, 6.5/3, 8/3.0), point_ary.avg)
  end

  def test_matrix_equation_solving
    mat = Matrix[[1,2,3],[4,5,6],[7,8,-9]]
    vec = Matrix.column_vector([26,62,8])
    inv_mat = mat.inverse
    ans = inv_mat*vec
    assert_equal(3, ans.row_size)
    assert_equal(1, ans.column_size)
    assert_equal(3, ans[0,0])
    assert_equal(4, ans[1,0])
    assert_equal(5, ans[2,0])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gmath3D-0.2.4 test/test_util.rb