Skip to content

Commit

Permalink
Moving tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotchance committed Apr 24, 2017
1 parent c84e8ce commit 020584c
Show file tree
Hide file tree
Showing 24 changed files with 140 additions and 158 deletions.
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
17 changes: 17 additions & 0 deletions tests/argv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This file contains tests for the system arguments (argv).
//
// TODO: 'argc' and 'argv' are hard-coded.

#include <stdio.h>

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;
}
14 changes: 8 additions & 6 deletions tests/misc/array.c → tests/array.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Array examples

#include <stdio.h>
int main()

int main()
{
int array[3], n, c;

Expand All @@ -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;
}
24 changes: 24 additions & 0 deletions tests/assert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This file contains tests for assert.h.

#include <stdio.h>
#include <assert.h>

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;
}
22 changes: 0 additions & 22 deletions tests/assert/assert.c

This file was deleted.

5 changes: 3 additions & 2 deletions tests/ctype/ctype.c → tests/ctype.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* isalnum example */
// Tests for ctype.h.

#include <stdio.h>
#include <ctype.h>

Expand Down Expand Up @@ -196,6 +197,6 @@ int main()
test_isxdigit();
test_tolower();
test_toupper();

return 0;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions tests/math/math.c → tests/math.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Test for math.h.

#include <stdio.h>
#include <math.h>

Expand Down
13 changes: 0 additions & 13 deletions tests/misc/argv.c

This file was deleted.

18 changes: 0 additions & 18 deletions tests/misc/comments.c

This file was deleted.

7 changes: 0 additions & 7 deletions tests/misc/hello-world.c

This file was deleted.

13 changes: 0 additions & 13 deletions tests/misc/if-else.c

This file was deleted.

25 changes: 0 additions & 25 deletions tests/misc/prime.c

This file was deleted.

21 changes: 0 additions & 21 deletions tests/misc/struct.c

This file was deleted.

13 changes: 0 additions & 13 deletions tests/misc/user-input.c

This file was deleted.

14 changes: 0 additions & 14 deletions tests/misc/while.c

This file was deleted.

25 changes: 25 additions & 0 deletions tests/prime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <stdio.h>

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;
}
13 changes: 10 additions & 3 deletions tests/stdio/stdio.c → tests/stdio.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
// This program actually still works without including stdio.h but it should be
// here for consistency.

#include <stdio.h>

void test_putchar()
{
char c;
for (c = 'A'; c <= 'Z'; c++)
putchar(c);
putchar(c);
}

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;
}
23 changes: 23 additions & 0 deletions tests/struct.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Tests for structures.

#include <stdio.h>

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;
}
13 changes: 13 additions & 0 deletions tests/user-input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stdio.h>

int main()
{
int number;

printf("Enter an integer\n");
scanf("%d", &number);

printf("Integer entered by you is %d\n", number);

return 0;
}
14 changes: 14 additions & 0 deletions tests/while.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdio.h>

int main()
{
int value = 1;

while (value <= 3)
{
printf("Value is %d\n", value);
value++;
}

return 0;
}

0 comments on commit 020584c

Please sign in to comment.