local k=import("\046\047\085\068\105\109")local K=import("\046\047\085\068\105\109\050")local function V(k)return{k.X.Scale,k.X.Offset,k.Y.Scale,k.Y.Offset}end describe("\116\121\112\101\115\046\085\068\105\109\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 k=K.new()assert.not_nil(k)assert.are.same({0;0;0;0},V(k))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 O=K.new(k.new(10,20),k.new(50,100))assert.not_nil(O)assert.are.same({10;20;50,100},V(O))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 k=K.new(10,20,50,100)assert.not_nil(k)assert.are.same({10,20,50;100},V(k))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()K.new("\116\101\115\116",1,2,3)end)assert.has.errors(function()K.new(1,"\116\101\115\116",2,3)end)assert.has.errors(function()K.new(1,2,"\116\101\115\116",3)end)assert.has.errors(function()K.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()local V=K.new("\116\101\115\116",k.new())end)assert.has.errors(function()local V=K.new(k.new(),"\116\101\115\116")end)end)it("\115\104\111\117\108\100 \104\097\118\101 \112\114\111\112\101\114\116\121 \088 \101\113\117\097\108 \112\114\111\112\101\114\116\121 \087\105\100\116\104",function()local k=K.new(10,20,50,100)assert.not_nil(k)assert.equals(k.X,k.Width)end)it("\115\104\111\117\108\100 \104\097\118\101 \112\114\111\112\101\114\116\121 \089 \101\113\117\097\108 \112\114\111\112\101\114\116\121 \072\101\105\103\104\116",function()local k=K.new(10,20,50,100)assert.not_nil(k)assert.equals(k.Y,k.Height)end)it("\115\104\111\117\108\100 \097\100\100 \097\110\111\116\104\101\114 \085\068\105\109\050",function()local O=K.new(10,30,50,200)local x=K.new(k.new(20,40),k.new(100,500))local T=O+x assert.not_nil(T)assert.are.same({30,70,150;700},V(T))end)it("\115\104\111\117\108\100 \101\113\117\097\108 \097\110\111\116\104\101\114 \085\068\105\109\050 \119\105\116\104 \116\104\101 \115\097\109\101 \118\097\108\117\101\115",function()local k=K.new(10,30,50,200)local V=K.new(10,30,50,200)assert.equals(k,V)end)it("\115\104\111\117\108\100 \110\111\116 \101\113\117\097\108 \097\110\111\116\104\101\114 \085\068\105\109 \119\105\116\104 \100\105\102\102\101\114\101\110\116 \115\099\097\108\101 \097\110\100 \111\102\102\115\101\116",function()local k=K.new(10,30,50,200)local V=K.new(11,30,50,200)local O=K.new(10,15,50,200)local x=K.new(10,30,60,200)local T=K.new(10,30,50,100)local M=K.new(1,2,3,4)assert.not_equals(k,V)assert.not_equals(k,O)assert.not_equals(k,x)assert.not_equals(k,T)assert.not_equals(k,M)end)it("\115\104\111\117\108\100 \108\101\114\112",function()local k=K.new(0,100,200,300)local O=K.new(100,200,300,400)assert.are.same({0,100;200;300},V(k:Lerp(O,0)))assert.are.same({50,150,250;350},V(k:Lerp(O,.5)))assert.are.same({100,200,300,400},V(k:Lerp(O,1)))end)end)
local UDim = import("./UDim")
local UDim2 = import("./UDim2")

local function extractUDim2(udim)
	return { udim.X.Scale, udim.X.Offset, udim.Y.Scale, udim.Y.Offset }
end

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

		assert.not_nil(udim)
		assert.are.same({0, 0, 0, 0}, extractUDim2(udim))
	end)

	it("should have a constructor with two parameters", function()
		local udim = UDim2.new(UDim.new(10, 20), UDim.new(50, 100))

		assert.not_nil(udim)
		assert.are.same({10, 20, 50, 100}, extractUDim2(udim))
	end)

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

		assert.not_nil(udim)
		assert.are.same({10, 20, 50, 100}, extractUDim2(udim))
	end)

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

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

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

		assert.has.errors(function()
			UDim2.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()
			-- luacheck: push ignore udim
			local udim = UDim2.new("test", UDim.new())
			-- luacheck: pop
		end)

		assert.has.errors(function()
			-- luacheck: push ignore udim
			local udim = UDim2.new(UDim.new(), "test")
			-- luacheck: pop
		end)
	end)

	it("should have property X equal property Width", function()
		local udim = UDim2.new(10, 20, 50, 100)

		assert.not_nil(udim)
		assert.equals(udim.X, udim.Width)
	end)


	it("should have property Y equal property Height", function()
		local udim = UDim2.new(10, 20, 50, 100)

		assert.not_nil(udim)
		assert.equals(udim.Y, udim.Height)
	end)

	it("should add another UDim2", function()
		local udimA = UDim2.new(10, 30, 50, 200)
		local udimB = UDim2.new(UDim.new(20, 40), UDim.new(100, 500))
		local udim = udimA + udimB

		assert.not_nil(udim)
		assert.are.same({30, 70, 150, 700}, extractUDim2(udim))
	end)

	it("should equal another UDim2 with the same values", function()
		local udimA = UDim2.new(10, 30, 50, 200)
		local udimB = UDim2.new(10, 30, 50, 200)

		assert.equals(udimA, udimB)
	end)

	it("should not equal another UDim with different scale and offset", function()
		local udimA = UDim2.new(10, 30, 50, 200)

		local udimB1 = UDim2.new(11, 30, 50, 200)
		local udimB2 = UDim2.new(10, 15, 50, 200)
		local udimB3 = UDim2.new(10, 30, 60, 200)
		local udimB4 = UDim2.new(10, 30, 50, 100)
		local udimB5 = UDim2.new(1, 2, 3, 4)

		assert.not_equals(udimA, udimB1)
		assert.not_equals(udimA, udimB2)
		assert.not_equals(udimA, udimB3)
		assert.not_equals(udimA, udimB4)
		assert.not_equals(udimA, udimB5)
	end)

	it("should lerp", function()
		local udimA = UDim2.new(0, 100, 200, 300)
		local udimB = UDim2.new(100, 200, 300, 400)

		assert.are.same({0, 100, 200, 300}, extractUDim2(udimA:Lerp(udimB, 0)))
		assert.are.same({50, 150, 250, 350}, extractUDim2(udimA:Lerp(udimB, 0.5)))
		assert.are.same({100, 200, 300, 400}, extractUDim2(udimA:Lerp(udimB, 1)))
	end)
end)
