// 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/bisect/bisect_left.ts').bisect_left const __locutus_source_module_url = new URL("../../../../src/python/bisect/bisect_left.ts", import.meta.url) const __locutus_source_require = createRequire(__locutus_source_module_url) const __locutus_func_name = "bisect_left" const __locutus_module_js_code = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.bisect_left = bisect_left;\nconst _bisect_ts_1 = require(\"../_helpers/_bisect.ts\");\nfunction bisect_left(a, x, lo, hi) {\n // discuss at: https://locutus.io/python/bisect/bisect_left/\n // parity verified: Python 3.12\n // original by: Kevin van Zonneveld (https://kvz.io)\n // example 1: bisect_left([1, 2, 2, 4], 2)\n // returns 1: 1\n return (0, _bisect_ts_1.pythonBisectLeft)(a, x, lo, hi);\n}" const __locutus_standalone_ts_code = "function isNumericLike(value) {\n return typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint';\n}\nfunction toPythonNumber(value, functionName) {\n if (typeof value === 'number') {\n return value;\n }\n if (typeof value === 'boolean') {\n return value ? 1 : 0;\n }\n if (typeof value === 'bigint') {\n const numericValue = Number(value);\n if (!Number.isSafeInteger(numericValue)) {\n throw new RangeError(`${functionName}() bigint values must fit within JS safe integer precision`);\n }\n return numericValue;\n }\n throw new TypeError(`${functionName}() expected a numeric value`);\n}\nfunction toPythonInteger(value, functionName) {\n if (typeof value === 'boolean') {\n return value ? 1n : 0n;\n }\n if (typeof value === 'bigint') {\n return value;\n }\n if (typeof value === 'number' && Number.isFinite(value) && Number.isSafeInteger(value)) {\n return BigInt(value);\n }\n throw new TypeError(`${functionName}() expected an integer value`);\n}\nfunction pythonBisectLeft(sequence, item, lo, hi) {\n return bisectCore(sequence, item, lo, hi, 'bisect_left', 'left');\n}\nfunction bisectCore(sequence, item, lo, hi, functionName, side) {\n const values = toBisectSequence(sequence, functionName);\n let left = normalizeLo(lo, functionName);\n let right = normalizeHi(hi, values.length, functionName);\n while (left < right) {\n const middle = Math.floor((left + right) / 2);\n const candidate = getSequenceItem(values, middle);\n if (side === 'left' ? pythonLessThan(candidate, item, functionName) : !pythonLessThan(item, candidate, functionName)) {\n left = middle + 1;\n }\n else {\n right = middle;\n }\n }\n return left;\n}\nfunction toBisectSequence(sequence, functionName) {\n if (Array.isArray(sequence) || typeof sequence === 'string') {\n return sequence;\n }\n throw new TypeError(`${functionName}() expected an indexable sequence`);\n}\nfunction normalizeLo(value, functionName) {\n if (value === undefined) {\n return 0;\n }\n const index = toSequenceIndex(value, functionName);\n if (index < 0) {\n throw new RangeError('lo must be non-negative');\n }\n return index;\n}\nfunction normalizeHi(value, sequenceLength, functionName) {\n if (value === undefined || value === null) {\n return sequenceLength;\n }\n return toSequenceIndex(value, functionName);\n}\nfunction toSequenceIndex(value, functionName) {\n const index = Number(toPythonInteger(value, functionName));\n if (!Number.isSafeInteger(index)) {\n throw new RangeError(`${functionName}() index must fit within JS safe integer precision`);\n }\n return index;\n}\nfunction getSequenceItem(sequence, index) {\n if (index < 0 || index >= sequence.length) {\n throw new Error(Array.isArray(sequence) ? 'list index out of range' : 'string index out of range');\n }\n return sequence[index];\n}\nfunction pythonLessThan(left, right, functionName) {\n if (isNumericLike(left) && isNumericLike(right)) {\n const leftNumber = toPythonNumber(left, functionName);\n const rightNumber = toPythonNumber(right, functionName);\n if (Number.isNaN(leftNumber) || Number.isNaN(rightNumber)) {\n return false;\n }\n return leftNumber < rightNumber;\n }\n if (typeof left === 'string' && typeof right === 'string') {\n return left < right;\n }\n throw new TypeError(`'<' not supported between instances of '${pythonTypeName(left)}' and '${pythonTypeName(right)}'`);\n}\nfunction pythonTypeName(value) {\n if (typeof value === 'string') {\n return 'str';\n }\n if (typeof value === 'boolean') {\n return 'bool';\n }\n if (typeof value === 'bigint' || typeof value === 'number') {\n return 'int';\n }\n if (Array.isArray(value)) {\n return 'list';\n }\n if (value === null) {\n return 'NoneType';\n }\n if (value === undefined) {\n return 'undefined';\n }\n return typeof value;\n}\n// python/bisect/bisect_left (target function module)\nfunction bisect_left(a, x, lo, hi) {\n // discuss at: https://locutus.io/python/bisect/bisect_left/\n // parity verified: Python 3.12\n // original by: Kevin van Zonneveld (https://kvz.io)\n // example 1: bisect_left([1, 2, 2, 4], 2)\n // returns 1: 1\n return pythonBisectLeft(a, x, lo, hi);\n}" const __locutus_standalone_js_code = "// python/_helpers/_operator (Locutus helper dependency)\nfunction isNumericLike(value) {\n return typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint';\n}\nfunction toPythonNumber(value, functionName) {\n if (typeof value === 'number') {\n return value;\n }\n if (typeof value === 'boolean') {\n return value ? 1 : 0;\n }\n if (typeof value === 'bigint') {\n const numericValue = Number(value);\n if (!Number.isSafeInteger(numericValue)) {\n throw new RangeError(`${functionName}() bigint values must fit within JS safe integer precision`);\n }\n return numericValue;\n }\n throw new TypeError(`${functionName}() expected a numeric value`);\n}\nfunction toPythonInteger(value, functionName) {\n if (typeof value === 'boolean') {\n return value ? 1n : 0n;\n }\n if (typeof value === 'bigint') {\n return value;\n }\n if (typeof value === 'number' && Number.isFinite(value) && Number.isSafeInteger(value)) {\n return BigInt(value);\n }\n throw new TypeError(`${functionName}() expected an integer value`);\n}\n// python/_helpers/_bisect (Locutus helper dependency)\nfunction pythonBisectLeft(sequence, item, lo, hi) {\n return bisectCore(sequence, item, lo, hi, 'bisect_left', 'left');\n}\nfunction bisectCore(sequence, item, lo, hi, functionName, side) {\n const values = toBisectSequence(sequence, functionName);\n let left = normalizeLo(lo, functionName);\n let right = normalizeHi(hi, values.length, functionName);\n while (left < right) {\n const middle = Math.floor((left + right) / 2);\n const candidate = getSequenceItem(values, middle);\n if (side === 'left' ? pythonLessThan(candidate, item, functionName) : !pythonLessThan(item, candidate, functionName)) {\n left = middle + 1;\n }\n else {\n right = middle;\n }\n }\n return left;\n}\nfunction toBisectSequence(sequence, functionName) {\n if (Array.isArray(sequence) || typeof sequence === 'string') {\n return sequence;\n }\n throw new TypeError(`${functionName}() expected an indexable sequence`);\n}\nfunction normalizeLo(value, functionName) {\n if (value === undefined) {\n return 0;\n }\n const index = toSequenceIndex(value, functionName);\n if (index < 0) {\n throw new RangeError('lo must be non-negative');\n }\n return index;\n}\nfunction normalizeHi(value, sequenceLength, functionName) {\n if (value === undefined || value === null) {\n return sequenceLength;\n }\n return toSequenceIndex(value, functionName);\n}\nfunction toSequenceIndex(value, functionName) {\n const index = Number(toPythonInteger(value, functionName));\n if (!Number.isSafeInteger(index)) {\n throw new RangeError(`${functionName}() index must fit within JS safe integer precision`);\n }\n return index;\n}\nfunction getSequenceItem(sequence, index) {\n if (index < 0 || index >= sequence.length) {\n throw new Error(Array.isArray(sequence) ? 'list index out of range' : 'string index out of range');\n }\n return sequence[index];\n}\nfunction pythonLessThan(left, right, functionName) {\n if (isNumericLike(left) && isNumericLike(right)) {\n const leftNumber = toPythonNumber(left, functionName);\n const rightNumber = toPythonNumber(right, functionName);\n if (Number.isNaN(leftNumber) || Number.isNaN(rightNumber)) {\n return false;\n }\n return leftNumber < rightNumber;\n }\n if (typeof left === 'string' && typeof right === 'string') {\n return left < right;\n }\n throw new TypeError(`'<' not supported between instances of '${pythonTypeName(left)}' and '${pythonTypeName(right)}'`);\n}\nfunction pythonTypeName(value) {\n if (typeof value === 'string') {\n return 'str';\n }\n if (typeof value === 'boolean') {\n return 'bool';\n }\n if (typeof value === 'bigint' || typeof value === 'number') {\n return 'int';\n }\n if (Array.isArray(value)) {\n return 'list';\n }\n if (value === null) {\n return 'NoneType';\n }\n if (value === undefined) {\n return 'undefined';\n }\n return typeof value;\n}\n// python/bisect/bisect_left (target function module)\nfunction bisect_left(a, x, lo, hi) {\n // discuss at: https://locutus.io/python/bisect/bisect_left/\n // parity verified: Python 3.12\n // original by: Kevin van Zonneveld (https://kvz.io)\n // example 1: bisect_left([1, 2, 2, 4], 2)\n // returns 1: 1\n return pythonBisectLeft(a, x, lo, hi);\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/bisect/bisect_left.ts (tested in test/generated/python/bisect/bisect_left.vitest.ts)', function () { it('should pass example 1', 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 = (bisect_left: typeof __locutus_source_fn) => { return bisect_left([1, 2, 2, 4], 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) } }) })