You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
761 B
JavaScript
41 lines
761 B
JavaScript
"use strict"
|
|
|
|
const assert = require("assert")
|
|
const { sum } = require("./sum.cjs")
|
|
|
|
function testSumResult() {
|
|
const a = 1
|
|
const b = 2
|
|
const result = sum(a, b)
|
|
assert(result === a + b, "the result should be the sum of its arguments")
|
|
}
|
|
|
|
function testSumNoArgs() {
|
|
try {
|
|
sum()
|
|
} catch (_) {
|
|
return
|
|
}
|
|
assert.fail("should fail if not provided any arguments")
|
|
}
|
|
|
|
function testSumMissingArg() {
|
|
const a = 1
|
|
try {
|
|
sum(a)
|
|
} catch (_) {
|
|
return
|
|
}
|
|
assert.fail("should fail if not provided all arguments")
|
|
}
|
|
|
|
function testWillFail() {
|
|
assert.fail("I have failed!")
|
|
}
|
|
|
|
module.exports = {
|
|
testSumResult,
|
|
testSumNoArgs,
|
|
testSumMissingArg,
|
|
testWillFail,
|
|
} |