Kirk Rader  1.0-SNAPSHOT
IdentityTest.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.assertTrue;
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 import us.rader.tt.formula.Variable;
30 
31 /**
32  * Unit tests for us.rader.tt.formula.Identity
33  */
34 public class IdentityTest {
35 
36  /**
37  * Unit test for {@link Formula#toTruthTable}.
38  */
39  @Test
40  public void missingEqualsTest() {
41 
42  try {
43 
44  final Formula formula = Formula.parseFormula(":x:Fx");
45  formula.toTruthTable(0);
46  fail("IOException expected");
47 
48  } catch (@SuppressWarnings("unused") final IOException e) {
49 
50  // success
51 
52  }
53 
54  }
55 
56  /**
57  * Unit test for {@link Expression#replaceVariable}.
58  *
59  * @throws Exception
60  * Thrown if an unexpected error occurs.
61  */
62  @Test
63  public void replaceVariableTest() throws Exception {
64 
65  final Formula identity1 = Formula.parseFormula(":x:(Fx->Gx)=y");
66  final Variable boundVariable = new Variable("y");
67  final Variable freeVariable = new Variable("a");
68  final Expression identity2 = identity1.replaceVariable(boundVariable, freeVariable);
69  assertEquals(":x:(Fx->Gx)=a", identity2.toString());
70 
71  }
72 
73  /**
74  * Unit test for {@link Formula#toDigraph}.
75  *
76  * @throws Exception
77  * Thrown if an unexpected error occurs.
78  */
79  @Test
80  public void toDigraphTest() throws Exception {
81 
82  final Formula formula = Formula.parseFormula(":x:Fx=a");
83  final String digraph = formula.toDigraph(0);
84  assertTrue(digraph.startsWith("digraph"));
85 
86  }
87 
88  /**
89  * Unit test for {@link Formula#toTruthTable}.
90  *
91  * @throws Exception
92  * Thrown if an unexpected error occurs.
93  */
94  @Test
95  public void toTruthTableTest() throws Exception {
96 
97  try {
98 
99  final Formula formula = Formula.parseFormula(":x:Fx=a");
100  formula.toTruthTable(0);
101  fail("IllegalArgumentException expected");
102 
103  } catch (@SuppressWarnings("unused") final IllegalArgumentException e) {
104 
105  // success
106 
107  }
108 
109  }
110 
111 }
Unit tests for us.rader.tt.formula.Identity.
Demonstrate object-oriented design and implementation using a simple Java class library.
void toDigraphTest()
Unit test for Formula#toDigraph.
A variable (lower-case alphabetic character) of the monadic predicate calculus.
Definition: Variable.java:27
final String toDigraph(final int indent)
Definition: Formula.java:505
final String toTruthTable(final int indent)
Definition: Formula.java:550
void toTruthTableTest()
Unit test for Formula#toTruthTable.
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.
Objects with unique Graphviz node names.
Definition: Expression.java:32
void replaceVariableTest()
Unit test for Expression#replaceVariable.
abstract Expression replaceVariable(Variable boundVariable, Expression factor)
Replace boundVariable with factor everywhere in this Expression.
A formula of the monadic predicate calculus.
Definition: Formula.java:51
void missingEqualsTest()
Unit test for Formula#toTruthTable.