Moved test_sum into it's own directory under scripts/

This commit is contained in:
2023-06-06 21:14:05 +10:00
parent bb81b8c474
commit 03e5096f10
3 changed files with 22 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
#include <stdio.h>
//functions be local in C
int sum(int n) {
if (n < 2) {
return n;
}
return n + sum(n - 1);
}
//the test case (C)
void test_sum(int key, int val) {
const int result = sum(val);
printf("%d: %d\n", key, result);
}
int main() {
for (int i = 0; i <= 10; i++) {
test_sum(i, i * 1000);
}
}

View File

@@ -0,0 +1,17 @@
//the test case (js)
function test_sum(key, val) {
function sum(n) {
if (n < 2) {
return n;
}
return n + sum(n - 1);
}
const result = sum(val);
console.log(`${key}: ${result}`);
}
for (let i = 0; i <= 10; i++) {
test_sum(i, i * 1000);
}

View File

@@ -0,0 +1,17 @@
//the test case (toy)
fn test_sum(key: int, val: int) {
fn sum(n: int) {
if (n < 2) {
return n;
}
return n + sum(n - 1);
}
var result: int const = sum(val);
print string key + ": " + string result;
}
for (var i: int = 0; i <= 10; i++) {
test_sum(i, i * 1000);
}