diff --git a/lua/.luacheckrc b/lua/.luacheckrc index 10bc7123..b5ac05d0 100644 --- a/lua/.luacheckrc +++ b/lua/.luacheckrc @@ -1,3 +1,7 @@ std = "max" max_line_length = 240 + +ignore = { + "212" +} diff --git a/lua/README.md b/lua/README.md index 07b547ef..1b5e010a 100644 --- a/lua/README.md +++ b/lua/README.md @@ -18,3 +18,4 @@ - [reverse-string](./reverse-string/README.md) - [raindrops](./raindrops/README.md) - [leap](./leap/README.md) +- [space-age](./space-age/README.md) diff --git a/lua/space-age/.busted b/lua/space-age/.busted new file mode 100644 index 00000000..86b84e7c --- /dev/null +++ b/lua/space-age/.busted @@ -0,0 +1,5 @@ +return { + default = { + ROOT = { '.' } + } +} diff --git a/lua/space-age/.exercism/config.json b/lua/space-age/.exercism/config.json new file mode 100644 index 00000000..3c80d1a8 --- /dev/null +++ b/lua/space-age/.exercism/config.json @@ -0,0 +1,24 @@ +{ + "authors": [ + "aarti" + ], + "contributors": [ + "etandel", + "kytrinyx", + "ryanplusplus" + ], + "files": { + "solution": [ + "space-age.lua" + ], + "test": [ + "space-age_spec.lua" + ], + "example": [ + ".meta/example.lua" + ] + }, + "blurb": "Given an age in seconds, calculate how old someone is in terms of a given planet's solar years.", + "source": "Partially inspired by Chapter 1 in Chris Pine's online Learn to Program tutorial.", + "source_url": "https://pine.fm/LearnToProgram/?Chapter=01" +} diff --git a/lua/space-age/.exercism/metadata.json b/lua/space-age/.exercism/metadata.json new file mode 100644 index 00000000..a3892ab2 --- /dev/null +++ b/lua/space-age/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"lua","exercise":"space-age","id":"f36b747a9a3a4cda932c2b3576e0d5ef","url":"https://exercism.org/tracks/lua/exercises/space-age","handle":"vpayno","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/lua/space-age/HELP.md b/lua/space-age/HELP.md new file mode 100644 index 00000000..0ec62de0 --- /dev/null +++ b/lua/space-age/HELP.md @@ -0,0 +1,54 @@ +# Help + +## Running the tests + +To run the tests, run the command `busted` from within the exercise directory. + +Refer to the [Installing Lua locally][install] documentation to get Lua and busted installed correctly. + +[install]: https://exercism.org/docs/tracks/lua/installation + +## Submitting your solution + +You can submit your solution using the `exercism submit space-age.lua` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Lua track's documentation](https://exercism.org/docs/tracks/lua) +- The [Lua track's programming category on the forum](https://forum.exercism.org/c/programming/lua) +- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +There are many great free online resources for Lua including: + +1. [lua.org][8] +2. A highly recommended detailed and authoritative introduction to all aspects of Lua programming by Lua's chief architect: [Programming in Lua, by Roberto Ierusalimschy][6]. Note that the first edition (covering Lua 5.0) is [freely available online][9]. +3. For an official definition of the Lua language, consult the [Lua 5.4 Reference Manual][7], by R. Ierusalimschy, L. H. de Figueiredo, W. Celes. +4. [Lua Style Guide][4] +5. [Learn Lua in 15 minutes][5] +6. Some options for linting + - [Lua Lint][10] + - [Lua Inspect][11] + - [luacheck][12] + - [Detecting Undefined Variables][13] + +[4]: https://github.com/Olivine-Labs/lua-style-guide +[5]: http://tylerneylon.com/a/learn-lua/ +[6]: http://www.lua.org/pil/ +[7]: http://www.lua.org/manual/5.4/ +[8]: http://www.lua.org +[9]: http://www.lua.org/pil/contents.html +[10]: http://lua-users.org/wiki/LuaLint +[11]: http://lua-users.org/wiki/LuaInspect +[12]: https://github.com/luarocks/luacheck +[13]: http://lua-users.org/wiki/DetectingUndefinedVariables \ No newline at end of file diff --git a/lua/space-age/README.md b/lua/space-age/README.md new file mode 100644 index 00000000..13e6cbb3 --- /dev/null +++ b/lua/space-age/README.md @@ -0,0 +1,51 @@ +# Space Age + +Welcome to Space Age on Exercism's Lua Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Given an age in seconds, calculate how old someone would be on: + +- Mercury: orbital period 0.2408467 Earth years +- Venus: orbital period 0.61519726 Earth years +- Earth: orbital period 1.0 Earth years, 365.25 Earth days, or 31557600 seconds +- Mars: orbital period 1.8808158 Earth years +- Jupiter: orbital period 11.862615 Earth years +- Saturn: orbital period 29.447498 Earth years +- Uranus: orbital period 84.016846 Earth years +- Neptune: orbital period 164.79132 Earth years + +So if you were told someone were 1,000,000,000 seconds old, you should +be able to say that they're 31.69 Earth-years old. + +If you're wondering why Pluto didn't make the cut, go watch [this YouTube video][pluto-video]. + +Note: The actual length of one complete orbit of the Earth around the sun is closer to 365.256 days (1 sidereal year). +The Gregorian calendar has, on average, 365.2425 days. +While not entirely accurate, 365.25 is the value used in this exercise. +See [Year on Wikipedia][year] for more ways to measure a year. + +[pluto-video]: https://www.youtube.com/watch?v=Z_2gbGXzFbs +[year]: https://en.wikipedia.org/wiki/Year#Summary + +## Source + +### Created by + +- @aarti + +### Contributed to by + +- @etandel +- @kytrinyx +- @ryanplusplus + +### Based on + +Partially inspired by Chapter 1 in Chris Pine's online Learn to Program tutorial. - https://pine.fm/LearnToProgram/?Chapter=01 + +### My Solution + +- [my solution](./space-age.lua) +- [run-tests](./run-tests-lua.txt) diff --git a/lua/space-age/luacov.report.out b/lua/space-age/luacov.report.out new file mode 100644 index 00000000..6e47f6b4 --- /dev/null +++ b/lua/space-age/luacov.report.out @@ -0,0 +1,130 @@ +============================================================================== +space-age_spec.lua +============================================================================== +* local SpaceAge = require("space-age") + +* describe("space-age", function() +* it("age in seconds", function() +* local age = SpaceAge:new(1000000) +* assert.are.equal(1000000, age.seconds) + end) + +* it("age in Earth years", function() +* local age = SpaceAge:new(1000000000) +* assert.are.equal(31.69, age.on_earth()) + end) + +* it("age in Mercury years", function() +* local age = SpaceAge:new(2134835688) +* assert.are.equal(67.65, age.on_earth()) +* assert.are.equal(280.88, age.on_mercury()) + end) + +* it("age in Venus years", function() +* local age = SpaceAge:new(189839836) +* assert.are.equal(6.02, age.on_earth()) +* assert.are.equal(9.78, age.on_venus()) + end) + +* it("age in Mars years", function() +* local age = SpaceAge:new(2329871239) +* assert.are.equal(73.83, age.on_earth()) +* assert.are.equal(39.25, age.on_mars()) + end) + +* it("age in Jupiter years", function() +* local age = SpaceAge:new(901876382) +* assert.are.equal(28.58, age.on_earth()) +* assert.are.equal(2.41, age.on_jupiter()) + end) + +* it("age in Saturn years", function() +* local age = SpaceAge:new(3000000000) +* assert.are.equal(95.06, age.on_earth()) +* assert.are.equal(3.23, age.on_saturn()) + end) + +* it("age in Uranus years", function() +* local age = SpaceAge:new(3210123456) +* assert.are.equal(101.72, age.on_earth()) +* assert.are.equal(1.21, age.on_uranus()) + end) + +* it("age in Neptune year", function() +* local age = SpaceAge:new(8210123456) +* assert.are.equal(260.16, age.on_earth()) +* assert.are.equal(1.58, age.on_neptune()) + end) + end) + +============================================================================== +space-age.lua +============================================================================== +* local SpaceAge = {} +* SpaceAge.__index = SpaceAge + +* function SpaceAge:new(seconds) +* local orbital_periods = { +* Mercury = 0.2408467, +* Venus = 0.61519726, +* Earth = 1.0, +* Mars = 1.8808158, +* Jupiter = 11.862615, +* Saturn = 29.447498, +* Uranus = 84.016846, +* Neptune = 164.79132, +* } + +* local seconds_in_earth_years = 365.25 * 24 * 60 * 60 + +* return { + -- one of the tests wants to retreive the seconds +* seconds = seconds, + + -- these have to be anonymous functions +* on_mercury = function() +* return tonumber(("%.2f"):format(seconds / (orbital_periods.Mercury * seconds_in_earth_years))) + end, + +* on_venus = function() +* return tonumber(("%.2f"):format(seconds / (orbital_periods.Venus * seconds_in_earth_years))) + end, + +* on_earth = function() +* return tonumber(("%.2f"):format(seconds / (orbital_periods.Earth * seconds_in_earth_years))) + end, + +* on_mars = function() +* return tonumber(("%.2f"):format(seconds / (orbital_periods.Mars * seconds_in_earth_years))) + end, + +* on_jupiter = function() +* return tonumber(("%.2f"):format(seconds / (orbital_periods.Jupiter * seconds_in_earth_years))) + end, + +* on_saturn = function() +* return tonumber(("%.2f"):format(seconds / (orbital_periods.Saturn * seconds_in_earth_years))) + end, + + on_uranus = function() +* return tonumber(("%.2f"):format(seconds / (orbital_periods.Uranus * seconds_in_earth_years))) + end, + + on_neptune = function() +* return tonumber(("%.2f"):format(seconds / (orbital_periods.Neptune * seconds_in_earth_years))) + end, +* } + end + +* return SpaceAge + +============================================================================== +Summary +============================================================================== + +File Hits Missed Coverage +--------------------------------------- +space-age.lua 32 0 100.00% +space-age_spec.lua 36 0 100.00% +--------------------------------------- +Total 68 0 100.00% diff --git a/lua/space-age/luacov.report.out.index b/lua/space-age/luacov.report.out.index new file mode 100644 index 00000000..382c7916 --- /dev/null +++ b/lua/space-age/luacov.report.out.index @@ -0,0 +1,3 @@ +space-age_spec.lua:0 1765 +space-age.lua:1765 3800 +Summary:3800 4204 diff --git a/lua/space-age/luacov.stats.out b/lua/space-age/luacov.stats.out new file mode 100644 index 00000000..5840416e --- /dev/null +++ b/lua/space-age/luacov.stats.out @@ -0,0 +1,66 @@ +163:/usr/share/lua/5.1/busted/block.lua +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 11 0 11 1683 0 1683 1694 0 11 99 99 1782 1683 1584 0 0 110 0 0 0 0 0 0 11 0 11 297 0 297 198 198 0 0 0 0 297 33 0 297 297 264 0 0 33 33 0 0 0 0 0 0 33 0 33 11 0 11 330 0 330 198 198 0 0 0 0 330 0 330 330 0 0 0 0 0 330 11 0 11 363 363 0 363 363 0 0 0 0 0 0 363 198 0 0 0 363 11 0 11 99 11 0 11 33 33 33 0 44 0 11 33 11 0 11 33 11 0 11 22 0 22 22 22 0 0 0 0 22 0 22 22 0 22 0 0 0 0 22 22 0 0 22 22 0 33 0 11 +38:/usr/share/lua/5.1/busted/compatibility.lua +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 7 +124:/usr/share/lua/5.1/busted/context.lua +0 0 0 11 462 451 0 11 11 11 11 11 0 0 0 11 462 451 0 979 968 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 121 121 11 110 0 110 0 0 121 121 0 0 121 121 0 0 121 11 0 121 0 0 2227 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 121 121 121 121 0 0 44 0 0 0 7646 0 0 0 506 506 506 506 506 0 0 506 506 506 506 506 +315:/usr/share/lua/5.1/busted/core.lua +0 0 0 0 0 0 0 0 0 0 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 39 39 22 17 0 0 17 0 0 0 61 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 149 149 0 149 149 215 171 66 66 0 0 149 149 0 149 149 0 0 0 39 39 39 39 0 39 39 0 0 0 0 0 39 0 0 0 435 0 0 0 385 0 0 0 0 0 0 0 188 0 266 266 11 11 11 11 11 11 0 0 255 177 177 177 177 177 0 0 78 0 0 0 0 0 0 22 22 22 22 22 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 11 0 11 0 0 506 506 506 0 1012 39 39 39 1051 0 506 39 0 0 0 39 0 0 0 0 0 0 0 0 0 0 0 39 0 506 0 506 506 0 0 0 264 264 264 132 132 132 132 132 132 0 528 264 528 264 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 121 0 0 0 0 121 0 121 121 110 0 0 0 121 242 0 121 121 0 0 0 0 0 0 121 121 121 121 121 121 121 121 121 121 121 121 0 0 121 0 121 33 0 88 0 121 0 0 0 33 154 121 121 242 121 0 33 +31:/usr/share/lua/5.1/busted/environment.lua +0 0 0 0 0 0 0 7280 0 7269 5427 7269 0 0 0 0 0 0 0 0 1853 0 0 0 0 0 0 0 0 0 11 +72:/usr/share/lua/5.1/busted/execute.lua +11 11 11 0 0 0 0 0 0 0 0 0 11 0 0 11 0 0 11 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 22 11 0 0 0 0 0 11 0 11 0 0 0 0 11 11 11 11 0 11 11 0 11 0 11 0 0 0 22 0 11 11 +127:/usr/share/lua/5.1/busted/init.lua +0 0 0 0 11 11 11 0 11 11 0 0 11 11 11 0 11 11 0 0 99 99 0 99 0 0 0 0 99 0 99 99 99 0 99 0 99 99 99 99 99 0 0 0 0 0 0 99 0 0 99 99 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 825 +50:/usr/share/lua/5.1/busted/languages/en.lua +11 0 11 0 0 11 11 11 11 0 11 11 11 11 0 11 11 11 11 0 11 11 11 11 0 11 0 11 11 0 0 11 11 11 11 11 11 11 11 11 0 11 11 11 11 11 11 0 11 11 +23:/usr/share/lua/5.1/busted/modules/files/lua.lua +11 0 11 0 0 149 149 149 11 0 0 11 11 0 0 11 11 0 0 11 11 0 11 +107:/usr/share/lua/5.1/busted/modules/files/moonscript.lua +11 0 22 11 11 0 11 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 11 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 11 0 0 0 0 0 0 0 11 0 11 +129:/usr/share/lua/5.1/busted/modules/filter_loader.lua +0 0 0 99 99 0 198 198 99 99 0 0 99 11 0 0 0 0 11 0 0 110 0 0 0 0 110 11 0 0 99 99 0 0 0 0 99 11 0 0 110 0 0 0 0 110 11 0 0 99 0 0 0 0 99 11 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 11 0 11 0 0 0 0 0 0 11 0 0 0 11 0 0 88 154 110 0 0 99 0 0 0 0 0 0 0 0 11 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 11 11 11 0 0 11 11 11 11 11 +34:/usr/share/lua/5.1/busted/modules/output_handler_loader.lua +0 0 0 0 0 0 0 0 11 22 11 0 11 0 0 11 0 22 0 11 0 0 0 11 0 0 0 0 11 0 0 0 11 11 +101:/usr/share/lua/5.1/busted/modules/test_file_loader.lua +11 0 0 11 11 11 11 0 33 22 22 0 0 0 0 0 11 0 11 11 11 0 22 125 125 0 0 0 0 239 125 11 0 0 114 22 0 22 11 0 0 11 0 22 0 0 0 0 0 11 11 11 0 0 11 22 11 0 11 11 0 0 0 11 11 11 0 0 11 0 0 11 0 22 11 0 11 22 11 11 11 11 0 0 11 0 0 0 11 0 0 0 0 0 0 0 11 11 0 11 11 +179:/usr/share/lua/5.1/busted/outputHandlers/base.lua +0 11 11 11 11 11 11 11 11 11 11 11 0 0 0 396 11 0 0 11 11 0 11 0 0 0 11 11 11 11 11 11 11 11 11 11 22 0 0 297 297 0 594 594 0 297 297 0 0 297 11 0 0 0 99 1071 972 774 0 0 99 99 0 99 99 99 99 99 99 99 0 99 0 99 11 0 0 0 0 0 0 0 11 0 0 11 11 11 11 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 11 11 11 11 0 0 99 99 11 0 0 0 0 99 60 60 39 0 0 39 0 22 22 17 0 17 17 0 0 60 0 60 60 60 0 0 0 60 0 0 60 0 60 11 0 0 0 0 0 0 11 0 0 22 22 11 0 0 17 17 17 11 0 0 39 0 0 0 0 39 11 0 11 11 +286:/usr/share/lua/5.1/busted/outputHandlers/gtest.lua +11 11 11 11 0 11 0 11 11 0 11 1851 0 0 0 0 0 11 11 0 11 11 11 11 11 11 11 11 11 11 11 11 11 11 0 11 11 11 11 11 11 0 11 11 11 11 11 0 11 11 11 11 11 0 0 11 11 11 11 11 11 11 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 39 39 39 0 0 0 0 0 0 39 0 39 0 0 0 39 11 0 0 237 237 237 237 0 237 11 0 0 33 33 33 9 9 9 0 9 9 48 39 39 39 0 0 0 0 0 33 11 0 0 33 33 33 9 9 9 0 33 11 0 0 11 11 0 11 11 11 0 11 11 11 11 0 11 11 0 0 198 11 0 0 0 0 0 0 0 0 0 0 0 11 0 0 11 0 0 11 0 0 11 11 11 0 11 11 0 0 11 11 11 11 11 11 11 0 11 11 0 0 11 11 11 11 11 0 0 11 11 11 11 11 11 11 0 0 99 99 0 99 11 0 0 99 99 0 99 99 99 60 60 39 0 0 39 22 22 17 17 17 0 0 99 99 0 99 11 0 0 22 22 22 0 22 11 0 0 17 17 17 0 17 11 0 0 39 0 0 0 0 0 0 0 39 11 0 11 11 11 11 11 11 11 11 11 11 11 0 11 11 +208:/usr/share/lua/5.1/busted/runner.lua +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 11 0 0 0 0 11 0 0 0 0 0 11 11 0 0 11 11 0 0 0 11 11 0 0 0 0 0 11 11 11 0 22 0 0 11 0 22 0 0 11 0 22 17 17 17 11 0 22 22 22 0 0 0 22 22 11 0 0 11 11 11 0 0 22 11 11 11 11 11 11 11 0 0 0 11 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 22 11 11 11 11 11 11 11 0 0 11 0 11 11 11 22 11 11 11 11 0 0 0 0 0 0 11 11 22 11 11 11 0 0 11 0 11 7 0 4 +42:/usr/share/lua/5.1/busted/status.lua +0 704 704 704 704 704 704 704 704 0 704 0 0 0 605 605 891 605 605 605 0 0 0 605 0 0 0 605 0 0 0 99 99 99 0 704 0 0 1210 605 803 605 +35:/usr/share/lua/5.1/busted/utils.lua +0 0 0 11 11 33 22 22 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 11 11 11 11 55 44 0 11 +177:/usr/share/lua/5.1/luassert/assert.lua +0 0 0 0 0 0 0 0 0 0 0 22 0 22 0 0 22 22 0 0 22 0 0 0 0 0 131 0 131 0 393 262 0 0 131 393 262 131 0 0 0 131 131 131 0 131 22 22 0 0 22 22 0 0 109 0 0 109 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 592 296 0 0 296 0 0 0 0 148 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22 22 66 44 44 44 44 44 0 0 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 131 0 0 0 131 0 0 0 148 +120:/usr/share/lua/5.1/luassert/assertions.lua +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 131 0 0 131 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 131 131 131 131 0 131 131 131 +202:/usr/share/lua/5.1/luassert/formatters/init.lua +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 38 0 0 0 38 0 38 0 38 0 0 0 38 0 38 0 0 0 0 0 38 0 0 0 38 38 0 0 0 0 38 0 0 38 0 0 44 6 0 38 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 44 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 0 0 0 44 0 0 44 0 0 44 0 0 44 0 0 44 +5:/usr/share/lua/5.1/luassert/modifiers.lua +0 0 0 0 131 +92:/usr/share/lua/5.1/luassert/state.lua +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 296 296 296 +283:/usr/share/lua/5.1/luassert/util.lua +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 131 131 131 131 131 131 0 0 0 0 131 131 0 131 0 0 0 0 0 262 131 0 0 131 131 0 0 0 0 0 0 0 0 0 131 131 0 131 0 0 0 0 0 131 0 262 131 0 0 131 131 131 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22 0 0 0 0 0 0 0 0 153 153 153 153 306 153 153 153 0 153 153 0 0 0 0 0 0 0 0 131 0 0 131 131 131 393 262 262 0 0 262 262 0 0 0 0 0 0 262 262 262 0 262 0 0 0 131 0 0 0 131 +154:/usr/share/lua/5.1/mediator.lua +0 385 0 0 0 385 385 385 385 0 0 0 0 0 385 0 385 385 0 0 0 0 0 231 231 231 231 231 231 0 0 385 385 0 385 0 385 220 220 0 209 0 0 385 0 385 231 0 0 0 0 0 0 0 0 0 0 0 0 231 0 0 0 0 0 0 0 0 231 0 0 231 231 231 0 0 0 231 0 0 1552 231 0 0 0 0 0 0 0 0 0 0 0 231 0 0 2127 1196 0 0 1196 0 1196 0 1196 1196 0 0 0 931 617 0 314 0 231 231 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 820 0 2372 1552 0 0 820 0 0 0 385 0 0 0 0 0 0 0 0 0 0 0 435 +476:/usr/share/lua/5.1/pl/dir.lua +0 0 0 0 0 0 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 0 11 0 0 11 22 0 0 0 11 0 0 125 125 11 0 0 0 0 0 0 0 11 0 0 0 11 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 11 0 0 11 0 0 0 0 0 0 0 0 11 0 0 11 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 11 0 0 0 0 11 0 0 0 0 0 0 11 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0 11 0 11 11 0 0 11 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 11 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 11 11 11 11 0 11 11 0 0 0 0 202 180 136 136 136 136 136 11 0 0 0 0 33 0 22 11 0 0 0 0 0 0 0 0 11 11 11 0 11 11 147 136 125 125 125 0 0 0 0 11 11 0 11 +276:/usr/share/lua/5.1/pl/path.lua +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 158 158 0 0 158 0 0 0 0 0 11 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 136 136 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6265 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 445 445 445 6221 5776 5776 0 445 0 0 445 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 11 11 44 33 0 0 33 33 0 11 0 0 11 0 0 0 0 0 0 320 320 320 0 0 0 0 0 125 125 125 0 0 0 0 0 11 11 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 125 125 0 0 125 +793:/usr/share/lua/5.1/pl/tablex.lua +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22 22 0 0 0 0 0 0 0 0 0 0 0 22 0 0 22 0 0 22 0 0 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22 22 990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0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22 22 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1511 0 0 1511 0 0 1511 0 0 0 0 0 0 1467 1467 +48:/usr/share/lua/5.1/say/init.lua +0 0 0 0 0 0 0 0 0 0 0 0 0 11 11 0 0 11 0 0 0 0 0 0 0 0 0 209 209 0 0 0 0 153 0 153 0 153 0 0 153 153 0 590 437 0 0 153 +58:space-age.lua +11 11 1 11 64 91 91 91 91 90 90 91 90 28 1 63 28 72 63 46 80 28 37 47 49 79 27 28 32 63 4 26 62 28 10 20 22 37 18 3 31 45 19 13 30 30 0 3 21 27 0 2 21 45 29 3 2 3 +55:space-age_spec.lua +11 0 22 22 11 11 16 0 22 11 11 18 0 22 11 11 7 17 0 22 11 11 7 18 0 22 11 11 7 18 0 22 11 11 7 18 0 22 11 11 7 18 0 22 11 11 7 18 0 22 11 11 7 18 33 diff --git a/lua/space-age/run-tests-lua.txt b/lua/space-age/run-tests-lua.txt new file mode 100644 index 00000000..b0ae1bd8 --- /dev/null +++ b/lua/space-age/run-tests-lua.txt @@ -0,0 +1,103 @@ +Running automated test file(s): + + +=============================================================================== + +Running: luacheck --no-color ./space-age.lua +Checking space-age.lua OK + +Total: 0 warnings / 0 errors in 1 file + +real 0m0.026s +user 0m0.018s +sys 0m0.008s + +=============================================================================== + +Running: busted --coverage --lpath= --cpath= --output=gtest -Xoutput --plain +[==========] Running tests from scanned files. +[----------] Global test environment setup. +[----------] Running tests from ./space-age_spec.lua +[ RUN ] ./space-age_spec.lua @ 4: space-age age in seconds +[ OK ] ./space-age_spec.lua @ 4: space-age age in seconds (0.83 ms) +[ RUN ] ./space-age_spec.lua @ 9: space-age age in Earth years +[ OK ] ./space-age_spec.lua @ 9: space-age age in Earth years (0.62 ms) +[ RUN ] ./space-age_spec.lua @ 14: space-age age in Mercury years +[ OK ] ./space-age_spec.lua @ 14: space-age age in Mercury years (0.92 ms) +[ RUN ] ./space-age_spec.lua @ 20: space-age age in Venus years +[ OK ] ./space-age_spec.lua @ 20: space-age age in Venus years (1.00 ms) +[ RUN ] ./space-age_spec.lua @ 26: space-age age in Mars years +[ OK ] ./space-age_spec.lua @ 26: space-age age in Mars years (0.81 ms) +[ RUN ] ./space-age_spec.lua @ 32: space-age age in Jupiter years +[ OK ] ./space-age_spec.lua @ 32: space-age age in Jupiter years (0.97 ms) +[ RUN ] ./space-age_spec.lua @ 38: space-age age in Saturn years +[ OK ] ./space-age_spec.lua @ 38: space-age age in Saturn years (0.82 ms) +[ RUN ] ./space-age_spec.lua @ 44: space-age age in Uranus years +[ OK ] ./space-age_spec.lua @ 44: space-age age in Uranus years (0.93 ms) +[ RUN ] ./space-age_spec.lua @ 50: space-age age in Neptune year +[ OK ] ./space-age_spec.lua @ 50: space-age age in Neptune year (0.82 ms) +[----------] 9 tests from ./space-age_spec.lua (28.57 ms total) + +[----------] Global test environment teardown. +[==========] 9 tests from 1 test file ran. (30.08 ms total) +[ PASSED ] 9 tests. + +real 0m0.059s +user 0m0.053s +sys 0m0.006s + +=============================================================================== + +Running: luacov . + +real 0m0.071s +user 0m0.066s +sys 0m0.005s + +=============================================================================== + +Running: luacov-console . + +real 0m0.016s +user 0m0.012s +sys 0m0.005s + +Running: luacov-console --no-colored --summary . +============================================================================== +Summary +============================================================================== + +File Hits Missed Coverage +--------------------------------------- +space-age.lua 32 0 100.00% +space-age_spec.lua 36 0 100.00% +--------------------------------------- +Total 68 0 100.00% + +real 0m0.013s +user 0m0.006s +sys 0m0.006s + +=============================================================================== + +Running: stylua ./space-age.lua ./space-age_spec.lua + +real 0m0.009s +user 0m0.009s +sys 0m0.005s + +=============================================================================== + +Running: misspell . +luacov.report.out:81:39: "retreive" is a misspelling of "retrieve" +space-age.lua:19:31: "retreive" is a misspelling of "retrieve" + +real 0m0.025s +user 0m0.019s +sys 0m0.019s + +=============================================================================== + + +=============================================================================== + diff --git a/lua/space-age/space-age.lua b/lua/space-age/space-age.lua new file mode 100644 index 00000000..c2ed20e7 --- /dev/null +++ b/lua/space-age/space-age.lua @@ -0,0 +1,57 @@ +local SpaceAge = {} +SpaceAge.__index = SpaceAge + +function SpaceAge:new(seconds) + local orbital_periods = { + Mercury = 0.2408467, + Venus = 0.61519726, + Earth = 1.0, + Mars = 1.8808158, + Jupiter = 11.862615, + Saturn = 29.447498, + Uranus = 84.016846, + Neptune = 164.79132, + } + + local seconds_in_earth_years = 365.25 * 24 * 60 * 60 + + return { + -- one of the tests wants to retreive the seconds + seconds = seconds, + + -- these have to be anonymous functions + on_mercury = function() + return tonumber(("%.2f"):format(seconds / (orbital_periods.Mercury * seconds_in_earth_years))) + end, + + on_venus = function() + return tonumber(("%.2f"):format(seconds / (orbital_periods.Venus * seconds_in_earth_years))) + end, + + on_earth = function() + return tonumber(("%.2f"):format(seconds / (orbital_periods.Earth * seconds_in_earth_years))) + end, + + on_mars = function() + return tonumber(("%.2f"):format(seconds / (orbital_periods.Mars * seconds_in_earth_years))) + end, + + on_jupiter = function() + return tonumber(("%.2f"):format(seconds / (orbital_periods.Jupiter * seconds_in_earth_years))) + end, + + on_saturn = function() + return tonumber(("%.2f"):format(seconds / (orbital_periods.Saturn * seconds_in_earth_years))) + end, + + on_uranus = function() + return tonumber(("%.2f"):format(seconds / (orbital_periods.Uranus * seconds_in_earth_years))) + end, + + on_neptune = function() + return tonumber(("%.2f"):format(seconds / (orbital_periods.Neptune * seconds_in_earth_years))) + end, + } +end + +return SpaceAge diff --git a/lua/space-age/space-age_spec.lua b/lua/space-age/space-age_spec.lua new file mode 100644 index 00000000..e662bae2 --- /dev/null +++ b/lua/space-age/space-age_spec.lua @@ -0,0 +1,55 @@ +local SpaceAge = require("space-age") + +describe("space-age", function() + it("age in seconds", function() + local age = SpaceAge:new(1000000) + assert.are.equal(1000000, age.seconds) + end) + + it("age in Earth years", function() + local age = SpaceAge:new(1000000000) + assert.are.equal(31.69, age.on_earth()) + end) + + it("age in Mercury years", function() + local age = SpaceAge:new(2134835688) + assert.are.equal(67.65, age.on_earth()) + assert.are.equal(280.88, age.on_mercury()) + end) + + it("age in Venus years", function() + local age = SpaceAge:new(189839836) + assert.are.equal(6.02, age.on_earth()) + assert.are.equal(9.78, age.on_venus()) + end) + + it("age in Mars years", function() + local age = SpaceAge:new(2329871239) + assert.are.equal(73.83, age.on_earth()) + assert.are.equal(39.25, age.on_mars()) + end) + + it("age in Jupiter years", function() + local age = SpaceAge:new(901876382) + assert.are.equal(28.58, age.on_earth()) + assert.are.equal(2.41, age.on_jupiter()) + end) + + it("age in Saturn years", function() + local age = SpaceAge:new(3000000000) + assert.are.equal(95.06, age.on_earth()) + assert.are.equal(3.23, age.on_saturn()) + end) + + it("age in Uranus years", function() + local age = SpaceAge:new(3210123456) + assert.are.equal(101.72, age.on_earth()) + assert.are.equal(1.21, age.on_uranus()) + end) + + it("age in Neptune year", function() + local age = SpaceAge:new(8210123456) + assert.are.equal(260.16, age.on_earth()) + assert.are.equal(1.58, age.on_neptune()) + end) +end)