require 'test/unit'
require 'solution'

class TestPoly < Test::Unit::TestCase
	def test_add
		assert_equal Poly.new([1, 2]), Poly.new([1, 1])  + Poly.new([0, 1])
		assert_equal Poly.new([12, 1]), Poly.new([1, 1])  + 11
	end
	def test_sub
		assert_equal Poly.new([1]), Poly.new([1, 1])  - Poly.new([0, 1])
		assert_equal Poly.new([-10, 1]), Poly.new([1, 1])  - 11
	end

	def test_brackets
		poly = Poly.new [1,2]
		assert_equal 1, poly[0]
		assert_equal 2, poly[1]
		assert_equal 0, poly[2]
	end
	def test_multiplication
		assert_equal Poly.new([6, 15, 8, 4]), Poly.new([6, 3, 2]) * Poly.new([1, 2])
		assert_equal Poly.new([12, 6, 4]), Poly.new([6, 3, 2]) * 2
	end
	def test_power
		assert_equal Poly.new([1, 3, 3, 1]), Poly.new([1, 1]) ** 3
		assert_equal Poly.new([1, 4, 6, 4, 1]), Poly.new([1, 1]) ** 4
	end
	def test_derivative
		assert_equal Poly.new([]), ~Poly.new([11])
		assert_equal Poly.new([3, 4]), ~Poly.new([6, 3, 2])
	end
	def test_to_s
		assert_equal '5x^3+2x+1', Poly.new([1, 2, 0, 5]).to_s
		assert_equal '-5x^3-2x-1', Poly.new([-1, -2, 0, -5]).to_s
	end
	def test_include
		assert Poly.new([1, 0, 5]).include? [0, 1]
	end
end

