Skip to content

Instantly share code, notes, and snippets.

@TheEpicFace007
Last active October 20, 2021 01:42
Show Gist options
  • Save TheEpicFace007/533e2cf9bcade846570b1651a206f8ae to your computer and use it in GitHub Desktop.
Save TheEpicFace007/533e2cf9bcade846570b1651a206f8ae to your computer and use it in GitHub Desktop.
rocha
local gameLogicRoot = script.Parent.Parent
local gameLogicApi = require(gameLogicRoot.gameLogicApi)
local modules = game.ReplicatedStorage.modules
local TestingLib = require(modules.TestFramework)
local RUN_TEST = true
if not RUN_TEST then
return
end
TestingLib.describe(1, "brick handling functions")
local normalBrick = gameLogicApi.createBrick(BrickColor.White(), BrickColor.Gray(),
"normal"
)
local wideBrick = gameLogicApi.createBrick(BrickColor.White(), BrickColor.Gray(),
"wide"
)
TestingLib.it(normalBrick.brickType == "normal", "normalBrick type should be normal")
TestingLib.it(TestingLib.isEqual(normalBrick:getPrimaryColor(), BrickColor.White()), "Primary color of normalBrick should be white")
TestingLib.it((function ()
local brickColor = BrickColor.new(Color3.fromHSV(0.0693333, 1, 1))
normalBrick:setSecondaryColor(brickColor)
return TestingLib.isEqual(normalBrick:getSecondaryColor(), brickColor)
end)(), "change normalBrickColor secondary brickColor. Verifying the info by using getSecondaryColor")
TestingLib.it(TestingLib.doesNotThrow(normalBrick.setBrickTransparency, normalBrick, 0.5),
"should be able to change the opacity without getting any error"
)
TestingLib.it(TestingLib.doesThrow(function ()
normalBrick.unexpected_property = "69 xd"
end), "it should throw a error when adding an unknown property")
TestingLib.describe(2, "Bouger la raquette ")
TestingLib.it(TestingLib.doesNotThrow(gameLogicApi.deplaceRaquette, "<", 12), "c'est supposer de bouger la raquette sans érreur")
TestingLib.describe(3, "Position class")
local pos = gameLogicApi.createPosition(21, 0)
local pos2 = gameLogicApi.createPosition(21, 1)
TestingLib.it(TestingLib.isNotEqual(pos == pos2), "testing __equal metamethod")
TestingLib.it(TestingLib.isEqual(gameLogicApi.createPosition(0, 5) + gameLogicApi.createPosition(10, 15)) == gameLogicApi.createPosition(10, 20),
"__add metamethod"
)
Copyright © 2021 ViniDalvino
This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
local TestService = game:GetService("TestService")
local module = {}
function module.isEqual<T>(value: T, expected: T)
return value == expected
end
function module.isNotEqual<T>(value: T, expected: T)
return value ~= expected
end
function module.doesNotThrow(func, ...)
local args = {...}
local succ = pcall(func, table.unpack(args))
return succ
end
function module.doesThrow(value, ...)
local args = {...}
local succ = pcall(value, table.unpack(args))
return not succ
end
function module.describe(idx, desc)
TestService:Message(idx .. ")" .. " " .. desc)
end
--- @Param {string} condition Something to return false to then make an error
function module.it(condition, stepName)
warn("\t> ".. stepName)
local errorMsg = "\t\tfailed the test `%s' ❌"
local succMsg = "\t\tPassed the test `%s' ✅"
if not condition then
print(errorMsg:format(stepName), "\n\t\t" .. debug.traceback())
else
print(succMsg:format((stepName)))
end
end
return module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment