Skip to content

Commit 31896e8

Browse files
committed
supported examples added
1 parent 6048615 commit 31896e8

23 files changed

+370
-130
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
4+
int abs_val(int x) {
5+
if (x < 0 && abs(x) > 0) {
6+
return -1;
7+
} else if (x > 0) {
8+
return 1;
9+
}
10+
return abs(x);
11+
}
12+
13+
int sign(char const *str) {
14+
int x = atoi(str);
15+
if (x == 5) {
16+
return 7;
17+
}
18+
// fprintf(stderr, "parsed int = %d\n", x);
19+
if (x > 0) {
20+
return 1;
21+
} else if (x < 0) {
22+
return -1;
23+
}
24+
return 0;
25+
}

integration-tests/c-example/lib/multi_arrays.c renamed to integration-tests/c-example/lib/arrays.c

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,10 @@
1-
#include "multi_arrays.h"
1+
#include "arrays.h"
22

3-
#include <string.h>
4-
5-
struct MyStructMult {
6-
int a[2][3][2];
7-
};
8-
9-
struct IntArray {
10-
int ints[2][5];
11-
};
12-
13-
struct PointStruct {
14-
int x;
15-
int y;
16-
};
17-
18-
19-
int kek(int a[1][2]) {
20-
return 1;
3+
int get_00_elem(int a[1][2]) {
4+
return a[0][0];
215
}
226

23-
24-
int sumSign(int a[2][2]) {
7+
int sum_sign(int a[2][2]) {
258
int sum = 0;
269
for (int i = 0; i < 2; i++) {
2710
for (int j = 0; j < 2; j++) {
@@ -37,6 +20,25 @@ int sumSign(int a[2][2]) {
3720
}
3821
}
3922

23+
int sum_sign_1d_small(int a[9]) {
24+
int sum = 0;
25+
for (int i = 0; i < 9; i++) {
26+
sum += a[i];
27+
if (i % 2 == 0) {
28+
sum++;
29+
} else {
30+
sum--;
31+
}
32+
}
33+
if (sum == 0) {
34+
return 0;
35+
} else if (sum > 0) {
36+
return 1;
37+
} else {
38+
return -1;
39+
}
40+
}
41+
4042
int value(int a[2][3]) {
4143
for (int i = 0; i < 2; i++) {
4244
for (int j = 0; j < 3; j++) {
@@ -48,7 +50,7 @@ int value(int a[2][3]) {
4850
return -1;
4951
}
5052

51-
int value2(int (* a)[3]) {
53+
int value2(int (*a)[3]) {
5254
for (int i = 0; i < 2; i++) {
5355
for (int j = 0; j < 3; j++) {
5456
if (a[i][j] > 0) {
@@ -60,8 +62,7 @@ int value2(int (* a)[3]) {
6062
}
6163

6264

63-
int some_method(int ** pointer2d) {
64-
int x = 2;
65+
int some_method(int **pointer2d) {
6566
for (int i = 0; i < 2; i++) {
6667
for (int j = 0; j < 2; j++) {
6768
if (pointer2d[i][j] > 0) {
@@ -75,13 +76,13 @@ int some_method(int ** pointer2d) {
7576
int return_sign_sum(struct MyStructMult st) {
7677
int res = 0;
7778
for (int i = 0; i < 2; i++) {
78-
for(int j = 0; j < 3; j++) {
79+
for (int j = 0; j < 3; j++) {
7980
for (int k = 0; k < 2; k++) {
8081
res += st.a[i][j][k];
8182
}
82-
}
83+
}
8384
}
84-
85+
8586
if (res > 0) {
8687
return 1;
8788
} else if (res == 0) {
@@ -98,7 +99,7 @@ long long return_sign_sum_of_struct_array(struct PointStruct arr[2][2]) {
9899
if (arr[i][j].x > 0) {
99100
sumDiffs += arr[i][j].x;
100101
} else {
101-
sumDiffs += -arr[i][j].x;
102+
sumDiffs += -arr[i][j].x;
102103
}
103104

104105
if (arr[i][j].y > 0) {
@@ -111,31 +112,31 @@ long long return_sign_sum_of_struct_array(struct PointStruct arr[2][2]) {
111112
return sumDiffs;
112113
}
113114

114-
int point_quart(struct PointStruct ** point) {
115+
int point_quart(struct PointStruct **point) {
115116
if ((**point).x > 0) {
116-
if ((**point).y > 0) {
117-
return 1;
118-
} else {
119-
return 4;
120-
}
117+
if ((**point).y > 0) {
118+
return 1;
119+
} else {
120+
return 4;
121+
}
121122
} else {
122-
if ((**point).y > 0) {
123-
return 2;
124-
} else {
125-
return 3;
126-
}
123+
if ((**point).y > 0) {
124+
return 2;
125+
} else {
126+
return 3;
127+
}
127128
}
128129
}
129130

130131
struct IntArray return_struct_with_2d_array(int a) {
131132
if (a > 0) {
132-
struct IntArray st = {{{1,2,3,4,5}, {1,2,3,4,5}}};
133+
struct IntArray st = {{{ 1, 2, 3, 4, 5 }, { 1, 2, 3, 4, 5 }}};
133134
return st;
134135
} else if (a < 0) {
135-
struct IntArray st = {{{-1,-2,-3,-4,-5}, {-1,-2,-3,-4,-5}}};
136+
struct IntArray st = {{{ -1, -2, -3, -4, -5 }, { -1, -2, -3, -4, -5 }}};
136137
return st;
137138
} else {
138-
struct IntArray st = {{{0,0,0,0,0}, {0,0,0,0,0}}};
139+
struct IntArray st = {{{ 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }}};
139140
return st;
140141
}
141142
}
@@ -163,10 +164,7 @@ int sum_matrix() {
163164
return sum;
164165
}
165166

166-
int argc;
167-
char **argv;
168-
169-
int count_dashes() {
167+
int count_dashes(int argc, char **argv) {
170168
char **cur = argv;
171169
int cnt = 0;
172170
while (argc--) {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef C_EXAMPLE_ARRAYS_H
2+
#define C_EXAMPLE_ARRAYS_H
3+
4+
#include <stddef.h>
5+
6+
int get_00_elem(int a[1][2]);
7+
8+
int sum_sign(int a[2][2]);
9+
10+
int sum_sign_1d_small(int a[9]);
11+
12+
int value(int a[2][3]);
13+
14+
int value2(int (*a)[3]);
15+
16+
int value3(int a[]);
17+
18+
int some_method(int **pointer2d);
19+
20+
struct MyStructMult {
21+
int a[2][3][2];
22+
};
23+
24+
struct IntArray {
25+
int ints[2][5];
26+
};
27+
28+
struct PointStruct {
29+
int x;
30+
int y;
31+
};
32+
33+
int return_sign_sum(struct MyStructMult st);
34+
35+
long long return_sign_sum_of_struct_array(struct PointStruct arr[2][2]);
36+
37+
int point_quart(struct PointStruct **point);
38+
39+
struct IntArray return_struct_with_2d_array(int a);
40+
41+
int count_dashes(int argc, char **argv);
42+
43+
#endif //C_EXAMPLE_ARRAYS_H

integration-tests/c-example/lib/assertion_failures.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include "assert.h"
55

66
int buggy_function1(int a, int b);
7+
78
int buggy_function2(int a);
9+
810
int buggy_function3(int a, int b);
911

10-
#endif //UNITTESTBOT_SRC_ASSERT_FAIL_H
12+
#endif //SIMPLE_TEST_PROJECT_SRC_ASSERT_FAIL_H

integration-tests/c-example/lib/basic_functions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
#define SIMPLE_TEST_PROJECT_BASIC_FUNCTIONS_H
33

44
int max_(int a, int b);
5+
56
int min(int a, int b);
7+
68
int sqr_positive(int a);
9+
710
int simple_loop(unsigned int n);
811

912
#endif //SIMPLE_TEST_PROJECT_BASIC_FUNCTIONS_H
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
int f() {
2+
struct s {
3+
int i;
4+
} *p = 0, *q;
5+
int j = 0;
6+
again:
7+
q = p, p = &((struct s) { j++ });
8+
if (j < 2) goto again;
9+
return p == q && q->i == 1; // always returns 1
10+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#define typeid(x) _Generic((x), \
2+
_Bool: 0, \
3+
char: 1, \
4+
int: 2, \
5+
float: 3, \
6+
default: 4)
7+
8+
int get_typeid(unsigned short int casen) {
9+
switch (casen) {
10+
case 0:
11+
return typeid((_Bool const) 0);
12+
case 1:
13+
return typeid((char) 'c');
14+
case 2:
15+
return typeid(24);
16+
case 3:
17+
return typeid(42.f);
18+
default:
19+
return typeid("char const *");
20+
}
21+
}
22+
23+
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "halt.h"
22

3-
#include "signal.h"
3+
#include <signal.h>
4+
#include <stdio.h>
5+
#include <stdlib.h>
46

57
int raise_by_num(int num) {
68
return raise(num);
@@ -9,3 +11,16 @@ int raise_by_num(int num) {
911
int raise_stop(int _) {
1012
return raise(SIGSTOP);
1113
}
14+
15+
void cleanup() {
16+
setvbuf(stdout, NULL, _IONBF, 0);
17+
printf("Normal program termination with cleaning up\n");
18+
}
19+
20+
int call_abort() {
21+
if (atexit(cleanup)) {
22+
return EXIT_FAILURE;
23+
}
24+
printf("Going to abort the program\n");
25+
abort();
26+
}

integration-tests/c-example/lib/halt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ int raise_by_num(int num);
55

66
int raise_stop(int _);
77

8+
void cleanup();
9+
10+
int call_abort();
11+
812
#endif

0 commit comments

Comments
 (0)