require_relative 'test_helper' class TestTerm < MiniTest::Unit::TestCase def test_initializer assert_equal 0, Term.new.coefficient assert_equal 0, Term.new.exponent end def test_parsing_with_standard_format assert_equal 4, Term.parse('4x^2').coefficient assert_equal 2, Term.parse('4x^2').exponent end def test_parsing_with_default_exponent_equal_to_one assert_equal 1, Term.parse('1x').coefficient assert_equal 1, Term.parse('1x').exponent end def test_parsing_with_default_coefficient_equal_to_one assert_equal 1.0, Term.parse('x^6').coefficient assert_equal 6, Term.parse('x^6').exponent end def test_parsing_variable_omitted assert_equal 6, Term.parse('6').coefficient assert_equal 0, Term.parse('6').exponent end def test_invalid_string_raises_not_parsable_error ['6x^ -5', '6^20', '2 2', 'xx', '2 ^ x'].each do |not_parsable_string| assert_raises NotParsableError do term = Term.parse not_parsable_string end end end def testing_to_s assert_equal "+ 6 ", Term.parse('6').to_s end end