• + 0 comments

    'use strict';

    process.stdin.resume(); process.stdin.setEncoding('utf-8');

    let inputString: string = ''; let inputLines: string[] = []; let currentLine: number = 0;

    process.stdin.on('data', function(inputStdin: string): void { inputString += inputStdin; });

    process.stdin.on('end', function(): void { inputLines = inputString.split('\n'); inputString = '';

    main();
    

    });

    function readLine(): string { return inputLines[currentLine++]; }

    class TestDataEmptyArray { static get_array(): number[] { return []; } }

    class TestDataUniqueValues { static get_array(): number[] { return [3, 1, 2]; }

    static get_expected_result(): number {
        return 1;
    }
    

    }

    class TestDataExactlyTwoDifferentMinimums { static get_array(): number[] { return [2, 1, 3, 1]; }

    static get_expected_result(): number {
        return 1;
    }
    

    }

    function minimum_index(seq: number[]): number { if (seq.length === 0) { throw new Error("Cannot get the minimum value index from an empty sequence"); } let min_idx: number = 0; for (let i: number = 1; i < seq.length; i++) { if (seq[i] < seq[min_idx]) { min_idx = i; } } return min_idx; }

    function TestWithEmptyArray(): void { try { const seq: number[] = TestDataEmptyArray.get_array(); const result: number = minimum_index(seq); } catch (e) { return; } throw new Error("Exception wasn't thrown as expected"); }

    function TestWithUniqueValues(): void { const seq: number[] = TestDataUniqueValues.get_array(); const result: number = minimum_index(seq); if (result !== TestDataUniqueValues.get_expected_result()) { throw new Error("Result doesn't match the expected value for unique values array"); } }

    function TestWithExactlyTwoDifferentMinimums(): void { const seq: number[] = TestDataExactlyTwoDifferentMinimums.get_array(); const result: number = minimum_index(seq); if (result !== TestDataExactlyTwoDifferentMinimums.get_expected_result()) { throw new Error("Result doesn't match the expected value for array with two minimums"); } }

    function main(): void { try { TestWithEmptyArray(); TestWithUniqueValues(); TestWithExactlyTwoDifferentMinimums(); console.log("OK"); } catch (e) { console.log((e as Error).message); } }