Kirk Rader  1.0-SNAPSHOT
DescriptionTest.java
Go to the documentation of this file.
1 /*
2  * Copyright 2016 Kirk Rader
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.fail;
21 
22 import java.io.IOException;
23 
24 import org.junit.Test;
25 
27 import us.rader.tt.formula.Formula;
28 import us.rader.tt.formula.Variable;
30 
31 /**
32  * Unit tests for us.rader.tt.formula.Description
33  */
34 public class DescriptionTest {
35 
36  /**
37  * Unit test for {@link VariableBindingOperator#instantiate}.
38  *
39  * @throws Exception
40  * Thrown if an unexpected error occurs.
41  */
42  @Test
43  public void instantiateTest() throws Exception {
44 
46  final Variable freeVariable = new Variable("a");
47  final Formula formula2 = formula1.instantiate(freeVariable);
48  assertEquals("(Fa->Ga)", formula2.toString());
49 
50  }
51 
52  /**
53  * Unit test for {@link Formula#parseFormula}.
54  */
55  @Test
56  public void parseFormulaTest() {
57 
58  try {
59 
60  Formula.parseFormula(":x:Fx");
61  fail("IOException e");
62 
63  } catch (@SuppressWarnings("unused") final IOException e) {
64 
65  // succcess
66 
67  }
68 
69  }
70 
71  /**
72  * Unit test for {@link Expression#replaceVariable}.
73  *
74  * @throws Exception
75  * Thrown if an unexpected error occurs.
76  */
77  @Test
78  public void replaceVariableTest() throws Exception {
79 
80  final Expression formula1 = Expression.parseFactor(":x:(Fx->Gy)");
81  final Variable boundVariable = new Variable("y");
82  final Variable freeVariable = new Variable("a");
83  final Expression formula2 = formula1.replaceVariable(boundVariable, freeVariable);
84  assertEquals(":x:(Fx->Ga)", formula2.toString());
85 
86  }
87 
88  /**
89  * Unit test for {@link Expression#toLaTeX()}.
90  *
91  * @throws Exception
92  * Thrown if an unexpected error occurs.
93  */
94  @Test
95  public void toLaTeXTest() throws Exception {
96 
97  final Expression description = Expression.parseFactor(":x:Fx");
98  final String latex = description.toLaTeX();
99  assertEquals("\\riota x Fx", latex);
100 
101  }
102 
103 }
Demonstrate object-oriented design and implementation using a simple Java class library.
static Expression parseFactor(final BufferedReader reader)
Parse the next Expression from the given buffered input stream.
A variable (lower-case alphabetic character) of the monadic predicate calculus.
Definition: Variable.java:27
static Formula parseFormula(final BufferedReader reader)
Parse the next Formula from the given buffered input stream.
Definition: Formula.java:112
void toLaTeXTest()
Unit test for Expression#toLaTeX().
Processor for well-formed formulas of the monadic predicate calculus.
void replaceVariableTest()
Unit test for Expression#replaceVariable.
Objects with unique Graphviz node names.
Definition: Expression.java:32
final Formula instantiate(final Expression factor)
Return the Formula that results from instantiating this operator.
abstract Expression replaceVariable(Variable boundVariable, Expression factor)
Replace boundVariable with factor everywhere in this Expression.
void parseFormulaTest()
Unit test for Formula#parseFormula.
void instantiateTest()
Unit test for VariableBindingOperator#instantiate.
A formula of the monadic predicate calculus.
Definition: Formula.java:51
Unit tests for us.rader.tt.formula.Description.