-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseTest.java
More file actions
41 lines (37 loc) · 1.5 KB
/
ParseTest.java
File metadata and controls
41 lines (37 loc) · 1.5 KB
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
import org.junit.Test;
import regex.Atom;
import regex.Parser;
import java.util.ArrayList;
import static org.junit.Assert.assertEquals;
public class ParseTest {
@Test
public void basicTest() {
String s1 = "(a|b)*c";
String s2 = "abc";
String s3 = "a|b|c";
ArrayList<Atom> list = Parser.insertExplicitConcatOperator(s1);
ArrayList<Atom> postfix = Parser.toPostfix(list);
assertEquals(list.size(), 8);
assertEquals(postfix.toString(), "[a, b, |, *, c, &]");
list = Parser.insertExplicitConcatOperator(s2);
postfix = Parser.toPostfix(list);
assertEquals(list.size(), 5);
assertEquals(postfix.toString(), "[a, b, &, c, &]");
list = Parser.insertExplicitConcatOperator(s3);
postfix = Parser.toPostfix(list);
assertEquals(list.size(), 5);
assertEquals(postfix.toString(), "[a, b, |, c, |]");
}
@Test
public void complexTest() {
String s1 = "\\d{1,5}|.c";
String s2 = "ac\\D?d";
String s3 = ".+(cc|a)";
ArrayList<Atom> postfix = Parser.toPostfix(Parser.insertExplicitConcatOperator(s1));
assertEquals(postfix.toString(), "[\\d, {1,5}, ., c, &, |]");
postfix = Parser.toPostfix(Parser.insertExplicitConcatOperator(s2));
assertEquals(postfix.toString(), "[a, c, &, \\D, ?, &, d, &]");
postfix = Parser.toPostfix(Parser.insertExplicitConcatOperator(s3));
assertEquals(postfix.toString(), "[., +, c, c, &, a, |, &]");
}
}