Sha256: 5f48a2f159334d0f0a2bb0bfb5d5845883632ce6cec3f4992a475a2d8e2c7ead
Contents?: true
Size: 1.26 KB
Versions: 6
Compression:
Stored size: 1.26 KB
Contents
require "#{File.dirname(File.expand_path(__FILE__))}/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_dup term = Term.new(2,10) assert_equal term.coefficient, term.dup.coefficient assert_equal term.exponent, term.dup.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
Version data entries
6 entries across 6 versions & 1 rubygems