mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Add more tests
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// test_output! [[1,2,5],[1,2,3,4,5]]
|
||||
|
||||
export default function main() {
|
||||
let tree = BinaryTree();
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! [[1,2,5],[1,2,3,4,5]]
|
||||
|
||||
export default function main() {
|
||||
let tree = new BinaryTree<number>();
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! [1,2,3]
|
||||
|
||||
export default function main() {
|
||||
let c = Counter();
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
export default function main(n) {
|
||||
export default function main(n: string) {
|
||||
return factorial(+n);
|
||||
}
|
||||
|
||||
function factorial(n) {
|
||||
function factorial(n: number): number {
|
||||
if (n === 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! "Hello world!"
|
||||
|
||||
export default function main() {
|
||||
return 'Hello world!';
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]
|
||||
|
||||
export default function main() {
|
||||
const x = [7, 18, 9, 11, 16, 3, 8, 2, 5, 4, 6, 14, 15, 17, 10, 12, 1, 13];
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output (TODO broken!) [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]
|
||||
|
||||
declare const Debug: {
|
||||
log: (...args: unknown[]) => undefined;
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! 2
|
||||
|
||||
export default function main() {
|
||||
let value = 1;
|
||||
return ++value;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! 70600674
|
||||
|
||||
export default function main() {
|
||||
const grid = [
|
||||
[ 8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8],
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! "Probably 5537376230 (trailing digits: 39036)"
|
||||
|
||||
export default function main() {
|
||||
const numStrs = [
|
||||
'37107287533902102798797998220837590246510135740250',
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! 137846528820
|
||||
|
||||
export default function main() {
|
||||
let rc = new RouteCalculator();
|
||||
return rc.calculate(20, 20);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! 1074
|
||||
|
||||
export default function main() {
|
||||
const tower = [
|
||||
[75],
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! 171
|
||||
|
||||
declare const Debug: {
|
||||
log: (...args: unknown[]) => undefined;
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! 232792560
|
||||
|
||||
declare const Debug: {
|
||||
log: (...args: unknown[]) => undefined;
|
||||
};
|
||||
@@ -19,7 +21,7 @@ function lcm(leftFactors: number[], rightFactors: number[]): number[] {
|
||||
while (leftFactors[0] < rightFactors[0]) {
|
||||
factors.push(leftFactors.shift()!);
|
||||
}
|
||||
|
||||
|
||||
while (rightFactors[0] < leftFactors[0]) {
|
||||
factors.push(rightFactors.shift()!);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! 25164150
|
||||
|
||||
export default function main() {
|
||||
return squareOfSum(100) - sumOfSquares(100);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
// test_output! 23514624000
|
||||
|
||||
export default function main() {
|
||||
const digits = [
|
||||
'73167176531330624919225119674426574742355349194934',
|
||||
'96983520312774506326239578318016984801869478851843',
|
||||
'85861560789112949495459501737958331952853208805511',
|
||||
'12540698747158523863050715693290963295227443043557',
|
||||
'66896648950445244523161731856403098711121722383113',
|
||||
'62229893423380308135336276614282806444486645238749',
|
||||
'30358907296290491560440772390713810515859307960866',
|
||||
'70172427121883998797908792274921901699720888093776',
|
||||
'65727333001053367881220235421809751254540594752243',
|
||||
'52584907711670556013604839586446706324415722155397',
|
||||
'53697817977846174064955149290862569321978468622482',
|
||||
'83972241375657056057490261407972968652414535100474',
|
||||
'82166370484403199890008895243450658541227588666881',
|
||||
'16427171479924442928230863465674813919123162824586',
|
||||
'17866458359124566529476545682848912883142607690042',
|
||||
'24219022671055626321111109370544217506941658960408',
|
||||
'07198403850962455444362981230987879927244284909188',
|
||||
'84580156166097919133875499200524063689912560717606',
|
||||
'05886116467109405077541002256983155200055935729725',
|
||||
'71636269561882670428252483600823257530420752963450',
|
||||
].join('');
|
||||
"73167176531330624919225119674426574742355349194934",
|
||||
"96983520312774506326239578318016984801869478851843",
|
||||
"85861560789112949495459501737958331952853208805511",
|
||||
"12540698747158523863050715693290963295227443043557",
|
||||
"66896648950445244523161731856403098711121722383113",
|
||||
"62229893423380308135336276614282806444486645238749",
|
||||
"30358907296290491560440772390713810515859307960866",
|
||||
"70172427121883998797908792274921901699720888093776",
|
||||
"65727333001053367881220235421809751254540594752243",
|
||||
"52584907711670556013604839586446706324415722155397",
|
||||
"53697817977846174064955149290862569321978468622482",
|
||||
"83972241375657056057490261407972968652414535100474",
|
||||
"82166370484403199890008895243450658541227588666881",
|
||||
"16427171479924442928230863465674813919123162824586",
|
||||
"17866458359124566529476545682848912883142607690042",
|
||||
"24219022671055626321111109370544217506941658960408",
|
||||
"07198403850962455444362981230987879927244284909188",
|
||||
"84580156166097919133875499200524063689912560717606",
|
||||
"05886116467109405077541002256983155200055935729725",
|
||||
"71636269561882670428252483600823257530420752963450",
|
||||
].join("");
|
||||
|
||||
let largest = 0;
|
||||
const lenM13 = digits.length - 13;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! 31875000
|
||||
|
||||
export default function main() {
|
||||
for (let a = 1; a <= 1000; a++) {
|
||||
for (let b = a; b <= 1000; b++) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! {"leftBowl":["apple","mango"],"rightBowl":["apple","mango","peach"]}
|
||||
|
||||
export default function main() {
|
||||
const leftBowl = ['apple', 'mango'];
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! 3
|
||||
|
||||
export default function main() {
|
||||
let sum = 0;
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// test_output! 3
|
||||
|
||||
export default function main() {
|
||||
const x = 3;
|
||||
|
||||
|
||||
@@ -24,12 +24,16 @@ mod tests {
|
||||
|
||||
let mut failed_paths = HashSet::<PathBuf>::new();
|
||||
|
||||
let files = get_files_recursively(input_dir_path).expect("Failed to get files");
|
||||
let mut files = get_files_recursively(input_dir_path).expect("Failed to get files");
|
||||
files.sort();
|
||||
|
||||
for file_path in files {
|
||||
let file_contents = fs::read_to_string(&file_path).expect("Failed to read file contents");
|
||||
|
||||
if let Some(first_line) = file_contents.lines().next() {
|
||||
if first_line.starts_with("// test_output! ") {
|
||||
println!("\nTesting {} ...", file_path.to_str().unwrap());
|
||||
|
||||
let output_str = first_line
|
||||
.splitn(2, "// test_output! ")
|
||||
.nth(1)
|
||||
@@ -62,10 +66,8 @@ mod tests {
|
||||
|
||||
if result_str != output_str {
|
||||
println!(
|
||||
"Failed {} (expected \"{}\", got \"{}\")",
|
||||
file_path.to_str().unwrap(),
|
||||
output_str,
|
||||
result_str,
|
||||
" Expected: \"{}\"\n Actual: \"{}\"\n",
|
||||
output_str, result_str,
|
||||
);
|
||||
|
||||
failed_paths.insert(file_path.clone());
|
||||
|
||||
Reference in New Issue
Block a user