forked from DavidMatuszek/SentenceGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrammarTest.java
More file actions
67 lines (56 loc) · 1.8 KB
/
GrammarTest.java
File metadata and controls
67 lines (56 loc) · 1.8 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
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
package sentenceGenerator;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
/**
* @author <Rajveer Parikh>
*/
public class GrammarTest {
Grammar testGrammar;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
testGrammar = new Grammar();
}
/**
* Test method for {@link sentenceGenerator.Grammar#Grammar()}.
*/
// @Test
// public final void testGrammar() {
// fail("Not yet implemented");
// }
/**
* Test method for {@link sentenceGenerator.Grammar#addRule(java.lang.String)}.
*/
@Test
public final void testAddRule() {
testGrammar.addRule("<adjectives> ::= <adjective> | <adjective> <adjectives>");
ListOfDefinitions listDefTest = testGrammar.getDefinitions("<adjectives>");
SingleDefinition def1 = new SingleDefinition();
SingleDefinition def2 = new SingleDefinition();
def1.add("<adjective>");
def2.add("<adjective>");
def2.add("<adjectives>");
assertEquals (def1, listDefTest.get(0));
assertEquals(def2, listDefTest.get(1));
}
/**
* Test method for {@link sentenceGenerator.Grammar#getDefinitions(java.lang.String)}.
*/
@Test
public final void testGetDefinitions() {
testGrammar.addRule("<adjectives> ::= <adjective> | <adjective> <adjectives>");
ListOfDefinitions listDefTest = testGrammar.getDefinitions("<adjectives>");
ListOfDefinitions expected = new ListOfDefinitions();
SingleDefinition def1 = new SingleDefinition();
SingleDefinition def2 = new SingleDefinition();
def1.add("<adjective>");
def2.add("<adjective>");
def2.add("<adjectives>");
expected.add(def1);
expected.add(def2);
assertEquals(expected, listDefTest);
}
}