local I=import("\046\047\086\101\099\116\111\114\050")local function u(I)return{I.X,I.Y}end describe("\116\121\112\101\115\046\086\101\099\116\111\114\050",function()it("\115\104\111\117\108\100 \104\097\118\101 \097\110 \101\109\112\116\121 \099\111\110\115\116\114\117\099\116\111\114",function()local z=I.new()assert.not_nil(z)assert.are.same({0;0},u(z))end)it("\115\104\111\117\108\100 \104\097\118\101 \097 \099\111\110\115\116\114\117\099\116\111\114 \119\105\116\104 \116\119\111 \112\097\114\097\109\101\116\101\114\115",function()local z=I.new(1,200)assert.not_nil(z)assert.are.same({1,200},u(z))end)it("\115\104\111\117\108\100 \116\104\114\111\119 \119\104\101\110 \098\097\100 \112\097\114\097\109\115 \097\114\101 \112\097\115\115\101\100 \116\111 \116\104\101 \099\111\110\115\116\114\117\099\116\111\114",function()assert.has.errors(function()I.new(1,"\116\101\115\116")end)assert.has.errors(function()I.new("\116\101\115\116",10)end)end)it("\115\104\111\117\108\100 \097\100\100 \097\110\111\116\104\101\114 \086\101\099\116\111\114\050",function()local z=I.new(1,200)local s=I.new(100,500)local C=z+s assert.not_nil(C)assert.are.same({101,700},u(C))end)it("\115\104\111\117\108\100 \115\117\098\116\114\097\099\116 \097\110\111\116\104\101\114 \086\101\099\116\111\114\050",function()local z=I.new(1,200)local s=I.new(100,500)local C=z-s assert.not_nil(C)assert.are.same({-99,-300},u(C))end)it("\115\104\111\117\108\100 \109\117\108\116\105\112\108\121 \098\121 \097\110\111\116\104\101\114 \086\101\099\116\111\114\050",function()local z=I.new(1,50)local s=I.new(2,.5)local C=z*s assert.not_nil(C)assert.are.same({2;25},u(C))end)it("\115\104\111\117\108\100 \109\117\108\116\105\112\108\121 \098\121 \097 \110\117\109\098\101\114",function()local z=I.new(1,50)local s=z*3 assert.not_nil(s)assert.are.same({3,150},u(s))end)it("\115\104\111\117\108\100 \109\117\108\116\105\112\108\121 \098\121 \097 \110\117\109\098\101\114 \114\101\118\101\114\115\101\100",function()local z=I.new(1,50)local s=3*z assert.not_nil(s)assert.are.same({3;150},u(s))end)it("\115\104\111\117\108\100 \116\104\114\111\119 \097\110 \101\114\114\111\114 \119\104\101\110 \109\117\108\116\105\112\108\105\101\100 \098\121 \097\110 \105\110\099\111\109\112\097\116\105\098\108\101 \116\121\112\101",function()assert.has.errors(function()return I.new(1,2)*nil end)end)it("\115\104\111\117\108\100 \100\105\118\105\100\101 \098\121 \097\110\111\116\104\101\114 \086\101\099\116\111\114\050",function()local z=I.new(1,50)local s=I.new(2,1)local C=z/s assert.not_nil(C)assert.are.same({.5;50},u(C))end)it("\115\104\111\117\108\100 \100\105\118\105\100\101 \098\121 \097 \110\117\109\098\101\114",function()local z=I.new(1,50)local s=z/4 assert.not_nil(s)assert.are.same({.25;12.5},u(s))end)it("\115\104\111\117\108\100 \100\105\118\105\100\101 \098\121 \097 \110\117\109\098\101\114 \114\101\118\101\114\115\101\100",function()local z=I.new(1,50)local s=4/z assert.not_nil(s)assert.are.same({.25,12.5},u(s))end)it("\115\104\111\117\108\100 \116\104\114\111\119 \097\110 \101\114\114\111\114 \119\104\101\110 \100\105\118\105\100\101\100 \098\121 \097\110 \105\110\099\111\109\112\097\116\105\098\108\101 \116\121\112\101",function()assert.has.errors(function()return I.new(1,2)/"\097\098\099"end)end)it("\115\104\111\117\108\100 \101\113\117\097\108 \097\110\111\116\104\101\114 \086\101\099\116\111\114\050 \119\105\116\104 \116\104\101 \115\097\109\101 \120 \097\110\100 \121",function()local u=I.new(1,200)local z=I.new(1,200)assert.equals(u,z)end)it("\115\104\111\117\108\100 \110\111\116 \101\113\117\097\108 \097\110\111\116\104\101\114 \086\101\099\116\111\114\050 \119\105\116\104 \100\105\102\102\101\114\101\110\116 \120 \097\110\100\047\111\114 \121",function()local u=I.new(1,200)local z=I.new(10,200)local s=I.new(1,300)local C=I.new(5,10)assert.not_equals(u,z)assert.not_equals(u,s)assert.not_equals(u,C)end)end)
local Vector2 = import("./Vector2")

local function extractValues(v)
	return { v.X, v.Y }
end


describe("types.Vector2", function()
	it("should have an empty constructor", function()
		local v = Vector2.new()

		assert.not_nil(v)
		assert.are.same({0, 0}, extractValues(v))
	end)

	it("should have a constructor with two parameters", function()
		local v = Vector2.new(1, 200)

		assert.not_nil(v)
		assert.are.same({1, 200}, extractValues(v))
	end)

	it("should throw when bad params are passed to the constructor", function()
		assert.has.errors(function()
			Vector2.new(1, "test")
		end)

		assert.has.errors(function()
			Vector2.new("test", 10)
		end)
	end)

	it("should add another Vector2", function()
		local vectorA = Vector2.new(1, 200)
		local vectorB = Vector2.new(100, 500)
		local v = vectorA + vectorB

		assert.not_nil(v)
		assert.are.same({101, 700}, extractValues(v))
	end)

	it("should subtract another Vector2", function()
		local vectorA = Vector2.new(1, 200)
		local vectorB = Vector2.new(100, 500)
		local v = vectorA - vectorB

		assert.not_nil(v)
		assert.are.same({-99, -300}, extractValues(v))
	end)

	it("should multiply by another Vector2", function()
		local vectorA = Vector2.new(1, 50)
		local vectorB = Vector2.new(2, 0.5)
		local v = vectorA * vectorB

		assert.not_nil(v)
		assert.are.same({2, 25}, extractValues(v))
	end)

	it("should multiply by a number", function()
		local vectorA = Vector2.new(1, 50)
		local v = vectorA * 3

		assert.not_nil(v)
		assert.are.same({3, 150}, extractValues(v))
	end)

	it("should multiply by a number reversed", function()
		local vectorA = Vector2.new(1, 50)
		local v = 3 * vectorA

		assert.not_nil(v)
		assert.are.same({3, 150}, extractValues(v))
	end)

	it("should throw an error when multiplied by an incompatible type", function()
		assert.has.errors(function()
			return Vector2.new(1, 2) * nil
		end)
	end)

	it("should divide by another Vector2", function()
		local vectorA = Vector2.new(1, 50)
		local vectorB = Vector2.new(2, 1)
		local v = vectorA / vectorB

		assert.not_nil(v)
		assert.are.same({0.5, 50}, extractValues(v))
	end)

	it("should divide by a number", function()
		local vectorA = Vector2.new(1, 50)
		local v = vectorA / 4

		assert.not_nil(v)
		assert.are.same({0.25, 12.5}, extractValues(v))
	end)

	it("should divide by a number reversed", function()
		local vectorA = Vector2.new(1, 50)
		local v = 4 / vectorA

		assert.not_nil(v)
		assert.are.same({0.25, 12.5}, extractValues(v))
	end)

	it("should throw an error when divided by an incompatible type", function()
		assert.has.errors(function()
			return Vector2.new(1, 2) / "abc"
		end)
	end)

	it("should equal another Vector2 with the same x and y", function()
		local vectorA = Vector2.new(1, 200)
		local vectorB = Vector2.new(1, 200)

		assert.equals(vectorA, vectorB)
	end)

	it("should not equal another Vector2 with different x and/or y", function()
		local vectorA = Vector2.new(1, 200)

		local vectorB1 = Vector2.new(10, 200)
		local vectorB2 = Vector2.new(1, 300)
		local vectorB3 = Vector2.new(5, 10)

		assert.not_equals(vectorA, vectorB1)
		assert.not_equals(vectorA, vectorB2)
		assert.not_equals(vectorA, vectorB3)
	end)
end)
