mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 17:04:42 -04:00
added d-flipflop detection to DetermineJKStateMachine.java
This commit is contained in:
parent
edd1b8e4cc
commit
2e6f4fe6a5
@ -1,9 +1,6 @@
|
|||||||
package de.neemann.digital.analyse;
|
package de.neemann.digital.analyse;
|
||||||
|
|
||||||
import de.neemann.digital.analyse.expression.Constant;
|
import de.neemann.digital.analyse.expression.*;
|
||||||
import de.neemann.digital.analyse.expression.Expression;
|
|
||||||
import de.neemann.digital.analyse.expression.ExpressionException;
|
|
||||||
import de.neemann.digital.analyse.expression.Operation;
|
|
||||||
import de.neemann.digital.analyse.expression.format.FormatToExpression;
|
import de.neemann.digital.analyse.expression.format.FormatToExpression;
|
||||||
import de.neemann.digital.analyse.expression.format.FormatterException;
|
import de.neemann.digital.analyse.expression.format.FormatterException;
|
||||||
import de.neemann.digital.lang.Lang;
|
import de.neemann.digital.lang.Lang;
|
||||||
@ -23,6 +20,7 @@ import static de.neemann.digital.analyse.expression.Operation.or;
|
|||||||
public class DetermineJKStateMachine {
|
public class DetermineJKStateMachine {
|
||||||
private Expression j = null;
|
private Expression j = null;
|
||||||
private Expression nk = null;
|
private Expression nk = null;
|
||||||
|
private boolean isDFF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance
|
* Creates a new instance
|
||||||
@ -33,7 +31,7 @@ public class DetermineJKStateMachine {
|
|||||||
* @throws FormatterException FormatterException
|
* @throws FormatterException FormatterException
|
||||||
*/
|
*/
|
||||||
public DetermineJKStateMachine(String name, Expression e) throws ExpressionException, FormatterException {
|
public DetermineJKStateMachine(String name, Expression e) throws ExpressionException, FormatterException {
|
||||||
String notName = "¬" + name;
|
String notName = FormatToExpression.FORMATTER_UNICODE.format(Not.not(new Variable(name)));
|
||||||
|
|
||||||
boolean wasK = false;
|
boolean wasK = false;
|
||||||
boolean wasJ = false;
|
boolean wasJ = false;
|
||||||
@ -77,6 +75,7 @@ public class DetermineJKStateMachine {
|
|||||||
if (wasK) nk = Constant.ONE;
|
if (wasK) nk = Constant.ONE;
|
||||||
else nk = Constant.ZERO;
|
else nk = Constant.ZERO;
|
||||||
}
|
}
|
||||||
|
isDFF = !wasJ && !wasK;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Iterable<Expression> getOrs(Expression e) {
|
private Iterable<Expression> getOrs(Expression e) {
|
||||||
@ -114,6 +113,16 @@ public class DetermineJKStateMachine {
|
|||||||
return not(nk);
|
return not(nk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if it is logical a D flipflop.
|
||||||
|
* This means that K = not(J).
|
||||||
|
*
|
||||||
|
* @return true if it is logical a D flipflop
|
||||||
|
*/
|
||||||
|
public boolean isDFF() {
|
||||||
|
return isDFF;
|
||||||
|
}
|
||||||
|
|
||||||
private static final class AsIterable<T> implements Iterable<T> {
|
private static final class AsIterable<T> implements Iterable<T> {
|
||||||
private final T item;
|
private final T item;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class DetermineJKStateMachineTest extends TestCase {
|
|||||||
DetermineJKStateMachine jk = new DetermineJKStateMachine("a", e);
|
DetermineJKStateMachine jk = new DetermineJKStateMachine("a", e);
|
||||||
assertEquals(toStr(notb), toStr(jk.getJ()));
|
assertEquals(toStr(notb), toStr(jk.getJ()));
|
||||||
assertEquals(toStr(notc), toStr(jk.getK()));
|
assertEquals(toStr(notc), toStr(jk.getK()));
|
||||||
|
assertFalse(jk.isDFF());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String toStr(Expression expression) throws FormatterException {
|
private String toStr(Expression expression) throws FormatterException {
|
||||||
@ -54,7 +54,7 @@ public class DetermineJKStateMachineTest extends TestCase {
|
|||||||
DetermineJKStateMachine jk = new DetermineJKStateMachine("a", e);
|
DetermineJKStateMachine jk = new DetermineJKStateMachine("a", e);
|
||||||
assertEquals("(b ∧ c) ∨ ¬b", toStr(jk.getJ()));
|
assertEquals("(b ∧ c) ∨ ¬b", toStr(jk.getJ()));
|
||||||
assertEquals("¬((b ∧ c) ∨ c)", toStr(jk.getK()));
|
assertEquals("¬((b ∧ c) ∨ c)", toStr(jk.getK()));
|
||||||
|
assertFalse(jk.isDFF());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimple3() throws Exception {
|
public void testSimple3() throws Exception {
|
||||||
@ -63,6 +63,7 @@ public class DetermineJKStateMachineTest extends TestCase {
|
|||||||
DetermineJKStateMachine jk = new DetermineJKStateMachine("a", e);
|
DetermineJKStateMachine jk = new DetermineJKStateMachine("a", e);
|
||||||
assertEquals("1", toStr(jk.getJ()));
|
assertEquals("1", toStr(jk.getJ()));
|
||||||
assertEquals("1", toStr(jk.getK()));
|
assertEquals("1", toStr(jk.getK()));
|
||||||
|
assertFalse(jk.isDFF());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimple4() throws Exception {
|
public void testSimple4() throws Exception {
|
||||||
@ -71,6 +72,16 @@ public class DetermineJKStateMachineTest extends TestCase {
|
|||||||
DetermineJKStateMachine jk = new DetermineJKStateMachine("a", e);
|
DetermineJKStateMachine jk = new DetermineJKStateMachine("a", e);
|
||||||
assertEquals("0", toStr(jk.getJ()));
|
assertEquals("0", toStr(jk.getJ()));
|
||||||
assertEquals("0", toStr(jk.getK()));
|
assertEquals("0", toStr(jk.getK()));
|
||||||
|
assertFalse(jk.isDFF());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSimpleD() throws Exception {
|
||||||
|
Expression e = or(and(a, b), and(nota, notb));
|
||||||
|
|
||||||
|
DetermineJKStateMachine jk = new DetermineJKStateMachine("c", e);
|
||||||
|
assertEquals("(¬a ∧ ¬b) ∨ (a ∧ b)", toStr(jk.getJ()));
|
||||||
|
assertEquals("(¬a ∧ ¬b) ∨ (a ∧ b)", toStr(jk.getNK()));
|
||||||
|
assertTrue(jk.isDFF());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user