Skip to content

Commit 9ac98b2

Browse files
committed
supported examples added
1 parent 6048615 commit 9ac98b2

26 files changed

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

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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}
Lines changed: 15 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,15 @@ int raise_by_num(int num) {
911
int raise_stop(int _) {
1012
return raise(SIGSTOP);
1113
}
14+
15+
void cleanup() {
16+
fprintf(stderr, "Normal program termination with cleaning up\n");
17+
}
18+
19+
int call_abort() {
20+
if (atexit(cleanup)) {
21+
return EXIT_FAILURE;
22+
}
23+
fprintf(stderr, "Going to abort the program\n");
24+
abort();
25+
}

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
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include "loops.h"
2+
#include <stdbool.h>
3+
4+
unsigned int while_loop(unsigned int n) {
5+
unsigned int i = 0;
6+
while (i < n) {
7+
i = i + 1;
8+
if (n % i == 37U)
9+
return 1;
10+
else if (i == 50U)
11+
return 2U;
12+
}
13+
return 0U;
14+
}
15+
16+
int do_while_loop(int n) {
17+
int i = 0;
18+
do {
19+
i = i + 1;
20+
if (n % i == 37)
21+
return 1;
22+
else if (i == 50)
23+
return 2;
24+
} while (i < n);
25+
return 0;
26+
}
27+
28+
int continue_break(int n) {
29+
int i = n, res = 0;
30+
do {
31+
res += i;
32+
if (res > 100) {
33+
break;
34+
}
35+
if (i < 20) {
36+
continue;
37+
}
38+
} while (false);
39+
return res;
40+
}
41+
42+
int goto_keyword(unsigned int a) {
43+
unsigned int sum = 0;
44+
do {
45+
if (a == 15) {
46+
goto RET;
47+
}
48+
sum += a;
49+
a++;
50+
} while (a < 22);
51+
if (sum > 1000) {
52+
return 1;
53+
}
54+
return 2;
55+
RET: return -1;
56+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef C_EXAMPLE_LOOPS_H
2+
#define C_EXAMPLE_LOOPS_H
3+
4+
unsigned int while_loop(unsigned int n);
5+
6+
int do_while_loop(int n);
7+
8+
int continue_break(int n);
9+
10+
int goto_keyword(unsigned int a);
11+
12+
#endif //C_EXAMPLE_LOOPS_H

integration-tests/c-example/lib/memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "stdlib.h"
2-
#include "string.h"
1+
#include <stdlib.h>
2+
#include <string.h>
33

44
int out_of_bound_access_to_heap(int num) {
55
int *p = calloc(5, sizeof(int));

integration-tests/c-example/lib/multi_arrays.c

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,10 @@
11
#include "multi_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_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(const 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
}
Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
1-
int kek(int a[1][2]);
1+
#ifndef C_EXAMPLE_MULTI_ARRAYS_H
2+
#define C_EXAMPLE_MULTI_ARRAYS_H
23

3-
int sumSign(int a[2][2]);
4+
#include <stddef.h>
5+
6+
struct MyStructMult {
7+
int a[2][3][2];
8+
};
9+
10+
struct IntArray {
11+
int ints[2][5];
12+
};
13+
14+
struct PointStruct {
15+
int x;
16+
int y;
17+
};
18+
19+
int get_elem(int a[1][2]);
20+
21+
int sum_sign(int a[2][2]);
22+
23+
int sum_sign_1d_small(const int a[9]);
424

525
int value(int a[2][3]);
6-
int value2(int (* a)[3]);
7-
int some_method(int ** pointer2d);
26+
27+
int value2(int (*a)[3]);
28+
29+
int value3(int a[]);
30+
31+
int some_method(int **pointer2d);
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();
42+
43+
#endif //C_EXAMPLE_MULTI_ARRAYS_H

0 commit comments

Comments
 (0)