for loop
function Exponentiation(x)
local product = 1
for i = 1, x do
product = product*x
end
return product
end
-- TODO: Replace examples and use TDD by writing your own tests
local solution = require 'solution'
describe("solution", function()
it("test for something", function()
assert.are.same(4, Exponentiation(2))
assert.are.same(256, Exponentiation(4))
assert.are.same(1, Exponentiation(0.5))
end)
end)
function bestCodeEver(a) return a == 19 and true or false end
def bestCodeEver():bestNumber = 19return bestNumber- function bestCodeEver(a)
- return a == 19 and true or false
- end
-- TODO: Replace examples and use TDD by writing your own tests local solution = require 'solution' describe("solution", function() it("test for something", function() assert.are.same(true, bestCodeEver(19)) assert.are.same(false, bestCodeEver(15)) end) end)
import codewars_test as test# TODO Write testsimport solution # or from solution import example# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")def test_group():@test.it("test case")def test_case():test.assert_equals(1 + 1, 2)- -- TODO: Replace examples and use TDD by writing your own tests
- local solution = require 'solution'
- describe("solution", function()
- it("test for something", function()
- assert.are.same(true, bestCodeEver(19))
- assert.are.same(false, bestCodeEver(15))
- end)
- end)
Return a+b where a,b are the inputs to the function
function sum_of_numbers(a, b) if a == b then return a + a or b + b else return math.sqrt(b^2) + math.sqrt(a^2) end end
- function sum_of_numbers(a, b)
return b + aend- if a == b then
- return a + a or b + b
- else
- return math.sqrt(b^2) + math.sqrt(a^2)
- end
- end
-- TODO: Replace examples and use TDD by writing your own tests local solution = require 'solution' describe("solution", function() it("test for something", function() assert.are.same(2, sum_of_numbers(1,1)) assert.are.same(56, sum_of_numbers(33,23)) assert.are.same(403, sum_of_numbers(380,23)) end) end)
- -- TODO: Replace examples and use TDD by writing your own tests
- local solution = require 'solution'
- describe("solution", function()
- it("test for something", function()
- assert.are.same(2, sum_of_numbers(1,1))
- assert.are.same(56, sum_of_numbers(33,23))
- assert.are.same(403, sum_of_numbers(380,23))
- end)
- end)
function sum_of_numbers(a, b) return b + a end
def sum_of_numbers(a, b):return b + a- function sum_of_numbers(a, b)
- return b + a
- end
-- TODO: Replace examples and use TDD by writing your own tests local solution = require 'solution' describe("solution", function() it("test for something", function() assert.are.same(2, sum_of_numbers(1,1)) end) end)
import codewars_test as test# TODO Write testsimport solution # or from solution import example# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")def test_group():@test.it("test case")def test_case():test.assert_equals(1 + 1, 2)- -- TODO: Replace examples and use TDD by writing your own tests
- local solution = require 'solution'
- describe("solution", function()
- it("test for something", function()
- assert.are.same(2, sum_of_numbers(1,1))
- end)
- end)