reversed order of multi-bit inputs and outputs in TableDialog. See #108

This commit is contained in:
hneemann 2018-01-23 14:39:02 +01:00
parent d5fbff081b
commit b0efe643cc
3 changed files with 24 additions and 17 deletions

View File

@ -130,11 +130,11 @@ public class ModelAnalyser {
try {
Splitter sp = Splitter.createOneToN(bits);
sp.setInputs(s.getValue().asList());
int i = 0;
for (ObservableValue out : sp.getOutputs()) {
outputs.add(new Signal(s.getName() + i, out));
i++;
}
final ObservableValues spOutputs = sp.getOutputs();
for (int i = spOutputs.size() - 1; i >= 0; i--)
outputs.add(new Signal(s.getName() + i, spOutputs.get(i)));
s.getValue().fireHasChanged();
} catch (NodeException e) {
throw new AnalyseException(e);
@ -163,12 +163,12 @@ public class ModelAnalyser {
out.fireHasChanged();
ObservableValues.Builder builder = new ObservableValues.Builder();
for (int i = 0; i < bits; i++) {
for (int i = bits - 1; i >= 0; i--) {
ObservableValue o = new ObservableValue(s.getName() + i, 1);
builder.add(o);
inputs.add(new Signal(s.getName() + i, o));
}
sp.setInputs(builder.build());
sp.setInputs(builder.reverse().build());
} catch (NodeException e) {
throw new AnalyseException(e);
}

View File

@ -2,10 +2,7 @@ package de.neemann.digital.core;
import de.neemann.digital.core.element.ImmutableList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.*;
/**
* @author hneemann
@ -58,6 +55,16 @@ public class ObservableValues extends ImmutableList<ObservableValue> {
return this;
}
/**
* Reverses the order of the values
*
* @return the builder
*/
public Builder reverse() {
Collections.reverse(values);
return this;
}
/**
* @return the {@link ObservableValues} instance
*/

View File

@ -111,10 +111,10 @@ public class ModelAnalyserTest extends TestCase {
checkTable(tt.getResult("Q0n+1"), one, zero, one, zero);
checkTable(tt.getResult("Q1n+1"), zero, one, one, zero);
assertEquals("Y0", tt.getResultName(2));
assertEquals("Y1", tt.getResultName(3));
final BoolTable y0 = tt.getResult(2);
final BoolTable y1 = tt.getResult(3);
assertEquals("Y1", tt.getResultName(2));
assertEquals("Y0", tt.getResultName(3));
final BoolTable y1 = tt.getResult(2);
final BoolTable y0 = tt.getResult(3);
for (int i = 0; i < 4; i++) {
assertEquals((i & 1) > 0, y0.get(i).invert().bool());
assertEquals((i & 2) > 0, y1.get(i).invert().bool());
@ -136,8 +136,8 @@ public class ModelAnalyserTest extends TestCase {
}
private void checkIdent(TruthTable tt) {
checkTable(tt.getResult("B0"), zero, zero, one, one);
checkTable(tt.getResult("B1"), zero, one, zero, one);
checkTable(tt.getResult("B1"), zero, zero, one, one);
checkTable(tt.getResult("B0"), zero, one, zero, one);
}
private void checkTable(BoolTable table, ThreeStateValue... expected) {