UNPKG

@academyjs/rover

Version:

Rover allows you to learn programming interactively.

53 lines (52 loc) 2.64 kB
"use strict"; /** * Copyright (c) AcademyJS and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const import_locals_1 = __importDefault(require("import-locals")); const assertions_1 = require("../../assertions"); suite({ title: "Calculate the factorial of a given integer.", handle: "node/factorial", description: `Factorial of a non-negative integer, is multiplication of all integers smaller than or equal to n. For example factorial of 6 is 6 * 5 * 4 * 3 * 2 * 1 which is 720. Factorial can be calculated iteratively or recursively. You can solve using any approach.`, tags: ["node", "javascript", "js", "factorial"], }); test("Write the program in 'factorial.js'", "This is a huge description.", () => __awaiter(void 0, void 0, void 0, function* () { yield (0, assertions_1.fileExists)("factorial.js", "Cannot find file `factorial.js`"); })); let factorial = null; let temporary = null; beforeEach(() => { import_locals_1.default.export(process.cwd() + "/factorial.js", "factorial"); factorial = require(process.cwd() + "/factorial.js").factorial; temporary = process.stdout.write; }); afterEach(() => { import_locals_1.default.unexport(process.cwd() + "/factorial.js", "factorial"); }); test("Calculate the factorial of 5", "This is a huge description.", () => { const actual = factorial(5); (0, assertions_1.strictEqual)(actual, 120, "factorial(5) should return 120"); }); test("Calculate the factorial of 6", "This is a huge description.", () => { const actual = factorial(6); (0, assertions_1.strictEqual)(actual, 720, "factorial(6) should return 720"); }); //# sourceMappingURL=factorial.js.map