local f=import("\046\047\067\111\108\111\114\051")local S=import("\046\046\047\102\117\110\099\116\105\111\110\115\047\116\121\112\101\111\102")local function z(f)return{f.r,f.g;f.b}end describe("\116\121\112\101\115\046\067\111\108\111\114\051",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 S=f.new()assert.not_nil(S)assert.are.same({0;0,0},z(S))end)it("\115\104\111\117\108\100 \104\097\118\101 \097 \099\111\110\115\116\114\117\099\116\111\114 \116\104\097\116 \116\097\107\101\115 \114\103\098 \118\097\108\117\101\115 \048-\049",function()local S=f.new(0,0,0)assert.not_nil(S)end)it("\115\104\111\117\108\100 \104\097\118\101 \116\104\101 \102\114\111\109\082\071\066 \109\101\116\104\111\100",function()local S=f.fromRGB(255,0,0)assert.are.same({1,0,0},z(S))end)it("\115\104\111\117\108\100 \104\097\118\101 \116\104\101 \102\114\111\109\072\083\086 \109\101\116\104\111\100",function()local S=f.fromHSV(.33333333333333,.5,.75)local z=math.floor(S.r*255+.5)local F=math.floor(S.g*255+.5)local Q=math.floor(S.b*255+.5)assert.are.same({96,191;96},{z,F;Q})end)it("\115\104\111\117\108\100 \104\097\118\101 \116\104\101 \116\111\072\083\086 \109\101\116\104\111\100",function()local S=f.fromHSV(.33333333333333,.5,.75)local z,F,Q=f.toHSV(S)assert.are.same({.33333333333333;.5,.75},{z;F,Q})end)describe("\108\101\114\112",function()local S=f.new(0,0,0)local F=f.new(1,1,1)it("\115\104\111\117\108\100 \108\101\114\112 \099\111\108\111\114\115",function()local f=S:lerp(F,.5)assert.are.same({.5,.5,.5},z(f))end)it("\115\104\111\117\108\100 \101\113\117\097\108 \116\104\101 \103\111\097\108 \119\104\101\110 \097\108\112\104\097 \105\115 \049",function()assert.are.same({1,1,1},z(S:lerp(F,1)))end)it("\115\104\111\117\108\100 \101\113\117\097\108 \116\104\101 \115\116\097\114\116 \119\104\101\110 \097\108\112\104\097 \105\115 \048",function()assert.are.same({0;0,0},z(S:lerp(F,0)))end)end)it("\115\104\111\117\108\100 \099\111\109\112\097\114\101 \067\111\108\111\114\051\115",function()local S,z=f.new(0,1,0),f.new(0,1,0)assert.are.equal(S,z)assert.are_not_equal(S,f.new(0,0,0))end)it("\115\104\111\117\108\100 \098\101 \100\101\116\101\099\116\101\100 \098\121 \116\121\112\101\111\102",function()local z=S(f.new())assert.are.equal("\067\111\108\111\114\051",z)end)end)
local Color3 = import("./Color3")

local typeof = import("../functions/typeof")

local function extractColors(color)
	return {
		color.r,
		color.g,
		color.b
	}
end

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

		assert.not_nil(color)
		assert.are.same({ 0, 0, 0 }, extractColors(color))
	end)

	it("should have a constructor that takes rgb values 0-1", function()
		local color = Color3.new(0, 0, 0)

		assert.not_nil(color)
	end)

	it("should have the fromRGB method", function()
		local color = Color3.fromRGB(255, 0, 0)

		assert.are.same({ 1, 0, 0 }, extractColors(color))
	end)

	it("should have the fromHSV method", function()
		local color = Color3.fromHSV(120 / 360, 0.5, 0.75)

		-- Round the colors to the nearest whole number
		-- This ensures we don't get errors from rounding, which are
		-- ultimately fairly unimportant.
		local r = math.floor(color.r * 255 + 0.5)
		local g = math.floor(color.g * 255 + 0.5)
		local b = math.floor(color.b * 255 + 0.5)

		assert.are.same({ 96, 191, 96 }, { r, g, b })
	end)

	it("should have the toHSV method", function()
		local color = Color3.fromHSV(120 / 360, 0.5, 0.75)
		local h, s, v = Color3.toHSV(color)

		assert.are.same({ 120 / 360, 0.5, 0.75 }, { h, s, v })
	end)

	describe("lerp", function()
		local a = Color3.new(0, 0, 0)
		local b = Color3.new(1, 1, 1)

		it("should lerp colors", function()
			-- Middle used to avoid rounding / float precision issues.
			local middle = a:lerp(b, 0.5)
			assert.are.same({ 0.5, 0.5, 0.5 }, extractColors(middle))
		end)

		it("should equal the goal when alpha is 1", function()
			assert.are.same({ 1, 1, 1 }, extractColors(a:lerp(b, 1)))
		end)

		it("should equal the start when alpha is 0", function()
			assert.are.same({ 0, 0, 0 }, extractColors(a:lerp(b, 0)))
		end)
	end)

	it("should compare Color3s", function()
		local c1, c2 = Color3.new(0, 1, 0), Color3.new(0, 1, 0)
		assert.are.equal(c1, c2)
		assert.are_not_equal(c1, Color3.new(0, 0, 0))
	end)

	it("should be detected by typeof", function()
		local type = typeof(Color3.new())
		assert.are.equal("Color3", type)
	end)
end)
