diff --git a/main_test.go b/main_test.go index aa20d6c3a..34a0af83c 100644 --- a/main_test.go +++ b/main_test.go @@ -38,7 +38,7 @@ type programOut struct { // go test -tags=integration -run=TestIntegrationScripts/tests/ctype/isalnum.c // func TestIntegrationScripts(t *testing.T) { - files, err := filepath.Glob("tests/*/*.c") + files, err := filepath.Glob("tests/*.c") if err != nil { t.Fatal(err) } diff --git a/tests/argv.c b/tests/argv.c new file mode 100644 index 000000000..7a60b5be4 --- /dev/null +++ b/tests/argv.c @@ -0,0 +1,17 @@ +// This file contains tests for the system arguments (argv). +// +// TODO: 'argc' and 'argv' are hard-coded. + +#include + +int main(int argc, char *argv[]) +{ + int c; + + printf("Number of command line arguments passed: %d\n", argc); + + for (c = 1; c < argc; c++) + printf("%d. Command line argument passed is %s\n", c + 1, argv[c]); + + return 0; +} diff --git a/tests/misc/array.c b/tests/array.c similarity index 78% rename from tests/misc/array.c rename to tests/array.c index 149d560e7..bbd4cefcd 100644 --- a/tests/misc/array.c +++ b/tests/array.c @@ -1,6 +1,8 @@ +// Array examples + #include - -int main() + +int main() { int array[3], n, c; @@ -9,11 +11,11 @@ int main() array[0] = 5; array[1] = 9; array[2] = -13; - + printf("Array elements entered by you are:\n"); - - for ( c = 0 ; c < n ; c++ ) + + for (c = 0; c < n; c++) printf("array[%d] = %d\n", c, array[c]); - + return 0; } diff --git a/tests/assert.c b/tests/assert.c new file mode 100644 index 000000000..da7a26941 --- /dev/null +++ b/tests/assert.c @@ -0,0 +1,24 @@ +// This file contains tests for assert.h. + +#include +#include + +void print_number(int *myInt) +{ + assert(myInt != NULL); + printf("%d\n", *myInt); +} + +int main() +{ + int a = 10; + int *b = NULL; + int *c = NULL; + + b = &a; + + print_number(b); + print_number(c); + + return 0; +} diff --git a/tests/assert/assert.c b/tests/assert/assert.c deleted file mode 100644 index 7150c051d..000000000 --- a/tests/assert/assert.c +++ /dev/null @@ -1,22 +0,0 @@ -/* assert example */ -#include /* printf */ -#include /* assert */ - -void print_number(int* myInt) { - assert (myInt!=NULL); - printf ("%d\n",*myInt); -} - -int main () -{ - int a=10; - int * b = NULL; - int * c = NULL; - - b=&a; - - print_number (b); - print_number (c); - - return 0; -} diff --git a/tests/ctype/ctype.c b/tests/ctype.c similarity index 99% rename from tests/ctype/ctype.c rename to tests/ctype.c index 338a03e46..1dab474f1 100644 --- a/tests/ctype/ctype.c +++ b/tests/ctype.c @@ -1,4 +1,5 @@ -/* isalnum example */ +// Tests for ctype.h. + #include #include @@ -196,6 +197,6 @@ int main() test_isxdigit(); test_tolower(); test_toupper(); - + return 0; } diff --git a/tests/misc/fib.c b/tests/fib.c similarity index 100% rename from tests/misc/fib.c rename to tests/fib.c diff --git a/tests/misc/for.c b/tests/for.c similarity index 100% rename from tests/misc/for.c rename to tests/for.c diff --git a/tests/misc/function.c b/tests/function.c similarity index 100% rename from tests/misc/function.c rename to tests/function.c diff --git a/tests/misc/if.c b/tests/if.c similarity index 100% rename from tests/misc/if.c rename to tests/if.c diff --git a/tests/math/math.c b/tests/math.c similarity index 99% rename from tests/math/math.c rename to tests/math.c index 51b9404d5..915b2819b 100644 --- a/tests/math/math.c +++ b/tests/math.c @@ -1,3 +1,5 @@ +// Test for math.h. + #include #include diff --git a/tests/misc/argv.c b/tests/misc/argv.c deleted file mode 100644 index 214565c1d..000000000 --- a/tests/misc/argv.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -int main(int argc, char *argv[]) -{ - int c; - - printf("Number of command line arguments passed: %d\n", argc); - - for ( c = 1 ; c < argc ; c++) - printf("%d. Command line argument passed is %s\n", c+1, argv[c]); - - return 0; -} diff --git a/tests/misc/comments.c b/tests/misc/comments.c deleted file mode 100644 index 4f9765dda..000000000 --- a/tests/misc/comments.c +++ /dev/null @@ -1,18 +0,0 @@ -#include - -int main() -{ - // Single line comment in c source code - - printf("Writing comments is very useful.\n"); - - /* - * Multi line comment syntax - * Comments help us to understand code later easily. - * Will you write comments while developing programs ? - */ - - printf("Good luck c programmer.\n"); - - return 0; -} diff --git a/tests/misc/hello-world.c b/tests/misc/hello-world.c deleted file mode 100644 index 17130760a..000000000 --- a/tests/misc/hello-world.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main() -{ - printf("Hello World\n"); - return 0; -} diff --git a/tests/misc/if-else.c b/tests/misc/if-else.c deleted file mode 100644 index 380b19f81..000000000 --- a/tests/misc/if-else.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -int main() -{ - int x = 2; - - if ( x == 1 ) - printf("x is equal to one.\n"); - else - printf("For comparison use == as = is the assignment operator.\n"); - - return 0; -} diff --git a/tests/misc/prime.c b/tests/misc/prime.c deleted file mode 100644 index 44098f2df..000000000 --- a/tests/misc/prime.c +++ /dev/null @@ -1,25 +0,0 @@ -#include - -int main() -{ - int n, c; - - printf("Enter a number\n"); - scanf("%d", &n); - - if ( n == 2 ) - printf("Prime number.\n"); - else - { - for ( c = 2 ; c <= n - 1 ; c++ ) - { - if ( n % c == 0 ) - break; - } - if ( c != n ) - printf("Not prime.\n"); - else - printf("Prime number.\n"); - } - return 0; -} diff --git a/tests/misc/struct.c b/tests/misc/struct.c deleted file mode 100644 index 72cc814b5..000000000 --- a/tests/misc/struct.c +++ /dev/null @@ -1,21 +0,0 @@ -#include - -struct programming -{ - float constant; - char *pointer; -}; - -int main() -{ - struct programming variable; - char *s = "Programming in Software Development."; - - variable.constant = 1.23; - variable.pointer = s; - - printf("%f\n", variable.constant); - printf("%s\n", variable.pointer); - - return 0; -} diff --git a/tests/misc/user-input.c b/tests/misc/user-input.c deleted file mode 100644 index 43304eb8a..000000000 --- a/tests/misc/user-input.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -int main() -{ - int number; - - printf("Enter an integer\n"); - scanf("%d",&number); - - printf("Integer entered by you is %d\n", number); - - return 0; -} diff --git a/tests/misc/while.c b/tests/misc/while.c deleted file mode 100644 index 64d466721..000000000 --- a/tests/misc/while.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -int main() -{ - int value = 1; - - while(value<=3) - { - printf("Value is %d\n", value); - value++; - } - - return 0; -} diff --git a/tests/prime.c b/tests/prime.c new file mode 100644 index 000000000..0b8a7b969 --- /dev/null +++ b/tests/prime.c @@ -0,0 +1,25 @@ +#include + +int main() +{ + int n, c; + + printf("Enter a number\n"); + scanf("%d", &n); + + if (n == 2) + printf("Prime number.\n"); + else + { + for (c = 2; c <= n - 1; c++) + { + if (n % c == 0) + break; + } + if (c != n) + printf("Not prime.\n"); + else + printf("Prime number.\n"); + } + return 0; +} diff --git a/tests/stdio/stdio.c b/tests/stdio.c similarity index 67% rename from tests/stdio/stdio.c rename to tests/stdio.c index 93834abb4..5b0275874 100644 --- a/tests/stdio/stdio.c +++ b/tests/stdio.c @@ -1,12 +1,13 @@ // This program actually still works without including stdio.h but it should be // here for consistency. + #include void test_putchar() { char c; for (c = 'A'; c <= 'Z'; c++) - putchar(c); + putchar(c); } void test_puts() @@ -14,10 +15,16 @@ void test_puts() puts("c2go"); } +void test_printf() +{ + printf("Hello World\n"); +} + int main() { - test_putchar(); - test_puts(); + test_putchar(); + test_puts(); + test_printf(); return 0; } diff --git a/tests/struct.c b/tests/struct.c new file mode 100644 index 000000000..9da060389 --- /dev/null +++ b/tests/struct.c @@ -0,0 +1,23 @@ +// Tests for structures. + +#include + +struct programming +{ + float constant; + char *pointer; +}; + +int main() +{ + struct programming variable; + char *s = "Programming in Software Development."; + + variable.constant = 1.23; + variable.pointer = s; + + printf("%f\n", variable.constant); + printf("%s\n", variable.pointer); + + return 0; +} diff --git a/tests/user-input.c b/tests/user-input.c new file mode 100644 index 000000000..8ebee25d9 --- /dev/null +++ b/tests/user-input.c @@ -0,0 +1,13 @@ +#include + +int main() +{ + int number; + + printf("Enter an integer\n"); + scanf("%d", &number); + + printf("Integer entered by you is %d\n", number); + + return 0; +} diff --git a/tests/while.c b/tests/while.c new file mode 100644 index 000000000..352a6fd8c --- /dev/null +++ b/tests/while.c @@ -0,0 +1,14 @@ +#include + +int main() +{ + int value = 1; + + while (value <= 3) + { + printf("Value is %d\n", value); + value++; + } + + return 0; +}