mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-22 11:55:15 -04:00
refactoring of expression format setting
This commit is contained in:
parent
5a79b016e1
commit
36e0b5fea3
@ -6,10 +6,10 @@
|
||||
package de.neemann.digital.analyse.expression.format;
|
||||
|
||||
import de.neemann.digital.analyse.expression.*;
|
||||
import de.neemann.digital.core.element.Keys;
|
||||
import de.neemann.digital.draw.graphics.text.formatter.PlainTextFormatter;
|
||||
import de.neemann.digital.draw.graphics.text.text.ExpressionToText;
|
||||
|
||||
import java.util.Objects;
|
||||
import de.neemann.digital.gui.Settings;
|
||||
|
||||
import static de.neemann.digital.analyse.expression.Not.not;
|
||||
import static de.neemann.digital.analyse.expression.Operation.and;
|
||||
@ -22,48 +22,46 @@ import static de.neemann.digital.analyse.expression.Variable.v;
|
||||
* At first the expression is converted to a {@link de.neemann.digital.draw.graphics.text.text.Text} instance and then
|
||||
* formatted to a string by the {@link PlainTextFormatter}.
|
||||
*/
|
||||
public final class FormatToExpression implements Formatter {
|
||||
public enum FormatToExpression implements Formatter {
|
||||
|
||||
/**
|
||||
* Creates a string compatible to Java
|
||||
*/
|
||||
public static final FormatToExpression FORMATTER_JAVA = new FormatToExpression("||", "&&", "^", "!", "false", "true", "=");
|
||||
JAVA("||", "&&", "^", "!", "false", "true", "="),
|
||||
/**
|
||||
* Creates a string compatible to Derive
|
||||
*/
|
||||
public static final FormatToExpression FORMATTER_DERIVE = new FormatToExpression("OR", "AND", "XOR", "NOT ", "false", "true", "=");
|
||||
DERIVE("OR", "AND", "XOR", "NOT ", "false", "true", "="),
|
||||
/**
|
||||
* Creates a string compatible to WinCUPL
|
||||
*/
|
||||
public static final FormatToExpression FORMATTER_CUPL = new FormatToExpression("#", "&", "$", "!", "'b'0", "'b'1", "=").setKeepVars();
|
||||
CUPL("#", "&", "$", "!", "'b'0", "'b'1", "=", true),
|
||||
/**
|
||||
* Creates a string compatible to Logisim
|
||||
*/
|
||||
public static final FormatToExpression FORMATTER_LOGISIM = new FormatToExpression("+", "", "^", "~", "false", "true", "=");
|
||||
LOGISIM("+", "", "^", "~", "false", "true", "="),
|
||||
/**
|
||||
* Creates a unicode string
|
||||
*/
|
||||
public static final FormatToExpression FORMATTER_UNICODE = new FormatToExpression("\u2228", "\u2227", "\u22BB", "\u00AC", "0", "1", "=");
|
||||
UNICODE("\u2228", "\u2227", "\u22BB", "\u00AC", "0", "1", "="),
|
||||
/**
|
||||
* Creates a unicode string with no AND character
|
||||
*/
|
||||
public static final FormatToExpression FORMATTER_UNICODE_NOAND = new FormatToExpression("\u2228", "", "\u22BB", "\u00AC", "0", "1", "=");
|
||||
UNICODE_NOAND("\u2228", "", "\u22BB", "\u00AC", "0", "1", "="),
|
||||
/**
|
||||
* Creates a short string representation
|
||||
*/
|
||||
public static final FormatToExpression FORMATTER_SHORT = new FormatToExpression("+", "*", "^", "!", "0", "1", "=");
|
||||
SHORT("+", "*", "^", "!", "0", "1", "="),
|
||||
/**
|
||||
* Creates a short string representation
|
||||
*/
|
||||
public static final FormatToExpression FORMATTER_SHORTER = new FormatToExpression("+", "", "^", "!", "0", "1", "=");
|
||||
SHORTER("+", "", "^", "!", "0", "1", "="),
|
||||
/**
|
||||
* Creates a LaTeX representation
|
||||
*/
|
||||
public static final FormatToExpression FORMATTER_LATEX = new FormatToExpression("\\oder", "\\und", "\\xoder", "", "0", "1", "&=&");
|
||||
|
||||
LATEX("\\oder", "\\und", "\\xoder", "", "0", "1", "&=&");
|
||||
|
||||
private static final Expression TOSTRING_EXPR;
|
||||
private static FormatToExpression defaultFormat = FORMATTER_UNICODE;
|
||||
|
||||
static {
|
||||
Variable a = v("A");
|
||||
@ -72,16 +70,12 @@ public final class FormatToExpression implements Formatter {
|
||||
}
|
||||
|
||||
|
||||
private static FormatToExpression[] availFormats = new FormatToExpression[]{
|
||||
FORMATTER_UNICODE,
|
||||
FORMATTER_UNICODE_NOAND,
|
||||
FORMATTER_DERIVE,
|
||||
FORMATTER_JAVA,
|
||||
FORMATTER_CUPL,
|
||||
FORMATTER_LOGISIM,
|
||||
FORMATTER_SHORT,
|
||||
FORMATTER_SHORTER
|
||||
};
|
||||
/**
|
||||
* @return the default format
|
||||
*/
|
||||
public static FormatToExpression getDefaultFormat() {
|
||||
return Settings.getInstance().get(Keys.SETTINGS_EXPRESSION_FORMAT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a expression to a string.
|
||||
@ -91,16 +85,7 @@ public final class FormatToExpression implements Formatter {
|
||||
* @return the string representation
|
||||
*/
|
||||
public static String defaultFormat(Expression exp) {
|
||||
return defaultFormat.format(exp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default format
|
||||
*
|
||||
* @param defaultFormat the default format
|
||||
*/
|
||||
public static void setDefaultFormat(FormatToExpression defaultFormat) {
|
||||
FormatToExpression.defaultFormat = defaultFormat;
|
||||
return getDefaultFormat().format(exp);
|
||||
}
|
||||
|
||||
private final String orString;
|
||||
@ -110,9 +95,15 @@ public final class FormatToExpression implements Formatter {
|
||||
private final String equal;
|
||||
private final String xorString;
|
||||
private final String notString;
|
||||
private boolean keepVars;
|
||||
private final boolean keepVars;
|
||||
private String name;
|
||||
|
||||
private FormatToExpression(String orString, String andString, String xorString, String notString, String falseString, String trueString, String equal) {
|
||||
FormatToExpression(String orString, String andString, String xorString, String notString, String falseString, String trueString, String equal) {
|
||||
this(orString, andString, xorString, notString, falseString, trueString, equal, false);
|
||||
}
|
||||
|
||||
//CHECKSTYLE.OFF: ParameterNumber
|
||||
FormatToExpression(String orString, String andString, String xorString, String notString, String falseString, String trueString, String equal, boolean keepVars) {
|
||||
this.orString = orString;
|
||||
this.andString = andString;
|
||||
this.xorString = xorString;
|
||||
@ -120,28 +111,9 @@ public final class FormatToExpression implements Formatter {
|
||||
this.falseString = falseString;
|
||||
this.trueString = trueString;
|
||||
this.equal = equal;
|
||||
this.keepVars = keepVars;
|
||||
}
|
||||
|
||||
private FormatToExpression setKeepVars() {
|
||||
keepVars = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the available formats useful for screen representation
|
||||
*
|
||||
* @return list of available formats
|
||||
*/
|
||||
public static FormatToExpression[] getAvailFormats() {
|
||||
return availFormats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the default format
|
||||
*/
|
||||
public static FormatToExpression getDefaultFormat() {
|
||||
return defaultFormat;
|
||||
}
|
||||
//CHECKSTYLE.ON: ParameterNumber
|
||||
|
||||
/**
|
||||
* @return the OR string
|
||||
@ -175,8 +147,6 @@ public final class FormatToExpression implements Formatter {
|
||||
* @return the EQUAL string
|
||||
*/
|
||||
public String getEqual() {
|
||||
if (equal == null) // compatibility with old config files!!!
|
||||
return "=";
|
||||
return equal;
|
||||
}
|
||||
|
||||
@ -198,26 +168,9 @@ public final class FormatToExpression implements Formatter {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return format(TOSTRING_EXPR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
FormatToExpression that = (FormatToExpression) o;
|
||||
return Objects.equals(orString, that.orString)
|
||||
&& Objects.equals(andString, that.andString)
|
||||
&& Objects.equals(falseString, that.falseString)
|
||||
&& Objects.equals(trueString, that.trueString)
|
||||
&& Objects.equals(xorString, that.xorString)
|
||||
&& Objects.equals(notString, that.notString)
|
||||
&& Objects.equals(getEqual(), that.getEqual());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(orString, andString, falseString, trueString, xorString, notString, getEqual());
|
||||
if (name == null)
|
||||
name = format(TOSTRING_EXPR);
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ public class CuplExporter implements ExpressionExporter<CuplExporter> {
|
||||
out.append("\r\n/* sequential logic */\r\n");
|
||||
for (Map.Entry<String, Expression> c : builder.getRegistered().entrySet()) {
|
||||
out.append(c.getKey()).append(".D = ");
|
||||
breakLines(out, FormatToExpression.FORMATTER_CUPL.format(c.getValue()));
|
||||
breakLines(out, FormatToExpression.CUPL.format(c.getValue()));
|
||||
out.append(";\r\n");
|
||||
sequentialWritten(out, c.getKey());
|
||||
}
|
||||
@ -181,7 +181,7 @@ public class CuplExporter implements ExpressionExporter<CuplExporter> {
|
||||
out.append("\r\n/* combinatorial logic */\r\n");
|
||||
for (Map.Entry<String, Expression> c : builder.getCombinatorial().entrySet()) {
|
||||
out.append(c.getKey()).append(" = ");
|
||||
breakLines(out, FormatToExpression.FORMATTER_CUPL.format(c.getValue()));
|
||||
breakLines(out, FormatToExpression.CUPL.format(c.getValue()));
|
||||
out.append(";\r\n");
|
||||
}
|
||||
}
|
||||
|
@ -433,6 +433,7 @@ public class Key<VALUE> {
|
||||
public static final class KeyEnum<E extends Enum> extends Key<E> {
|
||||
private final E[] values;
|
||||
private final String[] names;
|
||||
private final boolean toString;
|
||||
|
||||
/**
|
||||
* Creates a new emum key
|
||||
@ -442,12 +443,29 @@ public class Key<VALUE> {
|
||||
* @param values the possible values
|
||||
*/
|
||||
public KeyEnum(String key, E def, E[] values) {
|
||||
this(key, def, values, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new emum key
|
||||
*
|
||||
* @param key the key
|
||||
* @param def the default value
|
||||
* @param values the possible values
|
||||
* @param toString if true, the names are not taken from the language file but created by calling toString()
|
||||
*/
|
||||
public KeyEnum(String key, E def, E[] values, boolean toString) {
|
||||
super(key, def);
|
||||
this.values = values;
|
||||
this.toString = toString;
|
||||
|
||||
names = new String[values.length];
|
||||
for (int i = 0; i < values.length; i++)
|
||||
names[i] = Lang.get(getLangKey(values[i]));
|
||||
if (toString)
|
||||
for (int i = 0; i < values.length; i++)
|
||||
names[i] = values[i].toString();
|
||||
else
|
||||
for (int i = 0; i < values.length; i++)
|
||||
names[i] = Lang.get(getLangKey(values[i]));
|
||||
allowGroupEdit();
|
||||
}
|
||||
|
||||
@ -474,6 +492,13 @@ public class Key<VALUE> {
|
||||
public String[] getNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this enum key uses toString to create the display names
|
||||
*/
|
||||
public boolean usesToString() {
|
||||
return toString;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -467,8 +467,8 @@ public final class Keys {
|
||||
/**
|
||||
* The GUI expression string representation
|
||||
*/
|
||||
public static final Key<FormatToExpression> SETTINGS_EXPRESSION_FORMAT
|
||||
= new Key<>("ExpressionFormat", FormatToExpression.FORMATTER_UNICODE);
|
||||
public static final Key.KeyEnum<FormatToExpression> SETTINGS_EXPRESSION_FORMAT
|
||||
= new Key.KeyEnum<>("ExpressionFormat", FormatToExpression.UNICODE, FormatToExpression.values(), true);
|
||||
|
||||
/**
|
||||
* enables the grid
|
||||
|
@ -25,7 +25,7 @@ public final class LaTeXFormatter {
|
||||
* @return the formatted string
|
||||
*/
|
||||
public static String format(Expression exp) {
|
||||
return format(new ExpressionToText().createText(exp, FormatToExpression.FORMATTER_LATEX), true);
|
||||
return format(new ExpressionToText().createText(exp, FormatToExpression.LATEX), true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,7 +10,6 @@ import de.neemann.digital.analyse.AnalyseException;
|
||||
import de.neemann.digital.analyse.ModelAnalyser;
|
||||
import de.neemann.digital.analyse.SubstituteLibrary;
|
||||
import de.neemann.digital.analyse.TruthTable;
|
||||
import de.neemann.digital.analyse.expression.format.FormatToExpression;
|
||||
import de.neemann.digital.core.*;
|
||||
import de.neemann.digital.core.element.ElementAttributes;
|
||||
import de.neemann.digital.core.element.Keys;
|
||||
@ -758,7 +757,6 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
.setDialogTitle(Lang.get("menu_editSettings"))
|
||||
.showDialog();
|
||||
if (modified != null) {
|
||||
FormatToExpression.setDefaultFormat(modified.get(Keys.SETTINGS_EXPRESSION_FORMAT));
|
||||
ColorScheme.updateCustomColorScheme(modified);
|
||||
|
||||
if (Settings.getInstance().requiresRestart(modified)) {
|
||||
@ -1981,7 +1979,6 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
}
|
||||
ToolTipManager.sharedInstance().setDismissDelay(10000);
|
||||
URL.setURLStreamHandlerFactory(ElementHelpDialog.createURLStreamHandlerFactory());
|
||||
FormatToExpression.setDefaultFormat(Settings.getInstance().get(Keys.SETTINGS_EXPRESSION_FORMAT));
|
||||
|
||||
if (Screen.isMac()) {
|
||||
setMacCopyPasteTo(UIManager.get("TextField.focusInputMap"));
|
||||
|
@ -6,7 +6,7 @@
|
||||
package de.neemann.digital.gui.components;
|
||||
|
||||
import de.neemann.digital.FileLocator;
|
||||
import de.neemann.digital.analyse.expression.format.FormatToExpression;
|
||||
import de.neemann.digital.core.Bits;
|
||||
import de.neemann.digital.core.*;
|
||||
import de.neemann.digital.core.element.*;
|
||||
import de.neemann.digital.core.extern.Application;
|
||||
@ -69,7 +69,6 @@ public final class EditorFactory {
|
||||
add(Rotation.class, RotationEditor.class);
|
||||
add(Language.class, LanguageEditor.class);
|
||||
add(TestCaseDescription.class, TestCaseDescriptionEditor.class);
|
||||
add(FormatToExpression.class, FormatEditor.class);
|
||||
add(InverterConfig.class, InverterConfigEditor.class);
|
||||
add(ROMManger.class, ROMManagerEditor.class);
|
||||
add(Application.Type.class, ApplicationTypeEditor.class);
|
||||
@ -875,13 +874,13 @@ public final class EditorFactory {
|
||||
}
|
||||
|
||||
private static class LanguageEditor extends LabelEditor<Language> {
|
||||
private JComboBox comb;
|
||||
private final JComboBox<Language> comb;
|
||||
|
||||
public LanguageEditor(Language language, Key<Rotation> key) {
|
||||
public LanguageEditor(Language language, Key<Language> key) {
|
||||
Bundle b = Lang.getBundle();
|
||||
List<Language> supLang = b.getSupportedLanguages();
|
||||
comb = new JComboBox<>(supLang.toArray(new Language[supLang.size()]));
|
||||
comb.setSelectedItem(Lang.currentLanguage());
|
||||
comb = new JComboBox<>(supLang.toArray(new Language[0]));
|
||||
comb.setSelectedItem(language);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -900,31 +899,6 @@ public final class EditorFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private static class FormatEditor extends LabelEditor<FormatToExpression> {
|
||||
private JComboBox comb;
|
||||
|
||||
public FormatEditor(FormatToExpression format, Key<Rotation> key) {
|
||||
FormatToExpression[] formats = FormatToExpression.getAvailFormats();
|
||||
comb = new JComboBox<>(formats);
|
||||
comb.setSelectedItem(format);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent getComponent(ElementAttributes elementAttributes) {
|
||||
return comb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormatToExpression getValue() {
|
||||
return (FormatToExpression) comb.getSelectedItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(FormatToExpression value) {
|
||||
comb.setSelectedItem(value);
|
||||
}
|
||||
}
|
||||
|
||||
private static class InverterConfigEditor extends LabelEditor<InverterConfig> {
|
||||
|
||||
private final JButton button;
|
||||
|
@ -64,7 +64,7 @@ public class DetermineJKStateMachineTest extends TestCase {
|
||||
}
|
||||
|
||||
private String toStr(Expression expression) {
|
||||
return FormatToExpression.FORMATTER_UNICODE.format(expression);
|
||||
return FormatToExpression.UNICODE.format(expression);
|
||||
}
|
||||
|
||||
public void testSimple2() throws Exception {
|
||||
|
@ -11,7 +11,6 @@ import de.neemann.digital.analyse.expression.NamedExpression;
|
||||
import de.neemann.digital.analyse.expression.Variable;
|
||||
import de.neemann.digital.analyse.parser.Parser;
|
||||
import de.neemann.digital.draw.graphics.text.formatter.LaTeXFormatter;
|
||||
import de.neemann.digital.draw.graphics.text.text.ExpressionToText;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -30,12 +29,12 @@ public class FormatToExpressionTest extends TestCase {
|
||||
Variable b = v("B");
|
||||
Expression e = and(not(or(not(a), not(b))), not(and(not(a), not(b))));
|
||||
|
||||
assertEquals("!(!A || !B) && !(!A && !B)", FormatToExpression.FORMATTER_JAVA.format(e));
|
||||
assertEquals("NOT (NOT A OR NOT B) AND NOT (NOT A AND NOT B)", FormatToExpression.FORMATTER_DERIVE.format(e));
|
||||
assertEquals("~(~A + ~B) ~(~A ~B)", FormatToExpression.FORMATTER_LOGISIM.format(e));
|
||||
assertEquals("¬(¬A ∨ ¬B) ∧ ¬(¬A ∧ ¬B)", FormatToExpression.FORMATTER_UNICODE.format(e));
|
||||
assertEquals("!(!A + !B) * !(!A * !B)", FormatToExpression.FORMATTER_SHORT.format(e));
|
||||
assertEquals("!(!A + !B) !(!A !B)", FormatToExpression.FORMATTER_SHORTER.format(e));
|
||||
assertEquals("!(!A || !B) && !(!A && !B)", FormatToExpression.JAVA.format(e));
|
||||
assertEquals("NOT (NOT A OR NOT B) AND NOT (NOT A AND NOT B)", FormatToExpression.DERIVE.format(e));
|
||||
assertEquals("~(~A + ~B) ~(~A ~B)", FormatToExpression.LOGISIM.format(e));
|
||||
assertEquals("¬(¬A ∨ ¬B) ∧ ¬(¬A ∧ ¬B)", FormatToExpression.UNICODE.format(e));
|
||||
assertEquals("!(!A + !B) * !(!A * !B)", FormatToExpression.SHORT.format(e));
|
||||
assertEquals("!(!A + !B) !(!A !B)", FormatToExpression.SHORTER.format(e));
|
||||
|
||||
assertEquals("\\overline{\\overline{A} \\oder \\overline{B}} \\und \\overline{\\overline{A} \\und \\overline{B}}", LaTeXFormatter.format(e));
|
||||
}
|
||||
@ -46,7 +45,7 @@ public class FormatToExpressionTest extends TestCase {
|
||||
Variable c = v("C");
|
||||
Expression e = or(and(a, not(b), c), and(a, not(b), not(c)));
|
||||
|
||||
assertEquals("(A !B C) + (A !B !C)", FormatToExpression.FORMATTER_SHORTER.format(e));
|
||||
assertEquals("(A !B C) + (A !B !C)", FormatToExpression.SHORTER.format(e));
|
||||
}
|
||||
|
||||
public void testFormatNamesExp() throws Exception {
|
||||
@ -54,16 +53,16 @@ public class FormatToExpressionTest extends TestCase {
|
||||
Variable b = v("B");
|
||||
Expression e = and(a, b);
|
||||
NamedExpression n = new NamedExpression("U", e);
|
||||
assertEquals("U = A ∧ B", FormatToExpression.FORMATTER_UNICODE.format(n));
|
||||
assertEquals("U = A ∧ B", FormatToExpression.UNICODE.format(n));
|
||||
n = new NamedExpression("V", n);
|
||||
assertEquals("V = U = A ∧ B", FormatToExpression.FORMATTER_UNICODE.format(n));
|
||||
assertEquals("V = U = A ∧ B", FormatToExpression.UNICODE.format(n));
|
||||
}
|
||||
|
||||
public void testFormatExpNot() throws Exception, FormatterException {
|
||||
Variable a = new Variable("A");
|
||||
Expression e = not(a);
|
||||
|
||||
assertEquals("¬A", FormatToExpression.FORMATTER_UNICODE.format(e));
|
||||
assertEquals("¬A", FormatToExpression.UNICODE.format(e));
|
||||
}
|
||||
|
||||
public void testFormatExpNot2() throws Exception {
|
||||
@ -72,7 +71,7 @@ public class FormatToExpressionTest extends TestCase {
|
||||
Variable c = v("C");
|
||||
Expression e = or(and(a, b), not(c));
|
||||
|
||||
assertEquals("(A ∧ B) ∨ ¬C", FormatToExpression.FORMATTER_UNICODE.format(e));
|
||||
assertEquals("(A ∧ B) ∨ ¬C", FormatToExpression.UNICODE.format(e));
|
||||
}
|
||||
|
||||
public void testFormatExpLaTeX() throws Exception {
|
||||
@ -112,12 +111,12 @@ public class FormatToExpressionTest extends TestCase {
|
||||
|
||||
public void testFormatXOr() throws Exception {
|
||||
ArrayList<Expression> e = new Parser("let sum=(A^B)^C, let c = (A B) + ((A^B) C)").parse();
|
||||
assertEquals("sum = (A ⊻ B) ⊻ C", FormatToExpression.FORMATTER_UNICODE.format(e.get(0)));
|
||||
assertEquals("c = (A ∧ B) ∨ ((A ⊻ B) ∧ C)", FormatToExpression.FORMATTER_UNICODE.format(e.get(1)));
|
||||
assertEquals("sum = (A ⊻ B) ⊻ C", FormatToExpression.UNICODE.format(e.get(0)));
|
||||
assertEquals("c = (A ∧ B) ∨ ((A ⊻ B) ∧ C)", FormatToExpression.UNICODE.format(e.get(1)));
|
||||
assertEquals("sum &=& (A \\xoder B) \\xoder C", LaTeXFormatter.format(e.get(0)));
|
||||
assertEquals("sum = (A $ B) $ C", FormatToExpression.FORMATTER_CUPL.format(e.get(0)));
|
||||
assertEquals("sum = (A ^ B) ^ C", FormatToExpression.FORMATTER_JAVA.format(e.get(0)));
|
||||
assertEquals("sum = (A ^ B) ^ C", FormatToExpression.FORMATTER_SHORT.format(e.get(0)));
|
||||
assertEquals("sum = (A ^ B) ^ C", FormatToExpression.FORMATTER_SHORTER.format(e.get(0)));
|
||||
assertEquals("sum = (A $ B) $ C", FormatToExpression.CUPL.format(e.get(0)));
|
||||
assertEquals("sum = (A ^ B) ^ C", FormatToExpression.JAVA.format(e.get(0)));
|
||||
assertEquals("sum = (A ^ B) ^ C", FormatToExpression.SHORT.format(e.get(0)));
|
||||
assertEquals("sum = (A ^ B) ^ C", FormatToExpression.SHORTER.format(e.get(0)));
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class QuineMcCluskeyRegressionTest extends TestCase {
|
||||
t.simplifyStep();
|
||||
}
|
||||
t.simplifyPrimes(new PrimeSelectorDefault());
|
||||
assertEquals("A || C", FormatToExpression.FORMATTER_JAVA.format(t.getExpression()));
|
||||
assertEquals("A || C", FormatToExpression.JAVA.format(t.getExpression()));
|
||||
// System.out.println("--");
|
||||
}
|
||||
|
||||
|
@ -21,18 +21,18 @@ public class QuineMcCluskeyRowTest extends TestCase {
|
||||
ArrayList<Variable> vars = Variable.vars("A", "B", "C", "D");
|
||||
|
||||
TableRow tr = new TableRow(4, 15, 0, false);
|
||||
assertEquals("A && B && C && D", FormatToExpression.FORMATTER_JAVA.format(tr.getExpression(vars)));
|
||||
assertEquals("A && B && C && D", FormatToExpression.JAVA.format(tr.getExpression(vars)));
|
||||
|
||||
tr = new TableRow(4, 5, 0, false);
|
||||
assertEquals("!A && B && !C && D", FormatToExpression.FORMATTER_JAVA.format(tr.getExpression(vars)));
|
||||
assertEquals("!A && B && !C && D", FormatToExpression.JAVA.format(tr.getExpression(vars)));
|
||||
tr = new TableRow(4, 10, 0, false);
|
||||
assertEquals("A && !B && C && !D", FormatToExpression.FORMATTER_JAVA.format(tr.getExpression(vars)));
|
||||
assertEquals("A && !B && C && !D", FormatToExpression.JAVA.format(tr.getExpression(vars)));
|
||||
tr = new TableRow(4, 10, 0, false);
|
||||
tr.setToOptimized(2);
|
||||
assertEquals("A && !B && !D", FormatToExpression.FORMATTER_JAVA.format(tr.getExpression(vars)));
|
||||
assertEquals("A && !B && !D", FormatToExpression.JAVA.format(tr.getExpression(vars)));
|
||||
tr = new TableRow(4, 10, 0, false);
|
||||
tr.setToOptimized(0);
|
||||
assertEquals("!B && C && !D", FormatToExpression.FORMATTER_JAVA.format(tr.getExpression(vars)));
|
||||
assertEquals("!B && C && !D", FormatToExpression.JAVA.format(tr.getExpression(vars)));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import static de.neemann.digital.analyse.expression.Not.not;
|
||||
import static de.neemann.digital.analyse.expression.Operation.and;
|
||||
import static de.neemann.digital.analyse.expression.Operation.or;
|
||||
import static de.neemann.digital.analyse.expression.Variable.vars;
|
||||
import static de.neemann.digital.analyse.expression.format.FormatToExpression.FORMATTER_UNICODE;
|
||||
import static de.neemann.digital.analyse.expression.format.FormatToExpression.UNICODE;
|
||||
|
||||
/**
|
||||
*/
|
||||
@ -32,7 +32,7 @@ public class QuineMcCluskeyTest extends TestCase {
|
||||
.simplify()
|
||||
.getExpression();
|
||||
|
||||
assertEquals("!B", FormatToExpression.FORMATTER_JAVA.format(e));
|
||||
assertEquals("!B", FormatToExpression.JAVA.format(e));
|
||||
}
|
||||
|
||||
public void testGenerator() throws ExpressionException {
|
||||
@ -119,12 +119,12 @@ public class QuineMcCluskeyTest extends TestCase {
|
||||
assertEquals("-01-,2,3,6,7", primes.get(3).toString());
|
||||
|
||||
Expression exp = t.getExpression();
|
||||
assertEquals("(A && C && D) || (!B && !D) || (!B && C) || (!C && !D)", FormatToExpression.FORMATTER_JAVA.format(exp));
|
||||
assertEquals("(A && C && D) || (!B && !D) || (!B && C) || (!C && !D)", FormatToExpression.JAVA.format(exp));
|
||||
|
||||
t.simplifyPrimes(new PrimeSelectorDefault());
|
||||
|
||||
exp = t.getExpression();
|
||||
assertEquals("(A && C && D) || (!B && C) || (!C && !D)", FormatToExpression.FORMATTER_JAVA.format(exp));
|
||||
assertEquals("(A && C && D) || (!B && C) || (!C && !D)", FormatToExpression.JAVA.format(exp));
|
||||
}
|
||||
|
||||
public void testSimplify2() throws ExpressionException, FormatterException {
|
||||
@ -132,7 +132,7 @@ public class QuineMcCluskeyTest extends TestCase {
|
||||
t.fillTableWith(new BoolTableByteArray(new byte[]{1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1}));
|
||||
t = t.simplify();
|
||||
|
||||
assertEquals("(!A && !C) || (B && D) || (B && !C)", FormatToExpression.FORMATTER_JAVA.format(t.getExpression()));
|
||||
assertEquals("(!A && !C) || (B && D) || (B && !C)", FormatToExpression.JAVA.format(t.getExpression()));
|
||||
}
|
||||
|
||||
public void testZero() throws Exception {
|
||||
@ -211,9 +211,9 @@ public class QuineMcCluskeyTest extends TestCase {
|
||||
|
||||
boolean ok = (c <= cOne) && (c <= cZero);
|
||||
if (!ok) {
|
||||
System.out.println("\nX: " + FORMATTER_UNICODE.format(e) + ", " + c);
|
||||
System.out.println("0: " + FORMATTER_UNICODE.format(eZero) + ", " + cZero);
|
||||
System.out.println("1: " + FORMATTER_UNICODE.format(eOne) + ", " + cOne);
|
||||
System.out.println("\nX: " + UNICODE.format(e) + ", " + c);
|
||||
System.out.println("0: " + UNICODE.format(eZero) + ", " + cZero);
|
||||
System.out.println("1: " + UNICODE.format(eOne) + ", " + cOne);
|
||||
|
||||
assertTrue(false);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class SimplifyTest extends TestCase {
|
||||
Expression e = or(and(a, b), a);
|
||||
Expression s = QuineMcCluskey.simplify(e);
|
||||
|
||||
assertEquals("a", FormatToExpression.FORMATTER_UNICODE.format(s));
|
||||
assertEquals("a", FormatToExpression.UNICODE.format(s));
|
||||
}
|
||||
|
||||
public void testSimplify2() throws Exception, FormatterException {
|
||||
@ -35,7 +35,7 @@ public class SimplifyTest extends TestCase {
|
||||
Expression e = and(or(a, b), a);
|
||||
Expression s = QuineMcCluskey.simplify(e);
|
||||
|
||||
assertEquals("a", FormatToExpression.FORMATTER_UNICODE.format(s));
|
||||
assertEquals("a", FormatToExpression.UNICODE.format(s));
|
||||
}
|
||||
|
||||
public void testSimplify3() throws Exception {
|
||||
|
@ -49,7 +49,7 @@ public class ScreenShots {
|
||||
private static Main mainStatic;
|
||||
|
||||
public static void main(String[] args) {
|
||||
FormatToExpression.setDefaultFormat(FormatToExpression.FORMATTER_UNICODE_NOAND);
|
||||
Settings.getInstance().getAttributes().set(Keys.SETTINGS_EXPRESSION_FORMAT, FormatToExpression.UNICODE_NOAND);
|
||||
Settings.getInstance().getAttributes().set(Keys.SETTINGS_DEFAULT_TREESELECT, false);
|
||||
Settings.getInstance().getAttributes().set(Keys.SETTINGS_GRID, true);
|
||||
// mainScreenShot();
|
||||
@ -168,7 +168,7 @@ public class ScreenShots {
|
||||
.add(new GuiTester.CloseTopMost())
|
||||
.add(new GuiTester.CloseTopMost())
|
||||
.execute();/**/
|
||||
|
||||
|
||||
File trafficLight = new File(Resources.getRoot(), "../../main/fsm/trafficLightBlink.fsm");
|
||||
new GuiTester()
|
||||
.press("F10")
|
||||
|
@ -13,17 +13,17 @@ import junit.framework.TestCase;
|
||||
public class PlainTextFormatterTest extends TestCase {
|
||||
|
||||
public void testSimple() throws ParseException {
|
||||
assertEquals("Hello World", PlainTextFormatter.format(new Parser("Hello World").parse(), FormatToExpression.FORMATTER_JAVA));
|
||||
assertEquals("Q", PlainTextFormatter.format(new Parser("Q").parse(), FormatToExpression.FORMATTER_JAVA));
|
||||
assertEquals("Q", PlainTextFormatter.format(new Parser("$Q$").parse(), FormatToExpression.FORMATTER_JAVA));
|
||||
assertEquals("Q0n+1", PlainTextFormatter.format(new Parser("Q_0^{n+1}").parse(), FormatToExpression.FORMATTER_JAVA));
|
||||
assertEquals("Q0n", PlainTextFormatter.format(new Parser("Q_0^n").parse(), FormatToExpression.FORMATTER_JAVA));
|
||||
assertEquals("Q0n", PlainTextFormatter.format(new Parser("Q^n_0").parse(), FormatToExpression.FORMATTER_JAVA));
|
||||
assertEquals("!Q", PlainTextFormatter.format(new Parser("~{Q}").parse(), FormatToExpression.FORMATTER_JAVA));
|
||||
assertEquals("!(A+B)", PlainTextFormatter.format(new Parser("~{A+B}").parse(), FormatToExpression.FORMATTER_JAVA));
|
||||
assertEquals("!(!Q)", PlainTextFormatter.format(new Parser("~{~Q}").parse(), FormatToExpression.FORMATTER_JAVA));
|
||||
assertEquals("Hello World", PlainTextFormatter.format(new Parser("Hello World").parse(), FormatToExpression.JAVA));
|
||||
assertEquals("Q", PlainTextFormatter.format(new Parser("Q").parse(), FormatToExpression.JAVA));
|
||||
assertEquals("Q", PlainTextFormatter.format(new Parser("$Q$").parse(), FormatToExpression.JAVA));
|
||||
assertEquals("Q0n+1", PlainTextFormatter.format(new Parser("Q_0^{n+1}").parse(), FormatToExpression.JAVA));
|
||||
assertEquals("Q0n", PlainTextFormatter.format(new Parser("Q_0^n").parse(), FormatToExpression.JAVA));
|
||||
assertEquals("Q0n", PlainTextFormatter.format(new Parser("Q^n_0").parse(), FormatToExpression.JAVA));
|
||||
assertEquals("!Q", PlainTextFormatter.format(new Parser("~{Q}").parse(), FormatToExpression.JAVA));
|
||||
assertEquals("!(A+B)", PlainTextFormatter.format(new Parser("~{A+B}").parse(), FormatToExpression.JAVA));
|
||||
assertEquals("!(!Q)", PlainTextFormatter.format(new Parser("~{~Q}").parse(), FormatToExpression.JAVA));
|
||||
|
||||
assertEquals("!a0n", PlainTextFormatter.format(new Parser("~{a_0^n}").parse(), FormatToExpression.FORMATTER_JAVA));
|
||||
assertEquals("!a0n", PlainTextFormatter.format(new Parser("~{a_0^n}").parse(), FormatToExpression.JAVA));
|
||||
}
|
||||
|
||||
}
|
@ -16,6 +16,7 @@ import junit.framework.TestCase;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TestKeyConsistence extends TestCase {
|
||||
|
||||
@ -29,8 +30,9 @@ public class TestKeyConsistence extends TestCase {
|
||||
|
||||
if (key instanceof Key.KeyEnum) {
|
||||
Key.KeyEnum ke = (Key.KeyEnum) key;
|
||||
for (Enum v : ke.getValues())
|
||||
checkKey(ke.getLangKey(v));
|
||||
if (!ke.usesToString())
|
||||
for (Enum v : ke.getValues())
|
||||
checkKey(ke.getLangKey(v));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user