local s=import("\046\047\082\101\099\116")local t=import("\046\047\086\101\099\116\111\114\050")local c=import("\046\046\047\102\117\110\099\116\105\111\110\115\047\116\121\112\101\111\102")local function b(s)return{s.Min.X,s.Min.Y;s.Max.X;s.Max.Y;s.Width,s.Height}end describe("\116\121\112\101\115\046\082\101\099\116",function()it("\115\104\111\117\108\100 \110\111\116 \104\097\118\101 \097\110 \101\109\112\116\121 \099\111\110\115\116\114\117\099\116\111\114",function()assert.has.errors(function()s.new()end)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 c=s.new(t.new(10,20),t.new(50,100))assert.not_nil(c)assert.are.same({10,20,50,100;40;80},b(c))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 \102\111\117\114 \112\097\114\097\109\101\116\101\114\115",function()local t=s.new(10,20,50,100)assert.not_nil(t)assert.are.same({10;20,50,100;40,80},b(t))end)it("\115\104\111\117\108\100 \098\101 \116\121\112\101 \082\101\099\116",function()assert.equal(c(s.new(0,0,0,0)),"\082\101\099\116")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 \052-\112\097\114\097\109 \099\111\110\115\116\114\117\099\116\111\114",function()assert.has.errors(function()s.new("\116\101\115\116",1,2,3)end)assert.has.errors(function()s.new(1,"\116\101\115\116",2,3)end)assert.has.errors(function()s.new(1,2,"\116\101\115\116",3)end)assert.has.errors(function()s.new(1,2,3,"\116\101\115\116")end)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 \050-\112\097\114\097\109 \099\111\110\115\116\114\117\099\116\111\114",function()assert.has.errors(function()s.new("\116\101\115\116",t.new())end)assert.has.errors(function()s.new(t.new(),"\116\101\115\116")end)end)it("\115\104\111\117\108\100 \101\113\117\097\108 \097\110\111\116\104\101\114 \082\101\099\116 \119\105\116\104 \116\104\101 \115\097\109\101 \118\097\108\117\101\115",function()local c=s.new(10,30,50,200)local b=s.new(t.new(10,30),t.new(50,200))assert.equals(c,c)assert.equals(c,b)assert.equals(b,b)end)it("\115\104\111\117\108\100 \110\111\116 \101\113\117\097\108 \097\110\111\116\104\101\114 \082\101\099\116 \119\105\116\104 \100\105\102\102\101\114\101\110\116 \109\105\110 \097\110\100 \109\097\120 \118\097\108\117\101\115",function()local t=s.new(10,30,50,200)local c=s.new(11,30,50,200)local b=s.new(10,16,50,200)local p=s.new(10,30,40,200)local B=s.new(10,30,50,205)assert.not_equals(t,c)assert.not_equals(t,b)assert.not_equals(t,p)assert.not_equals(t,B)end)end)
local Rect = import("./Rect")
local Vector2 = import("./Vector2")
local typeof = import("../functions/typeof")

local function extractRect(r)
	return { r.Min.X, r.Min.Y, r.Max.X, r.Max.Y, r.Width, r.Height }
end

describe("types.Rect", function()
	it("should not have an empty constructor", function()
		assert.has.errors(function()
			Rect.new()
		end)
	end)

	it("should have a constructor with two parameters", function()
		local r = Rect.new(Vector2.new(10, 20), Vector2.new(50, 100))

		assert.not_nil(r)
		assert.are.same({10, 20, 50, 100, 40, 80}, extractRect(r))
	end)

	it("should have a constructor with four parameters", function()
		local r = Rect.new(10, 20, 50, 100)

		assert.not_nil(r)
		assert.are.same({10, 20, 50, 100, 40, 80}, extractRect(r))
	end)

	it("should be type Rect", function()
		assert.equal(typeof(Rect.new(0, 0, 0, 0)), "Rect")
	end)

	it("should throw when bad params are passed to the 4-param constructor", function()
		assert.has.errors(function()
			Rect.new("test", 1, 2, 3)
		end)

		assert.has.errors(function()
			Rect.new(1, "test", 2, 3)
		end)

		assert.has.errors(function()
			Rect.new(1, 2, "test", 3)
		end)

		assert.has.errors(function()
			Rect.new(1, 2, 3, "test")
		end)
	end)

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

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

	it("should equal another Rect with the same values", function()
		local r1 = Rect.new(10, 30, 50, 200)
		local r2 = Rect.new(Vector2.new(10, 30), Vector2.new(50, 200))

		assert.equals(r1, r1)
		assert.equals(r1, r2)
		assert.equals(r2, r2)
	end)

	it("should not equal another Rect with different min and max values", function()
		local rectA = Rect.new(10, 30, 50, 200)

		local rectB1 = Rect.new(11, 30, 50, 200)
		local rectB2 = Rect.new(10, 16, 50, 200)
		local rectB3 = Rect.new(10, 30, 40, 200)
		local rectB4 = Rect.new(10, 30, 50, 205)

		assert.not_equals(rectA, rectB1)
		assert.not_equals(rectA, rectB2)
		assert.not_equals(rectA, rectB3)
		assert.not_equals(rectA, rectB4)
	end)
end)
