Skip to content

Commit

Permalink
lua/raindrops: 2nd iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Dec 12, 2023
1 parent 2f33291 commit 8703801
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 169 deletions.
136 changes: 60 additions & 76 deletions lua/raindrops/luacov.report.out
Original file line number Diff line number Diff line change
@@ -1,105 +1,89 @@
==============================================================================
raindrops_spec.lua
==============================================================================
* local raindrops = require('raindrops')
* local raindrops = require("raindrops")

* describe('raindrops', function()
* it('the sound for 1 is 1', function()
* assert.equal('1', raindrops(1))
end)
* describe("raindrops", function()
* it("the sound for 1 is 1", function()
* assert.equal("1", raindrops(1))
end)

* it('the sound for 3 is Pling', function()
* assert.equal('Pling', raindrops(3))
end)
* it("the sound for 3 is Pling", function()
* assert.equal("Pling", raindrops(3))
end)

* it('the sound for 5 is Plang', function()
* assert.equal('Plang', raindrops(5))
end)
* it("the sound for 5 is Plang", function()
* assert.equal("Plang", raindrops(5))
end)

* it('the sound for 7 is Plong', function()
* assert.equal('Plong', raindrops(7))
end)
* it("the sound for 7 is Plong", function()
* assert.equal("Plong", raindrops(7))
end)

* it('the sound for 6 is Pling as it has a factor 3', function()
* assert.equal('Pling', raindrops(6))
end)
* it("the sound for 6 is Pling as it has a factor 3", function()
* assert.equal("Pling", raindrops(6))
end)

* it('2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base', function()
* assert.equal('8', raindrops(8))
end)
* it("2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base", function()
* assert.equal("8", raindrops(8))
end)

* it('the sound for 9 is Pling as it has a factor 3', function()
* assert.equal('Pling', raindrops(9))
end)
* it("the sound for 9 is Pling as it has a factor 3", function()
* assert.equal("Pling", raindrops(9))
end)

* it('the sound for 10 is Plang as it has a factor 5', function()
* assert.equal('Plang', raindrops(10))
end)
* it("the sound for 10 is Plang as it has a factor 5", function()
* assert.equal("Plang", raindrops(10))
end)

* it('the sound for 14 is Plong as it has a factor 7', function()
* assert.equal('Plong', raindrops(14))
end)
* it("the sound for 14 is Plong as it has a factor 7", function()
* assert.equal("Plong", raindrops(14))
end)

* it('the sound for 15 is PlingPlang as it has a factor 3 and 5', function()
* assert.equal('PlingPlang', raindrops(15))
end)
* it("the sound for 15 is PlingPlang as it has a factor 3 and 5", function()
* assert.equal("PlingPlang", raindrops(15))
end)

* it('the sound for 21 is PlingPlong as it has factors 3 and 7', function()
* assert.equal('PlingPlong', raindrops(21))
end)
* it("the sound for 21 is PlingPlong as it has factors 3 and 7", function()
* assert.equal("PlingPlong", raindrops(21))
end)

* it('the sound for 25 is Plang as it has a factor 5', function()
* assert.equal('Plang', raindrops(25))
end)
* it("the sound for 25 is Plang as it has a factor 5", function()
* assert.equal("Plang", raindrops(25))
end)

* it('the sound for 27 is Pling as it has a factor 3', function()
* assert.equal('Pling', raindrops(27))
end)
* it("the sound for 27 is Pling as it has a factor 3", function()
* assert.equal("Pling", raindrops(27))
end)

* it('the sound for 35 is PlangPlong as it has factors 5 and 7', function()
* assert.equal('PlangPlong', raindrops(35))
end)
* it("the sound for 35 is PlangPlong as it has factors 5 and 7", function()
* assert.equal("PlangPlong", raindrops(35))
end)

* it('the sound for 49 is Plong as it has a factor 7', function()
* assert.equal('Plong', raindrops(49))
end)
* it("the sound for 49 is Plong as it has a factor 7", function()
* assert.equal("Plong", raindrops(49))
end)

* it('the sound for 52 is 52', function()
* assert.equal('52', raindrops(52))
end)
* it("the sound for 52 is 52", function()
* assert.equal("52", raindrops(52))
end)

* it('the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7', function()
* assert.equal('PlingPlangPlong', raindrops(105))
end)
* it("the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7", function()
* assert.equal("PlingPlangPlong", raindrops(105))
end)

* it('the sound for 3125 is Plang as it has a factor 5', function()
* assert.equal('Plang', raindrops(3125))
end)
* it("the sound for 3125 is Plang as it has a factor 5", function()
* assert.equal("Plang", raindrops(3125))
end)
end)

==============================================================================
raindrops.lua
==============================================================================
return function(n)
* local sounds = ""
* local sounds = string.format("%s%s%s", n % 3 == 0 and "Pling" or "", n % 5 == 0 and "Plang" or "", n % 7 == 0 and "Plong" or "")

* if n % 3 == 0 then
* sounds = sounds .. "Pling"
end

* if n % 5 == 0 then
* sounds = sounds .. "Plang"
end

* if n % 7 == 0 then
* sounds = sounds .. "Plong"
end

* if sounds == "" then
* sounds = tostring(n)
end

* return sounds
* return sounds == "" and tostring(n) or sounds
end

==============================================================================
Expand All @@ -108,7 +92,7 @@ Summary

File Hits Missed Coverage
---------------------------------------
raindrops.lua 10 0 100.00%
raindrops.lua 2 0 100.00%
raindrops_spec.lua 38 0 100.00%
---------------------------------------
Total 48 0 100.00%
Total 40 0 100.00%
6 changes: 3 additions & 3 deletions lua/raindrops/luacov.report.out.index
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
raindrops_spec.lua:0 2418
raindrops.lua:2418 2951
Summary:2951 3355
raindrops_spec.lua:0 2346
raindrops.lua:2346 2728
Summary:2728 3132
Loading

0 comments on commit 8703801

Please sign in to comment.