From 5f066cfcc494e45fe38b67489afe67d47b26a91e Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Tue, 12 Dec 2023 21:00:28 -0800 Subject: [PATCH] lua/space-age: 1st iteration --- lua/README.md | 1 + lua/space-age/README.md | 7 +- lua/space-age/luacov.report.out | 130 ++++++++++++++++++++++++++ lua/space-age/luacov.report.out.index | 3 + lua/space-age/luacov.stats.out | 66 +++++++++++++ lua/space-age/run-tests-lua.txt | 105 +++++++++++++++++++++ lua/space-age/space-age.lua | 54 +++++++++++ lua/space-age/space-age_spec.lua | 108 ++++++++++----------- 8 files changed, 419 insertions(+), 55 deletions(-) create mode 100644 lua/space-age/luacov.report.out create mode 100644 lua/space-age/luacov.report.out.index create mode 100644 lua/space-age/luacov.stats.out create mode 100644 lua/space-age/run-tests-lua.txt 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/README.md b/lua/space-age/README.md index 3370c6c6..13e6cbb3 100644 --- a/lua/space-age/README.md +++ b/lua/space-age/README.md @@ -43,4 +43,9 @@ See [Year on Wikipedia][year] for more ways to measure a year. ### Based on -Partially inspired by Chapter 1 in Chris Pine's online Learn to Program tutorial. - https://pine.fm/LearnToProgram/?Chapter=01 \ No newline at end of file +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..088a3395 --- /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 7 7 0 7 1071 0 1071 1078 0 7 63 63 1134 1071 1008 0 0 70 0 0 0 0 0 0 7 0 7 189 0 189 126 126 0 0 0 0 189 21 0 189 189 168 0 0 21 21 0 0 0 0 0 0 21 0 21 7 0 7 210 0 210 126 126 0 0 0 0 210 0 210 210 0 0 0 0 0 210 7 0 7 231 231 0 231 231 0 0 0 0 0 0 231 126 0 0 0 231 7 0 7 63 7 0 7 21 21 21 0 28 0 7 21 7 0 7 21 7 0 7 14 0 14 14 14 0 0 0 0 14 0 14 14 0 14 0 0 0 0 14 14 0 0 14 14 0 21 0 7 +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 5 5 +124:/usr/share/lua/5.1/busted/context.lua +0 0 0 7 294 287 0 7 7 7 7 7 0 0 0 7 294 287 0 623 616 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 77 7 70 0 70 0 0 77 77 0 0 77 77 0 0 77 7 0 77 0 0 1407 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 77 77 77 0 0 28 0 0 0 4896 0 0 0 322 322 322 322 322 0 0 322 322 322 322 322 +315:/usr/share/lua/5.1/busted/core.lua +0 0 0 0 0 0 0 0 0 0 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37 37 21 16 0 0 16 0 0 0 58 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 107 107 0 107 107 170 128 63 63 0 0 107 107 0 107 107 0 0 0 37 37 37 37 0 37 37 0 0 0 0 0 37 0 0 0 289 0 0 0 245 0 0 0 0 0 0 0 144 0 218 218 7 7 7 7 7 7 0 0 211 137 137 137 137 137 0 0 74 0 0 0 0 0 0 21 21 21 21 21 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 7 0 7 0 0 322 322 322 0 644 37 37 37 681 0 322 37 0 0 0 37 0 0 0 0 0 0 0 0 0 0 0 37 0 322 0 322 322 0 0 0 168 168 168 84 84 84 84 84 84 0 336 168 336 168 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 0 0 0 0 77 0 77 77 70 0 0 0 77 154 0 77 77 0 0 0 0 0 0 77 77 77 77 77 77 77 77 77 77 77 77 0 0 77 0 77 21 0 56 0 77 0 0 0 21 98 77 77 154 77 0 21 +31:/usr/share/lua/5.1/busted/environment.lua +0 0 0 0 0 0 0 4592 0 4585 3423 4585 0 0 0 0 0 0 0 0 1169 0 0 0 0 0 0 0 0 0 7 +72:/usr/share/lua/5.1/busted/execute.lua +7 7 7 0 0 0 0 0 0 0 0 0 7 0 0 7 0 0 7 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 14 7 0 0 0 0 0 7 0 7 0 0 0 0 7 7 7 7 0 7 7 0 7 0 7 0 0 0 14 0 7 7 +127:/usr/share/lua/5.1/busted/init.lua +0 0 0 0 7 7 7 0 7 7 0 0 7 7 7 0 7 7 0 0 63 63 0 63 0 0 0 0 63 0 63 63 63 0 63 0 63 63 63 63 63 0 0 0 0 0 0 63 0 0 63 63 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 525 +50:/usr/share/lua/5.1/busted/languages/en.lua +7 0 7 0 0 7 7 7 7 0 7 7 7 7 0 7 7 7 7 0 7 7 7 7 0 7 0 7 7 0 0 7 7 7 7 7 7 7 7 7 0 7 7 7 7 7 7 0 7 7 +23:/usr/share/lua/5.1/busted/modules/files/lua.lua +7 0 7 0 0 107 107 107 7 0 0 7 7 0 0 7 7 0 0 7 7 0 7 +107:/usr/share/lua/5.1/busted/modules/files/moonscript.lua +7 0 14 7 7 0 7 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 7 0 0 0 0 0 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 0 7 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 7 0 0 0 0 0 0 0 7 0 7 +129:/usr/share/lua/5.1/busted/modules/filter_loader.lua +0 0 0 63 63 0 126 126 63 63 0 0 63 7 0 0 0 0 7 0 0 70 0 0 0 0 70 7 0 0 63 63 0 0 0 0 63 7 0 0 70 0 0 0 0 70 7 0 0 63 0 0 0 0 63 7 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 7 0 7 0 0 0 0 0 0 7 0 0 0 7 0 0 56 98 70 0 0 63 0 0 0 0 0 0 0 0 7 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 7 7 7 0 0 7 7 7 7 7 +34:/usr/share/lua/5.1/busted/modules/output_handler_loader.lua +0 0 0 0 0 0 0 0 7 14 7 0 7 0 0 7 0 14 0 7 0 0 0 7 0 0 0 0 7 0 0 0 7 7 +101:/usr/share/lua/5.1/busted/modules/test_file_loader.lua +7 0 0 7 7 7 7 0 21 14 14 0 0 0 0 0 7 0 7 7 7 0 14 79 79 0 0 0 0 151 79 7 0 0 72 14 0 14 7 0 0 7 0 14 0 0 0 0 0 7 7 7 0 0 7 14 7 0 7 7 0 0 0 7 7 7 0 0 7 0 0 7 0 14 7 0 7 14 7 7 7 7 0 0 7 0 0 0 7 0 0 0 0 0 0 0 7 7 0 7 7 +179:/usr/share/lua/5.1/busted/outputHandlers/base.lua +0 7 7 7 7 7 7 7 7 7 7 7 0 0 0 252 7 0 0 7 7 0 7 0 0 0 7 7 7 7 7 7 7 7 7 7 14 0 0 189 189 0 378 378 0 189 189 0 0 189 7 0 0 0 63 645 582 456 0 0 63 63 0 63 63 63 63 63 63 63 0 63 0 63 7 0 0 0 0 0 0 0 7 0 0 7 7 7 7 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0 7 7 7 7 0 0 63 63 7 0 0 0 0 63 26 26 37 0 0 37 0 21 21 16 0 16 16 0 0 26 0 26 26 26 0 0 0 26 0 0 26 0 26 7 0 0 0 0 0 0 7 0 0 21 21 7 0 0 16 16 16 7 0 0 37 0 0 0 0 37 7 0 7 7 +286:/usr/share/lua/5.1/busted/outputHandlers/gtest.lua +7 7 7 7 0 7 0 7 7 0 7 1251 0 0 0 0 0 7 7 0 7 7 7 7 7 7 7 7 7 7 7 7 7 7 0 7 7 7 7 7 7 0 7 7 7 7 7 0 7 7 7 7 7 0 0 7 7 7 7 7 7 7 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0 37 37 37 0 0 0 0 0 0 37 0 37 0 0 0 37 7 0 0 163 163 163 163 0 163 7 0 0 21 21 21 7 7 7 0 7 7 44 37 37 37 0 0 0 0 0 21 7 0 0 21 21 21 7 7 7 0 21 7 0 0 7 7 0 7 7 7 0 7 7 7 7 0 7 7 0 0 126 7 0 0 0 0 0 0 0 0 0 0 0 7 0 0 7 0 0 7 0 0 7 7 7 0 7 7 0 0 7 7 7 7 7 7 7 0 7 7 0 0 7 7 7 7 7 0 0 7 7 7 7 7 7 7 0 0 63 63 0 63 7 0 0 63 63 0 63 63 63 26 26 37 0 0 37 21 21 16 16 16 0 0 63 63 0 63 7 0 0 21 21 21 0 21 7 0 0 16 16 16 0 16 7 0 0 37 0 0 0 0 0 0 0 37 7 0 7 7 7 7 7 7 7 7 7 7 7 0 7 7 +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 7 0 0 0 0 0 0 7 0 0 0 0 7 0 0 0 0 0 7 7 0 0 7 7 0 0 0 7 7 0 0 0 0 0 7 7 7 0 14 0 0 7 0 14 0 0 7 0 14 16 16 16 7 0 14 21 21 0 0 0 21 21 7 0 0 7 7 7 0 0 14 7 7 7 7 7 7 7 0 0 0 7 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 14 7 7 7 7 7 7 7 0 0 7 0 7 7 7 14 7 7 7 7 0 0 0 0 0 0 7 7 14 7 7 7 0 0 7 0 7 5 0 2 +42:/usr/share/lua/5.1/busted/status.lua +0 448 448 448 448 448 448 448 448 0 448 0 0 0 385 385 567 385 385 385 0 0 0 385 0 0 0 385 0 0 0 63 63 63 0 448 0 0 770 385 511 385 +35:/usr/share/lua/5.1/busted/utils.lua +0 0 0 7 7 21 14 14 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 7 7 7 7 35 28 0 7 +177:/usr/share/lua/5.1/luassert/assert.lua +0 0 0 0 0 0 0 0 0 0 0 21 0 21 0 0 21 21 0 0 21 0 0 0 0 0 68 0 68 0 204 136 0 0 68 204 136 68 0 0 0 68 68 68 0 68 21 21 0 0 21 21 0 0 47 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 336 168 0 0 168 0 0 0 0 84 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 21 63 42 42 42 42 42 0 0 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 68 0 0 0 68 0 0 0 84 +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 68 0 0 68 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 68 68 68 68 0 68 68 68 +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 37 0 0 0 37 0 37 0 37 0 0 0 37 0 37 0 0 0 0 0 37 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21 0 0 0 0 0 0 0 0 89 89 89 89 178 89 89 89 0 89 89 0 0 0 0 0 0 0 0 68 0 0 68 68 68 204 136 136 0 0 136 136 0 0 0 0 0 0 136 136 136 0 136 0 0 0 68 0 0 0 68 +154:/usr/share/lua/5.1/mediator.lua +0 245 0 0 0 245 245 245 245 0 0 0 0 0 245 0 245 245 0 0 0 0 0 147 147 147 147 147 147 0 0 245 245 0 245 0 245 140 140 0 133 0 0 245 0 245 147 0 0 0 0 0 0 0 0 0 0 0 0 147 0 0 0 0 0 0 0 0 147 0 0 147 147 147 0 0 0 147 0 0 1012 147 0 0 0 0 0 0 0 0 0 0 0 147 0 0 1451 822 0 0 822 0 822 0 822 822 0 0 0 629 417 0 212 0 147 147 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 534 0 1546 1012 0 0 534 0 0 0 245 0 0 0 0 0 0 0 0 0 0 0 289 +476:/usr/share/lua/5.1/pl/dir.lua +0 0 0 0 0 0 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 0 7 0 0 7 14 0 0 0 7 0 0 79 79 7 0 0 0 0 0 0 0 7 0 0 0 7 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 7 0 0 7 0 0 0 0 0 0 0 0 7 0 0 7 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 7 0 0 0 0 7 0 0 0 0 0 0 7 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 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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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1021 0 0 1021 0 0 1021 0 0 0 0 0 0 993 993 +48:/usr/share/lua/5.1/say/init.lua +0 0 0 0 0 0 0 0 0 0 0 0 0 7 7 0 0 7 0 0 0 0 0 0 0 0 0 133 133 0 0 0 0 89 0 89 0 89 0 0 89 89 0 335 246 0 0 89 +57:space-age.lua +7 7 1 7 55 55 55 55 55 54 54 55 54 1 1 54 1 63 36 37 53 28 37 46 37 52 27 27 20 36 4 18 29 1 10 19 10 10 18 2 19 18 19 12 18 3 0 2 9 0 0 1 9 9 1 0 1 +55:space-age_spec.lua +7 0 14 14 7 7 9 0 14 7 7 10 0 14 7 7 3 10 0 14 7 7 3 10 0 14 7 7 3 10 0 14 7 7 3 10 0 14 7 7 3 10 0 14 7 7 3 10 0 14 7 7 3 10 21 diff --git a/lua/space-age/run-tests-lua.txt b/lua/space-age/run-tests-lua.txt new file mode 100644 index 00000000..0484fc46 --- /dev/null +++ b/lua/space-age/run-tests-lua.txt @@ -0,0 +1,105 @@ +Running automated test file(s): + + +=============================================================================== + +Running: luacheck --no-color ./space-age.lua +Checking space-age.lua 1 warning + + space-age.lua:4:18: unused argument 'self' + +Total: 1 warning / 0 errors in 1 file + +real 0m0.050s +user 0m0.030s +sys 0m0.019s + +=============================================================================== + +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.97 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.63 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.73 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 (0.99 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.80 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 (1.01 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.95 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 (1.07 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.70 ms) +[----------] 9 tests from ./space-age_spec.lua (29.12 ms total) + +[----------] Global test environment teardown. +[==========] 9 tests from 1 test file ran. (30.58 ms total) +[ PASSED ] 9 tests. + +real 0m0.057s +user 0m0.051s +sys 0m0.006s + +=============================================================================== + +Running: luacov . + +real 0m0.110s +user 0m0.099s +sys 0m0.010s + +=============================================================================== + +Running: luacov-console . + +real 0m0.018s +user 0m0.012s +sys 0m0.006s + +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.012s +user 0m0.009s +sys 0m0.004s + +=============================================================================== + +Running: stylua ./space-age.lua ./space-age_spec.lua + +real 0m0.011s +user 0m0.011s +sys 0m0.003s + +=============================================================================== + +Running: misspell . +space-age.lua:19:31: "retreive" is a misspelling of "retrieve" +luacov.report.out:81:39: "retreive" is a misspelling of "retrieve" + +real 0m0.022s +user 0m0.022s +sys 0m0.015s + +=============================================================================== + + +=============================================================================== + diff --git a/lua/space-age/space-age.lua b/lua/space-age/space-age.lua index 645586cf..c2ed20e7 100644 --- a/lua/space-age/space-age.lua +++ b/lua/space-age/space-age.lua @@ -1,3 +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 index 1a324556..e662bae2 100644 --- a/lua/space-age/space-age_spec.lua +++ b/lua/space-age/space-age_spec.lua @@ -1,55 +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) +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)