Kirk Rader  1.0-SNAPSHOT
ExpressionTest.java
Go to the documentation of this file.
1 /*
2  * Copyright 2016 Kirk Radert
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package us.rader.tt.formula.test;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.fail;
22 
23 import java.io.IOException;
24 
25 import org.junit.Test;
26 
28 import us.rader.tt.formula.Formula;
29 
30 /**
31  * Unit tests for us.rader.tt.formula.Expression
32  */
33 public class ExpressionTest {
34 
35  /**
36  * @throws Exception
37  * Thrown if an unexpected error occurs.
38  */
39  @Test
40  public void equalToSameExpressionTest() throws Exception {
41 
42  assertEquals(Expression.parseFactor(":x:Fx"),
43  Expression.parseFactor(" :x: Fx "));
44 
45  }
46 
47  /**
48  * @throws Exception
49  * Thrown if an unexpected error occurs.
50  */
51  @Test
52  public void notEqualToNonExpressionTest() throws Exception {
53 
54  assertFalse(Expression.parseFactor(":x:Fx").equals(new Object()));
55 
56  }
57 
58  /**
59  * @throws Exception
60  * Thrown if an unexpected error occurs.
61  */
62  @Test
63  public void notEqualToNullTest() throws Exception {
64 
65  assertFalse(Expression.parseFactor(":x:Fx").equals(null));
66 
67  }
68 
69  /**
70  * Unit test for invalid bound-variable syntax.
71  */
72  @Test
73  public void parseBadBoundVariableTest() {
74 
75  try {
76 
77  Formula.parseFormula("[P]FP");
78  fail("IOException expected");
79 
80  } catch (@SuppressWarnings("unused") final IOException e) {
81 
82  // success
83 
84  }
85  }
86 
87  /**
88  * Unit test for invalid factor.
89  */
90  @Test
91  public void parseBadFactorTest() {
92 
93  try {
94 
96  fail("IOException expected");
97 
98  } catch (@SuppressWarnings("unused") final IOException e) {
99 
100  // success
101 
102  }
103  }
104 
105  /**
106  * Unit test for empty factor.
107  */
108  @Test
109  public void parseEmptyTest() {
110 
111  try {
112 
113  Expression.parseFactor(" ");
114  fail("IOException expected");
115 
116  } catch (@SuppressWarnings("unused") final IOException e) {
117 
118  // success
119 
120  }
121  }
122 
123  /**
124  * Unit test for mismatched delimiters.
125  */
126  @Test
128 
129  try {
130 
131  Formula.parseFormula("[x}Fx");
132  fail("IOException expected");
133 
134  } catch (@SuppressWarnings("unused") final IOException e) {
135 
136  // success
137 
138  }
139  }
140 
141  /**
142  * Unit test for missing bound variable.
143  */
144  @Test
146 
147  try {
148 
149  Formula.parseFormula(" [ ");
150  fail("IOException expected");
151 
152  } catch (@SuppressWarnings("unused") final IOException e) {
153 
154  // success
155 
156  }
157  }
158 
159 }
Demonstrate object-oriented design and implementation using a simple Java class library.
void parseBadFactorTest()
Unit test for invalid factor.
void parseMismatchedDelimitersTest()
Unit test for mismatched delimiters.
static Expression parseFactor(final BufferedReader reader)
Parse the next Expression from the given buffered input stream.
final boolean equals(final Object obj)
Base equality on the string representation of a formula.
static Formula parseFormula(final BufferedReader reader)
Parse the next Formula from the given buffered input stream.
Definition: Formula.java:112
Processor for well-formed formulas of the monadic predicate calculus.
void parseBadBoundVariableTest()
Unit test for invalid bound-variable syntax.
Objects with unique Graphviz node names.
Definition: Expression.java:32
void parseMissingBoundVariableTest()
Unit test for missing bound variable.
A formula of the monadic predicate calculus.
Definition: Formula.java:51
void parseEmptyTest()
Unit test for empty factor.
Unit tests for us.rader.tt.formula.Expression.