← IaC Academy

Lua and tests · 20 / 23

Choose a profile and multiple suites

Use pure computation tests and give edge cases their own suite.

YOUR TASK

Make this happen

3 steps
  1. Keep both test files in the content.test list.

  2. Use content.test.profile = "pure" for this computation-only function.

  3. Fix the zero-quantity expectation and run all suites.

Read the starter files

main.cococo

script "pricing" {
  name = "academy-pricing"
  role = "SCRIPT"
  content.test = [file("tests/pricing.test.lua"), file("tests/zero.test.lua")]
  content.test.profile = "pure"
  content = file("scripts/pricing.lua")
}

scripts/pricing.lua

exports.quote = function(quantity: number, unitPrice: number): number
  return quantity * unitPrice
end

tests/pricing.test.lua

local t = require("test")
local subject = require("cococo.subject")

t.it("calculates a quote", function()
  local pricing = subject.load()
  t.expect(pricing.quote(4, 12)):eq(48)
end)

tests/zero.test.lua

local t = require("test")
local subject = require("cococo.subject")

t.it("zero quantity", function()
  local pricing = subject.load()
  t.expect(pricing.quote(0, 12)):eq(12)
end)