test/math_test.rb in polynomials-0.1.2 vs test/math_test.rb in polynomials-0.1.4
- old
+ new
@@ -1,65 +1,65 @@
require 'test_helper'
class TestMath < MiniTest::Unit::TestCase
- def test_nulls_for_constant_functions
+ def test_roots_for_constant_functions
polynomial = Polynomial.parse('5')
- assert_equal Set[],polynomial.nulls
+ assert_equal Set[],polynomial.roots
end
- def test_nulls_for_linear_functions
+ def test_roots_for_linear_functions
polynomial = Polynomial.parse('5x + 2')
- assert_equal Set[-2.0/5.0],polynomial.nulls
+ assert_equal Set[-2.0/5.0],polynomial.roots
end
- def test_nulls_quadratic_functions
+ def test_roots_quadratic_functions
polynomial = Polynomial.parse('3x^2 + 2x - 40')
p = 2.0/3.0
q = -40.0/3.0
root = Math.sqrt((p/2)**2 - q)
fraction = -(p/2)
- assert_equal Set[(fraction - root).round(10), (fraction + root).round(10)],polynomial.nulls
+ assert_equal Set[(fraction - root).round(10), (fraction + root).round(10)],polynomial.roots
polynomial = Polynomial.parse('3x^2 - 40')
- assert_equal Set[Math.sqrt(40.0/3).round(10), -Math.sqrt(40.0/3).round(10)], polynomial.nulls
+ assert_equal Set[Math.sqrt(40.0/3).round(10), -Math.sqrt(40.0/3).round(10)], polynomial.roots
end
- def test_nulls_for_cubic_functions
+ def test_roots_for_cubic_functions
polynomial = Polynomial.parse('1x^3 + 1x^2 + 2x - 1')
- assert_equal(1, polynomial.nulls.size)
- assert_equal Set[0.3926467817], polynomial.nulls
+ assert_equal(1, polynomial.roots.size)
+ assert_equal Set[0.3926467817], polynomial.roots
polynomial = Polynomial.parse('2x^3 - 4x^2 - 22x + 24')
- assert_equal Set[4.0,-3.0,1.0], polynomial.nulls
+ assert_equal Set[4.0,-3.0,1.0], polynomial.roots
end
- def test_nulls_for_cubic_functions_with_complex
+ def test_roots_for_cubic_functions_with_complex
coefficients = Polynomial.parse('3x^3 - 10x^2 + 14x + 27').terms.first(4).map{ |t| t.last.coefficient }
assert_equal Set[-1.0, Complex(2.1666666666666634,2.0749832663314605), Complex(2.1666666666666634,-2.0749832663314605)],Math.roots_of_cubic_function(*coefficients, true)
end
- def test_nulls_for_cubic_functions_one_real_all_equal
+ def test_roots_for_cubic_functions_one_real_all_equal
polynomial = Polynomial.parse('1x^3 + 6x^2 + 12x + 8')
- assert_equal(1, polynomial.nulls.size)
- assert_equal(-2, polynomial.nulls.first)
+ assert_equal(1, polynomial.roots.size)
+ assert_equal(-2, polynomial.roots.first)
end
- def test_nulls_for_quartic_functions
+ def test_roots_for_quartic_functions
polynomial = Polynomial.parse('3x^4 + 6x^3 - 123x^2 - 126x + 1080')
- assert_equal Set[5.0, 3.0, -4.0, -6.0], polynomial.nulls
+ assert_equal Set[5.0, 3.0, -4.0, -6.0], polynomial.roots
polynomial = Polynomial.parse('-20x^4 + 5x^3 + 17x^2 - 29x + 87')
- assert_equal Set[-1.6820039266,1.4875831103], polynomial.nulls
+ assert_equal Set[-1.6820039266,1.4875831103], polynomial.roots
end
- def test_nulls_without_term_with_exponent_of_zero
+ def test_roots_without_term_with_exponent_of_zero
polynomial = Polynomial.parse('3x^3 + 3x^2')
- assert_equal Set[0.0,-1.0], polynomial.nulls
+ assert_equal Set[0.0,-1.0], polynomial.roots
polynomial = Polynomial.parse('1 x^4')
- assert_equal Set[0.0], polynomial.nulls
+ assert_equal Set[0.0], polynomial.roots
end
- def test_nulls_biquadratic_equation
+ def test_roots_biquadratic_equation
polynomial = Polynomial.parse('4x^4 + 2x^2 - 1')
- assert_equal Set[0.5558929703, -0.5558929703], polynomial.nulls
+ assert_equal Set[0.5558929703, -0.5558929703], polynomial.roots
end
end