Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Add Color3.new empty constructor and Color3.fromRGB #2

Merged
merged 3 commits into from
Feb 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions lib/types/Color3.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
local Color3 = {}

function Color3.new(r, g, b)
return {
r = r,
g = g,
b = b,
}
function Color3.new(...)
if select("#", ...) == 0 then
return Color3.new(0, 0, 0)
else
local r, g, b = ...

return {
r = r,
g = g,
b = b,
}
end
end

function Color3.fromRGB(r, g, b)
return Color3.new(r / 255, g / 255, b / 255)
end

return Color3
return Color3
25 changes: 23 additions & 2 deletions lib/types/Color3_spec.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
local Color3 = import("./Color3")

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

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

assert.not_nil(color)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably make sure that the result is {0, 0, 0} for the empty constructor

assert.are.same(extractColors(color), { 0, 0, 0 })
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)
end)

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

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