We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 27: Testing
Day 27: Testing
Sort by
recency
|
228 Discussions
|
Please Login in order to post a comment
I tried joining Online Quran Classes For Adults after struggling to keep a consistent schedule for learning at home. The experience made it much easier to follow lessons at my own pace, and I could practice with clear guidance. It’s refreshing to see classes designed for adult learners that focus on practical understanding and daily application.
I think the templates need an update or the problem description needs to be adjusted.
import java.util.*;
public class Solution {
} **
'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 = '';
});
function readLine(): string { return inputLines[currentLine++]; }
class TestDataEmptyArray { static get_array(): number[] { return []; } }
class TestDataUniqueValues { static get_array(): number[] { return [3, 1, 2]; }
}
class TestDataExactlyTwoDifferentMinimums { static get_array(): number[] { return [2, 1, 3, 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); } }