forked from VU-Programming/copp-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testadvanced6.c
55 lines (43 loc) · 891 Bytes
/
testadvanced6.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <string.h>
#include "ijvm.h"
#include "testutil.h"
void run_calc_inp(char *input, char *expected)
{
int res = init_ijvm("files/advanced/SimpleCalc.ijvm");
assert(res != -1);
char buf[128];
FILE *f = tmpfile();
fprintf(f, "%s", input);
rewind(f);
set_input(f);
FILE *out_file = tmpfile();
set_output(out_file);
// Run program
run();
rewind(out_file);
memset(buf, '\0', 128);
fread(buf, 1, 127, out_file);
// Compare output
assert(strncmp(buf, expected, strlen(expected)) == 0);
destroy_ijvm();
}
void test_rec_1()
{
run_calc_inp("2!?.", "2\n");
}
void test_rec_2()
{
run_calc_inp("7!?.", "5040\n");
}
void test_rec_3()
{
run_calc_inp("8!?.", "40320\n");
}
int main()
{
RUN_TEST(test_rec_1);
RUN_TEST(test_rec_2);
RUN_TEST(test_rec_3);
return END_TEST();
}