aboutsummaryrefslogtreecommitdiff
path: root/tests/fst_pre_init_tests.c
blob: 6b7a44014e93f926fe69a7f1878091a78160689d (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "fst_test_util.h"

static bool cube_to_fst_to_cube_testcase(Cube *c, Alg *a);
static bool fst_is_consistent_testcase(Cube *c, Alg *a);

static bool fst_is_consistent_test();
static bool cube_to_fst_to_cube_test();

static Tester test[] = {
	fst_is_consistent_test,
	cube_to_fst_to_cube_test,
	NULL
};

static char *name[] = {
	"Consistency of FST (converted from cube)",
	"Cube to FST to cube",
};

static bool
fst_is_consistent_testcase(Cube *c, Alg *a)
{
	FstCube fst_uf, fst_fr, fst_rd;
	Cube c_fr, c_rd;
	bool consistent_fr, consistent_rd;

	copy_cube(c, &c_fr);
	apply_trans(fr, &c_fr);

	copy_cube(c, &c_rd);
	apply_trans(rd, &c_rd);

	fst_uf = cube_to_fst(c);
	fst_fr = cube_to_fst(&c_fr);
	fst_rd = cube_to_fst(&c_rd);

	consistent_fr = fst_uf.fr_eofb == fst_fr.uf_eofb &&
			fst_uf.fr_eposepe == fst_fr.uf_eposepe &&
			fst_uf.fr_coud == fst_fr.uf_coud;

	consistent_rd = fst_uf.rd_eofb == fst_rd.uf_eofb &&
			fst_uf.rd_eposepe == fst_rd.uf_eposepe &&
			fst_uf.rd_coud == fst_rd.uf_coud;

	return consistent_fr && consistent_rd;
}

static bool
cube_to_fst_to_cube_testcase(Cube *c, Alg *a)
{
	Cube d;
	FstCube fst;

	fst = cube_to_fst(c);
	fst_to_cube(fst, &d);

	return equal_and_log(c, &d);;
}

static bool
cube_to_fst_to_cube_test()
{
	return try_all_str(
	    cube_to_fst_to_cube_testcase, "Cube to FST to cube failed");
}

static bool
fst_is_consistent_test()
{
	return try_all_str(
	    fst_is_consistent_testcase, "FST from cube not consistent");
}

void fst_pre_init_testall() {
	int i;

	init_env();
	init_trans();

	for (i = 0; test[i] != NULL; i++) {
		printf("Test: %s\n", name[i]);
		if (!test[i]()) {
			printf("Failed!\n");
			exit(1);
		}
		printf("Passed.\n\n");
	}
	printf("All FST pre-init tests passed.\n\n");
}

Generated with cgit - Back to sebastiano.tronto.net