// warning: This file is auto generated by `yarn build:tests` // Do not edit by hand! import { createRequire } from 'node:module' import { describe, it, expect } from 'vitest' process.env.TZ = 'UTC' const __locutus_source_fn = require('../../../../src/python/math/comb.ts').comb const __locutus_source_module_url = new URL("../../../../src/python/math/comb.ts", import.meta.url) const __locutus_source_require = createRequire(__locutus_source_module_url) const __locutus_func_name = "comb" const __locutus_module_js_code = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.comb = comb;\nfunction comb(n, k) {\n // discuss at: https://locutus.io/python/comb/\n // parity verified: Python 3.12\n // original by: Kevin van Zonneveld (https://kvz.io)\n // note 1: Returns the number of ways to choose k items from n without repetition.\n // example 1: comb(5, 2)\n // returns 1: 10\n // example 2: comb(10, 0)\n // returns 2: 1\n // example 3: comb(10, 3)\n // returns 3: 120\n const nn = Math.trunc(Number(n));\n const kk = Math.trunc(Number(k));\n if (!Number.isFinite(nn) || !Number.isFinite(kk) || nn < 0 || kk < 0) {\n throw new Error('comb() only accepts non-negative integers');\n }\n if (kk > nn) {\n return 0;\n }\n const r = Math.min(kk, nn - kk);\n let result = 1;\n for (let i = 1; i <= r; i += 1) {\n result = (result * (nn - r + i)) / i;\n }\n return Math.trunc(result);\n}" const __locutus_standalone_ts_code = "// python/math/comb (target function module)\nfunction comb(n, k) {\n // discuss at: https://locutus.io/python/comb/\n // parity verified: Python 3.12\n // original by: Kevin van Zonneveld (https://kvz.io)\n // note 1: Returns the number of ways to choose k items from n without repetition.\n // example 1: comb(5, 2)\n // returns 1: 10\n // example 2: comb(10, 0)\n // returns 2: 1\n // example 3: comb(10, 3)\n // returns 3: 120\n const nn = Math.trunc(Number(n));\n const kk = Math.trunc(Number(k));\n if (!Number.isFinite(nn) || !Number.isFinite(kk) || nn < 0 || kk < 0) {\n throw new Error('comb() only accepts non-negative integers');\n }\n if (kk > nn) {\n return 0;\n }\n const r = Math.min(kk, nn - kk);\n let result = 1;\n for (let i = 1; i <= r; i += 1) {\n result = (result * (nn - r + i)) / i;\n }\n return Math.trunc(result);\n}" const __locutus_standalone_js_code = "// python/math/comb (target function module)\nfunction comb(n, k) {\n // discuss at: https://locutus.io/python/comb/\n // parity verified: Python 3.12\n // original by: Kevin van Zonneveld (https://kvz.io)\n // note 1: Returns the number of ways to choose k items from n without repetition.\n // example 1: comb(5, 2)\n // returns 1: 10\n // example 2: comb(10, 0)\n // returns 2: 1\n // example 3: comb(10, 3)\n // returns 3: 120\n const nn = Math.trunc(Number(n));\n const kk = Math.trunc(Number(k));\n if (!Number.isFinite(nn) || !Number.isFinite(kk) || nn < 0 || kk < 0) {\n throw new Error('comb() only accepts non-negative integers');\n }\n if (kk > nn) {\n return 0;\n }\n const r = Math.min(kk, nn - kk);\n let result = 1;\n for (let i = 1; i <= r; i += 1) {\n result = (result * (nn - r + i)) / i;\n }\n return Math.trunc(result);\n}" const __locutus_eval_function = (compiledCode: string): ((...args: unknown[]) => unknown) => { const evaluator = new Function('require', compiledCode + '\nreturn ' + __locutus_func_name + ';') return evaluator(__locutus_source_require) as (...args: unknown[]) => unknown } const __locutus_eval_module_export = (compiledCode: string, exportName: string): ((...args: unknown[]) => unknown) => { const module = { exports: {} as { [key: string]: unknown } } const exports = module.exports const evaluator = new Function('exports', 'module', 'require', compiledCode) evaluator(exports, module, __locutus_source_require) return module.exports[exportName] as (...args: unknown[]) => unknown } const __locutus_module_js_fn = __locutus_eval_module_export(__locutus_module_js_code, __locutus_func_name) const __locutus_standalone_ts_fn = __locutus_eval_function(__locutus_standalone_ts_code) const __locutus_standalone_js_fn = __locutus_eval_function(__locutus_standalone_js_code) describe('src/python/math/comb.ts (tested in test/generated/python/math/comb.vitest.ts)', function () { it('should pass example 1', function () { const expected = 10 const __locutus_variants: Array<{ name: string; fn: (...args: unknown[]) => unknown }> = [ { name: "source", fn: __locutus_source_fn }, { name: "module-js", fn: __locutus_module_js_fn }, { name: "standalone-ts", fn: __locutus_standalone_ts_fn }, { name: "standalone-js", fn: __locutus_standalone_js_fn }, ] const __locutus_run_example = (comb: typeof __locutus_source_fn) => { return comb(5, 2) } for (const __locutus_variant of __locutus_variants) { const result = __locutus_run_example(__locutus_variant.fn as typeof __locutus_source_fn) expect(result).toEqual(expected) } }) it('should pass example 2', function () { const expected = 1 const __locutus_variants: Array<{ name: string; fn: (...args: unknown[]) => unknown }> = [ { name: "source", fn: __locutus_source_fn }, { name: "module-js", fn: __locutus_module_js_fn }, { name: "standalone-ts", fn: __locutus_standalone_ts_fn }, { name: "standalone-js", fn: __locutus_standalone_js_fn }, ] const __locutus_run_example = (comb: typeof __locutus_source_fn) => { return comb(10, 0) } for (const __locutus_variant of __locutus_variants) { const result = __locutus_run_example(__locutus_variant.fn as typeof __locutus_source_fn) expect(result).toEqual(expected) } }) it('should pass example 3', function () { const expected = 120 const __locutus_variants: Array<{ name: string; fn: (...args: unknown[]) => unknown }> = [ { name: "source", fn: __locutus_source_fn }, { name: "module-js", fn: __locutus_module_js_fn }, { name: "standalone-ts", fn: __locutus_standalone_ts_fn }, { name: "standalone-js", fn: __locutus_standalone_js_fn }, ] const __locutus_run_example = (comb: typeof __locutus_source_fn) => { return comb(10, 3) } for (const __locutus_variant of __locutus_variants) { const result = __locutus_run_example(__locutus_variant.fn as typeof __locutus_source_fn) expect(result).toEqual(expected) } }) })