aboutsummaryrefslogtreecommitdiff
path: root/tests/test_fst.c
blob: 5f48f6cc23ea774fb14fe6645c7a2f142b75836e (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
90
91
92
93
94
95
96
97
98
99
#include "inc.h"
#include "../src/fst.h"

static bool test_cube_to_fst_to_cube(Cube *c);

static bool test_cube_to_fst_to_cube_solved();
static bool test_cube_to_fst_to_cube_unsolved();

static Tester test[] = {
	test_cube_to_fst_to_cube_solved,
	test_cube_to_fst_to_cube_unsolved,
	NULL
};

static char *name[] = {
	"Cube to FST to cube (solved)",
	"Cube to FST to cube (unsolved)",
};

static bool
test_cube_to_fst_to_cube(Cube *c)
{
	Cube d;
	FstCube fst;

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

	if (!equal(c, &d)) {
		printf("Cubes are different:\n\n");
		printf("Cube 1:\n");
		print_cube(c);
		printf("\nCube 2:\n");
		print_cube(&d);
		printf("\n");
		return false;
	}

	return true;
}

static bool
test_cube_to_fst_to_cube_solved()
{
	Cube c;

	make_solved(&c);
	return test_cube_to_fst_to_cube(&c);
}

static bool
test_cube_to_fst_to_cube_unsolved()
{
	bool b;
	int i;
	Alg *a;
	Cube c;
	char *algs[] = {
		"U2 R2 U2 R2 U2",
		"U2 F2 R2 B2 U2 D2 F2 L2 B2",
		"RUR'URU2R'",
		"L2 D R U2 B2 L",
		"R'U'F",
		"F2 U' R2 D' B2 D2 R2 D2 R2 U' F L' U' R B F2 R B' D2",
		"D L2 F2 R2 D R2 U L2 U' B2 D L' F2 U2 B' L D' U' R' B2 F2",
		"F' L2 F' D' R F2 L U L' D2 R2 F2 D2 R2 B' L2 B2 U2 F D2 B",
		NULL,
	};

	for (i = 0; algs[i] != NULL; i++) {
		make_solved(&c);
		a = new_alg(algs[i]);
		apply_alg(a, &c);
		b = test_cube_to_fst_to_cube(&c);
		free_alg(a);
		if (!b) {
			printf("Cube to FST to cube failed with alg %s\n",
			    algs[i]);
			return false;
		}
	}
	return true;
}

void test_fst_all() {
	int i;

	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 tests passed.\n\n");
}

Generated with cgit - Back to sebastiano.tronto.net