chore: restructure project into src/tests/examples directories with modular build system
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
int main() {
|
||||
int counter = 0;
|
||||
|
||||
printf("Testing while(1) endless loop with counter:\n");
|
||||
|
||||
while (1) {
|
||||
printf("Loop iteration: %d\n", counter);
|
||||
counter = counter + 1;
|
||||
|
||||
if (counter == 10) {
|
||||
printf("Reached 10 iterations, exiting\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
printf("This should never print\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
int main() {
|
||||
int x = -5;
|
||||
int y = -10;
|
||||
int z = 0;
|
||||
|
||||
printf("Testing negative numbers:\n");
|
||||
printf("x = %d\n", x);
|
||||
printf("y = %d\n", y);
|
||||
printf("x + y = %d\n", x + y);
|
||||
|
||||
printf("\nTesting == operator:\n");
|
||||
if (x == -5) {
|
||||
printf("x == -5 is true\n");
|
||||
}
|
||||
if (x == y) {
|
||||
printf("x == y is true\n");
|
||||
} else {
|
||||
printf("x == y is false\n");
|
||||
}
|
||||
|
||||
printf("\nTesting != operator:\n");
|
||||
if (x != y) {
|
||||
printf("x != y is true\n");
|
||||
}
|
||||
if (x != -5) {
|
||||
printf("x != -5 is true\n");
|
||||
} else {
|
||||
printf("x != -5 is false\n");
|
||||
}
|
||||
|
||||
printf("\nTesting while loop with counter:\n");
|
||||
int count = 0;
|
||||
while (count != 5) {
|
||||
printf("count = %d\n", count);
|
||||
count = count + 1;
|
||||
}
|
||||
|
||||
printf("\nTesting while(1) with break condition:\n");
|
||||
int i = 0;
|
||||
while (1) {
|
||||
printf("i = %d\n", i);
|
||||
i = i + 1;
|
||||
if (i == 3) {
|
||||
printf("Breaking out of infinite loop\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
int main() {
|
||||
printf("Testing Math Functions:\n\n");
|
||||
|
||||
int x = 16;
|
||||
int result = sqrt(x);
|
||||
printf("sqrt(16) = %d\n", result);
|
||||
|
||||
int p = pow(2, 8);
|
||||
printf("pow(2, 8) = %d\n", p);
|
||||
|
||||
int a = abs(-42);
|
||||
printf("abs(-42) = %d\n", a);
|
||||
|
||||
int f = floor(7);
|
||||
printf("floor(7) = %d\n", f);
|
||||
|
||||
int c = ceil(7);
|
||||
printf("ceil(7) = %d\n", c);
|
||||
|
||||
printf("\nTesting with negative numbers:\n");
|
||||
int neg = -100;
|
||||
int abs_neg = abs(neg);
|
||||
printf("abs(-100) = %d\n", abs_neg);
|
||||
|
||||
printf("\nTesting pow with different values:\n");
|
||||
printf("pow(3, 3) = %d\n", pow(3, 3));
|
||||
printf("pow(5, 2) = %d\n", pow(5, 2));
|
||||
printf("pow(10, 3) = %d\n", pow(10, 3));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
int main() {
|
||||
printf("=== String Manipulation Tests ===\n\n");
|
||||
|
||||
char *text = "Hello World";
|
||||
|
||||
printf("Testing strpos:\n");
|
||||
int pos = strpos(text, "World");
|
||||
printf("Position of 'World' in 'Hello World': %d\n", pos);
|
||||
int pos2 = strpos(text, "xyz");
|
||||
printf("Position of 'xyz' in 'Hello World': %d\n\n", pos2);
|
||||
|
||||
printf("Testing substr:\n");
|
||||
char *sub = substr(text, 0, 5);
|
||||
printf("substr('Hello World', 0, 5) = '%s'\n", sub);
|
||||
char *sub2 = substr(text, 6, 5);
|
||||
printf("substr('Hello World', 6, 5) = '%s'\n\n", sub2);
|
||||
|
||||
printf("Testing upper and lower:\n");
|
||||
char *up = upper(text);
|
||||
printf("upper('Hello World') = '%s'\n", up);
|
||||
char *low = lower(text);
|
||||
printf("lower('Hello World') = '%s'\n\n", low);
|
||||
|
||||
printf("Testing strip:\n");
|
||||
char *spaced = " Hello World ";
|
||||
char *stripped = strip(spaced);
|
||||
printf("strip(' Hello World ') = '%s'\n\n", stripped);
|
||||
|
||||
printf("Testing replace:\n");
|
||||
char *replaced = replace(text, "World", "Python");
|
||||
printf("replace('Hello World', 'World', 'Python') = '%s'\n", replaced);
|
||||
char *replaced2 = replace("aaa bbb aaa", "aaa", "xxx");
|
||||
printf("replace('aaa bbb aaa', 'aaa', 'xxx') = '%s'\n\n", replaced2);
|
||||
|
||||
printf("Testing startswith:\n");
|
||||
if (startswith(text, "Hello")) {
|
||||
printf("'Hello World' starts with 'Hello': true\n");
|
||||
}
|
||||
if (startswith(text, "World")) {
|
||||
printf("'Hello World' starts with 'World': true\n");
|
||||
} else {
|
||||
printf("'Hello World' starts with 'World': false\n");
|
||||
}
|
||||
|
||||
printf("\nTesting endswith:\n");
|
||||
if (endswith(text, "World")) {
|
||||
printf("'Hello World' ends with 'World': true\n");
|
||||
}
|
||||
if (endswith(text, "Hello")) {
|
||||
printf("'Hello World' ends with 'Hello': true\n");
|
||||
} else {
|
||||
printf("'Hello World' ends with 'Hello': false\n");
|
||||
}
|
||||
|
||||
printf("\nTesting slicing [start:end]:\n");
|
||||
char *str = "Python Programming";
|
||||
char *slice1 = str[0:6];
|
||||
printf("'Python Programming'[0:6] = '%s'\n", slice1);
|
||||
char *slice2 = str[7:18];
|
||||
printf("'Python Programming'[7:18] = '%s'\n", slice2);
|
||||
char *slice3 = str[7:11];
|
||||
printf("'Python Programming'[7:11] = '%s'\n", slice3);
|
||||
|
||||
printf("\nCombining operations:\n");
|
||||
char *combined = upper(str[0:6]);
|
||||
printf("upper('Python Programming'[0:6]) = '%s'\n", combined);
|
||||
|
||||
char *chain = replace(lower("HELLO WORLD"), "world", "python");
|
||||
printf("replace(lower('HELLO WORLD'), 'world', 'python') = '%s'\n", chain);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
int main() {
|
||||
printf("Testing String Concatenation:\n\n");
|
||||
|
||||
char *hello = "Hello";
|
||||
char *world = " World";
|
||||
char *result = hello + world;
|
||||
printf("Result: %s\n", result);
|
||||
|
||||
printf("\nTesting multiple concatenations:\n");
|
||||
char *a = "aaa";
|
||||
char *b = "bbb";
|
||||
char *c = "ccc";
|
||||
char *abc = a + b + c;
|
||||
printf("a + b + c = %s\n", abc);
|
||||
|
||||
printf("\nTesting literal concatenation:\n");
|
||||
char *direct = "First" + " Second" + " Third";
|
||||
printf("Result: %s\n", direct);
|
||||
|
||||
printf("\nTesting with variable and literal:\n");
|
||||
char *name = "Alice";
|
||||
char *greeting = "Hello, " + name + "!";
|
||||
printf("%s\n", greeting);
|
||||
|
||||
printf("\nTesting in printf directly:\n");
|
||||
printf("Direct: %s\n", "Start" + " Middle" + " End");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user