#  JLMatrix - Matrix support for JRuby
#  Copyright (C) 2008 Approximatrix, LLC
#  http://www.approximatrix.com
#  
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#  NOTE: This software is licensed under the GPL and does not allow
#        linking to closed-source software.
#

require 'test/unit'
require 'jlmatrix'
  
class TC_Math < Test::Unit::TestCase

  # def setup
  # end

  # def teardown
  # end
 
  def test_sqrt
  	
  	assert_equal 2, sqrt(4)
  	
  	v = Vector.elements([4,9,16])
  
  	vroot = sqrt(v)
  	assert_kind_of Vector, vroot
  	assert_equal 2, vroot[0]
  	assert_equal 3, vroot[1]
  	assert_equal 4, vroot[2]
  
  	# Special case - vector of one must work
  	v = Vector.elements([4])
    vroot = sqrt(v)
    assert_kind_of Vector, vroot
    assert_equal 2, vroot[0]
  	
  	m = Matrix.rows([[0,4],[9,16]])
  	
  	mroot = sqrt(m)
  	assert_kind_of Matrix, mroot
  	assert_equal 0, mroot[0,0]
  	assert_equal 2, mroot[0,1]
  	assert_equal 3, mroot[1,0]
  	assert_equal 4, mroot[1,1]
  
  end

end
