Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update resistor-color-trio files #391

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 10 additions & 3 deletions exercises/practice/resistor-color-trio/.meta/example.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ local value = {
}

return {
decode = function(c1, c2, c3)
decode = function(colors)
local c1 = colors[1]
local c2 = colors[2]
local c3 = colors[3]
local value = (value[c1] * 10 + value[c2]) * 10 ^ value[c3]

if value > 1000 then
return value / 1000, 'kiloohms'
if value >= 1e9 then
return value / 1e9, 'gigaohms'
elseif value >= 1e6 then
return value / 1e6, 'megaohms'
elseif value >= 1e3 then
return value / 1e3, 'kiloohms'
else
return value, 'ohms'
end
Expand Down
28 changes: 25 additions & 3 deletions exercises/practice/resistor-color-trio/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[d6863355-15b7-40bb-abe0-bfb1a25512ed]
description = "Orange and orange and black"
Expand All @@ -16,3 +23,18 @@ description = "Green and brown and orange"

[f5d37ef9-1919-4719-a90d-a33c5a6934c9]
description = "Yellow and violet and yellow"

[5f6404a7-5bb3-4283-877d-3d39bcc33854]
description = "Blue and violet and blue"

[7d3a6ab8-e40e-46c3-98b1-91639fff2344]
description = "Minimum possible value"

[ca0aa0ac-3825-42de-9f07-dac68cc580fd]
description = "Maximum possible value"

[0061a76c-903a-4714-8ce2-f26ce23b0e09]
description = "First two colors make an invalid octal number"

[30872c92-f567-4b69-a105-8455611c10c4]
description = "Ignore extra colors"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
return {
decode = function(c1, c2, c3)
decode = function(colors)

end
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,63 @@ local rct = require 'resistor-color-trio'

describe('resistor-color-trio', function()
it('orange and orange and black', function()
local value, unit = rct.decode('orange', 'orange', 'black')
local value, unit = rct.decode({'orange', 'orange', 'black'})
assert.are.equal(33, value)
assert.are.equal('ohms', unit)
end)

it('blue and grey and brown', function()
local value, unit = rct.decode('blue', 'grey', 'brown')
local value, unit = rct.decode({'blue', 'grey', 'brown'})
assert.are.equal(680, value)
assert.are.equal('ohms', unit)
end)

it('red and black and red', function()
local value, unit = rct.decode('red', 'black', 'red')
local value, unit = rct.decode({'red', 'black', 'red'})
assert.are.equal(2, value)
assert.are.equal('kiloohms', unit)
end)

it('green and brown and orange', function()
local value, unit = rct.decode('green', 'brown', 'orange')
local value, unit = rct.decode({'green', 'brown', 'orange'})
assert.are.equal(51, value)
assert.are.equal('kiloohms', unit)
end)

it('yellow and violet and yellow', function()
local value, unit = rct.decode('yellow', 'violet', 'yellow')
local value, unit = rct.decode({'yellow', 'violet', 'yellow'})
assert.are.equal(470, value)
assert.are.equal('kiloohms', unit)
end)

it('blue and violet and blue', function()
local value, unit = rct.decode({'blue', 'violet', 'blue'})
assert.are.equal(67, value)
assert.are.equal('megaohms', unit)
end)

it('minimum possible value', function()
local value, unit = rct.decode({'black', 'black', 'black'})
assert.are.equal(0, value)
assert.are.equal('ohms', unit)
end)

it('maximum possible value', function()
local value, unit = rct.decode({'white', 'white', 'white'})
assert.are.equal(99, value)
assert.are.equal('gigaohms', unit)
end)

it('first two colors make an invalid octal number', function()
local value, unit = rct.decode({'black', 'grey', 'black'})
assert.are.equal(8, value)
assert.are.equal('ohms', unit)
end)

it('ignore extra colors', function()
local value, unit = rct.decode({'blue', 'green', 'yellow', 'orange'})
assert.are.equal(650, value)
assert.are.equal('kiloohms', unit)
end)

BNAndras marked this conversation as resolved.
Show resolved Hide resolved
end)
Loading