Skip to content

Instantly share code, notes, and snippets.

View deepal's full-sized avatar

Deepal Jayasekara deepal

  • CompareTheMarket.com
  • London, United Kingdom
View GitHub Profile
version: '3.4'
services:
test:
image: imega/busted
environment:
- LUA_PATH=/app/?.lua
command: busted /app
volumes:
- ./lib:/app/lib
describe("app module", function ()
describe("run() function", function ()
local check_env_stub = stub()
setup(function ()
package.preload["lib.check_env"] = function ()
return check_env_stub
end
end)
local check_env = require "lib.check_env"
local sum = require "lib.sum"
local app = {}
app.run = function ()
if check_env() == true then
return string.format("Result of 10 + 20 is %s", sum(10, 20))
else
return nil
describe("check_env module", function ()
local check_env = require "lib.check_env"
before_each(function()
stub(os, "getenv")
end)
after_each(function ()
os.getenv:revert()
end)
return function ()
if os.getenv("RUN_SUM") == "1" then
return true
else
return false
end
end
describe("sum module", function ()
it("should return the sum of two numbers", function ()
local sum = require "lib.sum"
local result = sum(100, 200)
assert.are.same(300, result)
end)
end)
return function (a, b)
return a + b
end
@deepal
deepal / mon.js
Last active March 15, 2022 20:40
setFakeTime();
const startTimeMon = performance.now(); // set startTime with monotonic clock
setImmediate(() => {
correctTimeNTP(); // synchronise the clock
});
await doSomething();
const endTimeMon = performance.now(); // set endTime with monotonic clock
@deepal
deepal / tod.js
Last active March 11, 2022 20:59
setFakeTime(); // set time to 1 min ahead of actual time
const startTimeToD = Date.now(); // set startTime with time-of-day clock
setImmediate(() => {
correctTimeNTP(); // synchronise the clock
});
await doSomething();
const start = Date.now()
doSomething()
const end = Date.now()
const durationMs = end - start;