-
Notifications
You must be signed in to change notification settings - Fork 1
/
scramble_parser.rs
131 lines (113 loc) · 4.64 KB
/
scramble_parser.rs
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// Move Parser Tests
//
use cubesim::{parse_scramble, simplify_moves};
use cubesim::prelude::{Move::*, MoveVariant::*};
#[test]
fn test_basic_moves() {
assert_eq!(parse_scramble(String::from("U"))[0], U(Standard));
assert_eq!(parse_scramble(String::from("F"))[0], F(Standard));
assert_eq!(parse_scramble(String::from("R"))[0], R(Standard));
assert_eq!(parse_scramble(String::from("D"))[0], D(Standard));
assert_eq!(parse_scramble(String::from("L"))[0], L(Standard));
assert_eq!(parse_scramble(String::from("B"))[0], B(Standard));
assert_eq!(parse_scramble(String::from("x"))[0], X(Standard));
assert_eq!(parse_scramble(String::from("y"))[0], Y(Standard));
assert_eq!(parse_scramble(String::from("z"))[0], Z(Standard));
}
#[test]
fn test_double_moves() {
assert_eq!(parse_scramble(String::from("U2"))[0], U(Double));
assert_eq!(parse_scramble(String::from("F2"))[0], F(Double));
assert_eq!(parse_scramble(String::from("R2"))[0], R(Double));
assert_eq!(parse_scramble(String::from("D2"))[0], D(Double));
assert_eq!(parse_scramble(String::from("L2"))[0], L(Double));
assert_eq!(parse_scramble(String::from("B2"))[0], B(Double));
assert_eq!(parse_scramble(String::from("x2"))[0], X(Double));
assert_eq!(parse_scramble(String::from("y2"))[0], Y(Double));
assert_eq!(parse_scramble(String::from("z2"))[0], Z(Double));
}
#[test]
fn test_inverse_moves() {
assert_eq!(parse_scramble(String::from("U'"))[0], U(Inverse));
assert_eq!(parse_scramble(String::from("F'"))[0], F(Inverse));
assert_eq!(parse_scramble(String::from("R'"))[0], R(Inverse));
assert_eq!(parse_scramble(String::from("D'"))[0], D(Inverse));
assert_eq!(parse_scramble(String::from("L'"))[0], L(Inverse));
assert_eq!(parse_scramble(String::from("B'"))[0], B(Inverse));
assert_eq!(parse_scramble(String::from("x'"))[0], X(Inverse));
assert_eq!(parse_scramble(String::from("y'"))[0], Y(Inverse));
assert_eq!(parse_scramble(String::from("z'"))[0], Z(Inverse));
}
#[test]
fn test_long_scramble() {
assert_eq!(parse_scramble(String::from("R U R' U' R' F R2 U' R' U' R U R' F'")), vec![
R(Standard),
U(Standard),
R(Inverse),
U(Inverse),
R(Inverse),
F(Standard),
R(Double),
U(Inverse),
R(Inverse),
U(Inverse),
R(Standard),
U(Standard),
R(Inverse),
F(Inverse),
]);
}
#[test]
fn test_wide_moves() {
assert_eq!(parse_scramble(String::from("Rw 3Fw 5Bw' 3Lw2")), vec![
Rw(2, Standard),
Fw(3, Standard),
Bw(5, Inverse),
Lw(3, Double)
]);
}
#[test]
fn test_simplify_unsimplifiable_moves() {
assert_eq!(simplify_moves(&parse_scramble(String::from("x2"))), vec![X(Double)]);
assert_eq!(simplify_moves(&parse_scramble(String::from(""))), vec![]);
assert_eq!(simplify_moves(&parse_scramble(String::from("x y z"))),
vec![X(Standard), Y(Standard), Z(Standard)]);
}
#[test]
fn test_simplify_standard_and_inverse_cancel() {
assert_eq!(simplify_moves(&parse_scramble(String::from("U U'"))), vec![]);
assert_eq!(simplify_moves(&parse_scramble(String::from("R' R"))), vec![]);
}
#[test]
fn test_simplify_two_doubles_cancel() {
assert_eq!(simplify_moves(&parse_scramble(String::from("D2 D2"))), vec![]);
assert_eq!(simplify_moves(&parse_scramble(String::from("2Lw 2Lw"))), vec![]);
}
#[test]
fn test_simplify_double_and_standard_becomes_inverse() {
assert_eq!(simplify_moves(&parse_scramble(String::from("L2 L"))), vec![L(Inverse)]);
assert_eq!(simplify_moves(&parse_scramble(String::from("F F2"))), vec![F(Inverse)]);
}
#[test]
fn test_simplify_double_and_inverse_becomes_standard() {
assert_eq!(simplify_moves(&parse_scramble(String::from("L2 L'"))), vec![L(Standard)]);
assert_eq!(simplify_moves(&parse_scramble(String::from("F' F2"))), vec![F(Standard)]);
}
#[test]
fn test_simplify_two_singles_becomes_double() {
assert_eq!(simplify_moves(&parse_scramble(String::from("B B"))), vec![B(Double)]);
assert_eq!(simplify_moves(&parse_scramble(String::from("Uw Uw"))), vec![Uw(2, Double)]);
assert_eq!(simplify_moves(&parse_scramble(String::from("B' B'"))), vec![B(Double)]);
assert_eq!(simplify_moves(&parse_scramble(String::from("Uw' Uw'"))), vec![Uw(2, Double)]);
}
#[test]
fn test_simplify_long() {
assert_eq!(simplify_moves(&parse_scramble(String::from("B B2 B' R B2 B' R2 R' F2 R' R'"))),
vec![B(Double), R(Standard), B(Standard), R(Standard), F(Double), R(Double)]);
}
#[test]
fn test_simplify_complex() {
assert_eq!(simplify_moves(&parse_scramble(String::from("R U2 R' R U2 F F' U2 B2 B2 U' U2 U R'"))),
vec![])
}