removed unnecessary class Wire
This commit is contained in:
parent
e5c694fc53
commit
1b7531633d
5
pom.xml
5
pom.xml
@ -30,6 +30,11 @@
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.11.0-M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.17.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -1,7 +1,6 @@
|
||||
package de.ph87.electro.circuit;
|
||||
|
||||
import de.ph87.electro.circuit.junction.Junction;
|
||||
import de.ph87.electro.circuit.junction.Wire;
|
||||
import de.ph87.electro.circuit.part.Junction;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.PartBattery;
|
||||
import de.ph87.electro.circuit.part.PartOther;
|
||||
@ -23,8 +22,6 @@ public class Circuit {
|
||||
|
||||
private final List<PartOther> others = new ArrayList<>();
|
||||
|
||||
private final List<Wire> wires = new ArrayList<>();
|
||||
|
||||
public PartBattery addBattery(final String name, final int x, final int y, final double voltage) {
|
||||
final PartBattery battery = new PartBattery(name, x, y, voltage);
|
||||
parts.add(battery);
|
||||
@ -60,14 +57,12 @@ public class Circuit {
|
||||
return switchCross;
|
||||
}
|
||||
|
||||
public Wire connect(final Junction a, final Junction b) {
|
||||
final Wire wire = new Wire(a, b);
|
||||
wires.add(wire);
|
||||
return wire;
|
||||
public void connect(final Junction a, final Junction b) {
|
||||
a.getJunctions().add(b);
|
||||
b.getJunctions().add(a);
|
||||
}
|
||||
|
||||
public void evaluate() {
|
||||
wires.forEach(Wire::reset);
|
||||
parts.forEach(Part::reset);
|
||||
batteries.forEach(PartBattery::startPropagation);
|
||||
}
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
package de.ph87.electro.circuit.junction;
|
||||
|
||||
import de.ph87.electro.circuit.ShortCircuit;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class Wire {
|
||||
|
||||
private final Junction junction0;
|
||||
|
||||
private final Junction junction1;
|
||||
|
||||
private double voltage = Double.NaN;
|
||||
|
||||
public Wire(final Junction junction0, final Junction junction1) {
|
||||
if (junction0 == junction1) {
|
||||
throw new RuntimeException("Cannot connect Pin to itself!");
|
||||
}
|
||||
this.junction0 = junction0;
|
||||
this.junction1 = junction1;
|
||||
junction0.getWires().add(this);
|
||||
junction1.getWires().add(this);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
voltage = Double.NaN;
|
||||
}
|
||||
|
||||
public void propagate(final double newVoltage) throws ShortCircuit {
|
||||
if (voltage == newVoltage) {
|
||||
return;
|
||||
}
|
||||
if (Double.isNaN(voltage)) {
|
||||
voltage = newVoltage;
|
||||
junction0.propagate(voltage);
|
||||
junction1.propagate(voltage);
|
||||
return;
|
||||
}
|
||||
throw new ShortCircuit();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
package de.ph87.electro.circuit.junction;
|
||||
package de.ph87.electro.circuit.part;
|
||||
|
||||
import de.ph87.electro.circuit.ShortCircuit;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@ -9,11 +8,14 @@ import lombok.ToString;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@ToString(onlyExplicitlyIncluded = true)
|
||||
public class Junction {
|
||||
|
||||
private final String uuid;
|
||||
|
||||
private final Part owner;
|
||||
|
||||
@ToString.Include
|
||||
@ -25,9 +27,10 @@ public class Junction {
|
||||
@ToString.Include
|
||||
private double voltage = Double.NaN;
|
||||
|
||||
private final List<Wire> wires = new ArrayList<>();
|
||||
private final List<Junction> junctions = new ArrayList<>();
|
||||
|
||||
public Junction(final Part owner, final String name, final int x, final int y) {
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
this.owner = owner;
|
||||
this.name = name;
|
||||
this.position = new Point(x, y);
|
||||
@ -44,8 +47,8 @@ public class Junction {
|
||||
if (Double.isNaN(voltage)) {
|
||||
voltage = newVoltage;
|
||||
owner.propagate(this);
|
||||
for (Wire wire : wires) {
|
||||
wire.propagate(newVoltage);
|
||||
for (Junction junction : junctions) {
|
||||
junction.propagate(newVoltage);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
package de.ph87.electro.circuit.part;
|
||||
|
||||
import de.ph87.electro.circuit.ShortCircuit;
|
||||
import de.ph87.electro.circuit.junction.Junction;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@ -9,12 +8,15 @@ import lombok.ToString;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(onlyExplicitlyIncluded = true)
|
||||
public abstract class Part {
|
||||
|
||||
private final String uuid;
|
||||
|
||||
@ToString.Include
|
||||
private String name;
|
||||
|
||||
@ -23,6 +25,7 @@ public abstract class Part {
|
||||
protected final List<Junction> junctions = new ArrayList<>();
|
||||
|
||||
protected Part(final String name, final int x, final int y) {
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
this.name = name;
|
||||
this.position = new Point(x, y);
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package de.ph87.electro.circuit.part;
|
||||
|
||||
import de.ph87.electro.circuit.ShortCircuit;
|
||||
import de.ph87.electro.circuit.junction.Junction;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package de.ph87.electro.circuit.part.other;
|
||||
|
||||
import de.ph87.electro.circuit.ShortCircuit;
|
||||
import de.ph87.electro.circuit.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.Junction;
|
||||
import de.ph87.electro.circuit.part.PartOther;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.other;
|
||||
|
||||
import de.ph87.electro.circuit.ShortCircuit;
|
||||
import de.ph87.electro.circuit.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.Junction;
|
||||
import de.ph87.electro.circuit.part.PartOther;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.other;
|
||||
|
||||
import de.ph87.electro.circuit.ShortCircuit;
|
||||
import de.ph87.electro.circuit.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.Junction;
|
||||
import de.ph87.electro.circuit.part.PartOther;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.other;
|
||||
|
||||
import de.ph87.electro.circuit.ShortCircuit;
|
||||
import de.ph87.electro.circuit.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.Junction;
|
||||
import de.ph87.electro.circuit.part.PartOther;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package de.ph87.electro.circuit;
|
||||
|
||||
import de.ph87.electro.circuit.junction.Wire;
|
||||
import de.ph87.electro.circuit.part.PartBattery;
|
||||
import de.ph87.electro.circuit.part.other.PartLight;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@ -12,30 +12,30 @@ public class BatteryLightTest {
|
||||
|
||||
private static final double VOLTAGE = 3;
|
||||
|
||||
private final Circuit circuit = new Circuit();
|
||||
private static final Circuit circuit = new Circuit();
|
||||
|
||||
private final PartBattery battery = circuit.addBattery("Batterie", 1, 0, VOLTAGE);
|
||||
private static final PartBattery battery = circuit.addBattery("Batterie", 1, 0, VOLTAGE);
|
||||
|
||||
private final PartLight light = circuit.addLight("Licht", 1, 1, VOLTAGE);
|
||||
private static final PartLight light = circuit.addLight("Licht", 1, 1, VOLTAGE);
|
||||
|
||||
private final Wire plus = circuit.connect(battery.getPlus(), light.getPlus());
|
||||
|
||||
private final Wire minus = circuit.connect(light.getMinus(), battery.getMinus());
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
circuit.connect(battery.getPlus(), light.getPlus());
|
||||
circuit.connect(light.getMinus(), battery.getMinus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
circuit.evaluate();
|
||||
|
||||
assertEquals(VOLTAGE, battery.getPlus().getVoltage());
|
||||
assertEquals(VOLTAGE, plus.getVoltage());
|
||||
|
||||
assertEquals(VOLTAGE, light.getPlus().getVoltage());
|
||||
assertEquals(VOLTAGE, light.getVoltage());
|
||||
assertEquals(0, light.getMinus().getVoltage());
|
||||
assertFalse(light.isDefect());
|
||||
|
||||
assertEquals(0, minus.getVoltage());
|
||||
assertEquals(0, light.getMinus().getVoltage());
|
||||
assertEquals(0, battery.getMinus().getVoltage());
|
||||
|
||||
assertFalse(light.isDefect());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package de.ph87.electro.circuit;
|
||||
|
||||
import de.ph87.electro.circuit.junction.Wire;
|
||||
import de.ph87.electro.circuit.part.PartBattery;
|
||||
import de.ph87.electro.circuit.part.other.PartLight;
|
||||
import de.ph87.electro.circuit.part.other.PartSwitch1x1;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@ -13,19 +13,20 @@ public class BatterySwitcher1x1Test {
|
||||
|
||||
private static final double VOLTAGE = 3;
|
||||
|
||||
private final Circuit circuit = new Circuit();
|
||||
private static final Circuit circuit = new Circuit();
|
||||
|
||||
private final PartBattery battery = circuit.addBattery("Batterie", 1, 0, VOLTAGE);
|
||||
private static final PartBattery battery = circuit.addBattery("Batterie", 1, 0, VOLTAGE);
|
||||
|
||||
private final PartSwitch1x1 switcher = circuit.addSwitch1x1("Ein-/Ausschalter", 1, 1);
|
||||
private static final PartSwitch1x1 switcher = circuit.addSwitch1x1("Ein-/Ausschalter", 1, 1);
|
||||
|
||||
private final PartLight light = circuit.addLight("Licht", 1, 1, VOLTAGE);
|
||||
private static final PartLight light = circuit.addLight("Licht", 1, 1, VOLTAGE);
|
||||
|
||||
private final Wire plus = circuit.connect(battery.getPlus(), switcher.getCommon());
|
||||
|
||||
private final Wire output = circuit.connect(switcher.getOutput(), light.getPlus());
|
||||
|
||||
private final Wire minus = circuit.connect(light.getMinus(), battery.getMinus());
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
circuit.connect(battery.getPlus(), switcher.getCommon());
|
||||
circuit.connect(switcher.getOutput(), light.getPlus());
|
||||
circuit.connect(light.getMinus(), battery.getMinus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test0() {
|
||||
@ -47,19 +48,16 @@ public class BatterySwitcher1x1Test {
|
||||
assertEquals(state, switcher.isState());
|
||||
|
||||
assertEquals(VOLTAGE, battery.getPlus().getVoltage());
|
||||
assertEquals(VOLTAGE, plus.getVoltage());
|
||||
|
||||
assertEquals(VOLTAGE, switcher.getCommon().getVoltage());
|
||||
|
||||
assertEquals(voltage, switcher.getOutput().getVoltage());
|
||||
assertEquals(voltage, output.getVoltage());
|
||||
assertEquals(voltage, light.getPlus().getVoltage());
|
||||
assertEquals(voltage, light.getVoltage());
|
||||
assertEquals(0, light.getMinus().getVoltage());
|
||||
assertEquals(0, minus.getVoltage());
|
||||
assertFalse(light.isDefect());
|
||||
|
||||
assertEquals(0, light.getMinus().getVoltage());
|
||||
assertEquals(0, battery.getMinus().getVoltage());
|
||||
|
||||
assertFalse(light.isDefect());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package de.ph87.electro.circuit;
|
||||
|
||||
import de.ph87.electro.circuit.junction.Wire;
|
||||
import de.ph87.electro.circuit.part.PartBattery;
|
||||
import de.ph87.electro.circuit.part.other.PartLight;
|
||||
import de.ph87.electro.circuit.part.other.PartSwitch1x2;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@ -13,25 +13,24 @@ public class BatterySwitcher1x2Test {
|
||||
|
||||
private static final double VOLTAGE = 3;
|
||||
|
||||
private final Circuit circuit = new Circuit();
|
||||
private static final Circuit circuit = new Circuit();
|
||||
|
||||
private final PartBattery battery = circuit.addBattery("Batterie", 1, 0, VOLTAGE);
|
||||
private static final PartBattery battery = circuit.addBattery("Batterie", 1, 0, VOLTAGE);
|
||||
|
||||
private final PartSwitch1x2 switcher = circuit.addSwitch1x2("Wechselschalter", 1, 1);
|
||||
private static final PartSwitch1x2 switcher = circuit.addSwitch1x2("Wechselschalter", 1, 1);
|
||||
|
||||
private final PartLight light0 = circuit.addLight("Licht 0", 1, 1, VOLTAGE);
|
||||
private static final PartLight light0 = circuit.addLight("Licht 0", 1, 1, VOLTAGE);
|
||||
|
||||
private final PartLight light1 = circuit.addLight("Licht 1", 1, 1, VOLTAGE);
|
||||
private static final PartLight light1 = circuit.addLight("Licht 1", 1, 1, VOLTAGE);
|
||||
|
||||
private final Wire plus = circuit.connect(battery.getPlus(), switcher.getCommon());
|
||||
|
||||
private final Wire output0 = circuit.connect(switcher.getOutput0(), light0.getPlus());
|
||||
|
||||
private final Wire minus0 = circuit.connect(light0.getMinus(), battery.getMinus());
|
||||
|
||||
private final Wire output1 = circuit.connect(switcher.getOutput1(), light1.getPlus());
|
||||
|
||||
private final Wire minus1 = circuit.connect(light1.getMinus(), battery.getMinus());
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
circuit.connect(battery.getPlus(), switcher.getCommon());
|
||||
circuit.connect(switcher.getOutput0(), light0.getPlus());
|
||||
circuit.connect(light0.getMinus(), battery.getMinus());
|
||||
circuit.connect(switcher.getOutput1(), light1.getPlus());
|
||||
circuit.connect(light1.getMinus(), battery.getMinus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test0() {
|
||||
@ -54,27 +53,22 @@ public class BatterySwitcher1x2Test {
|
||||
assertEquals(state, switcher.isState());
|
||||
|
||||
assertEquals(VOLTAGE, battery.getPlus().getVoltage());
|
||||
assertEquals(VOLTAGE, plus.getVoltage());
|
||||
|
||||
assertEquals(VOLTAGE, switcher.getCommon().getVoltage());
|
||||
|
||||
assertEquals(voltage0, switcher.getOutput0().getVoltage());
|
||||
assertEquals(voltage0, output0.getVoltage());
|
||||
assertEquals(voltage0, light0.getPlus().getVoltage());
|
||||
assertEquals(voltage0, light0.getVoltage());
|
||||
assertEquals(0, light0.getMinus().getVoltage());
|
||||
assertEquals(0, minus0.getVoltage());
|
||||
assertFalse(light0.isDefect());
|
||||
|
||||
assertEquals(voltage1, switcher.getOutput1().getVoltage());
|
||||
assertEquals(voltage1, output1.getVoltage());
|
||||
assertEquals(voltage1, light1.getPlus().getVoltage());
|
||||
assertEquals(voltage1, light1.getVoltage());
|
||||
assertEquals(0, light1.getMinus().getVoltage());
|
||||
assertEquals(0, minus1.getVoltage());
|
||||
assertFalse(light1.isDefect());
|
||||
|
||||
assertEquals(0, light0.getMinus().getVoltage());
|
||||
assertEquals(0, light1.getMinus().getVoltage());
|
||||
assertEquals(0, battery.getMinus().getVoltage());
|
||||
|
||||
assertFalse(light0.isDefect());
|
||||
assertFalse(light1.isDefect());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package de.ph87.electro.circuit;
|
||||
|
||||
import de.ph87.electro.circuit.junction.Wire;
|
||||
import de.ph87.electro.circuit.part.PartBattery;
|
||||
import de.ph87.electro.circuit.part.other.PartLight;
|
||||
import de.ph87.electro.circuit.part.other.PartSwitch1x2;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@ -13,25 +13,24 @@ public class BatterySwitcher2x2Test {
|
||||
|
||||
private static final double VOLTAGE = 3;
|
||||
|
||||
private final Circuit circuit = new Circuit();
|
||||
private static final Circuit circuit = new Circuit();
|
||||
|
||||
private final PartBattery battery = circuit.addBattery("Batterie", 1, 0, VOLTAGE);
|
||||
private static final PartBattery battery = circuit.addBattery("Batterie", 1, 0, VOLTAGE);
|
||||
|
||||
private final PartSwitch1x2 switcher0 = circuit.addSwitch1x2("Wechselschalter 0", 1, 1);
|
||||
private static final PartSwitch1x2 switcher0 = circuit.addSwitch1x2("Wechselschalter 0", 1, 1);
|
||||
|
||||
private final PartSwitch1x2 switcher1 = circuit.addSwitch1x2("Wechselschalter 1", 1, 1);
|
||||
private static final PartSwitch1x2 switcher1 = circuit.addSwitch1x2("Wechselschalter 1", 1, 1);
|
||||
|
||||
private final PartLight light = circuit.addLight("Licht", 1, 1, VOLTAGE);
|
||||
private static final PartLight light = circuit.addLight("Licht", 1, 1, VOLTAGE);
|
||||
|
||||
private final Wire plus = circuit.connect(battery.getPlus(), switcher0.getCommon());
|
||||
|
||||
private final Wire switcher00 = circuit.connect(switcher0.getOutput0(), switcher1.getOutput0());
|
||||
|
||||
private final Wire switcher01 = circuit.connect(switcher0.getOutput1(), switcher1.getOutput1());
|
||||
|
||||
private final Wire output = circuit.connect(switcher1.getCommon(), light.getPlus());
|
||||
|
||||
private final Wire minus = circuit.connect(light.getMinus(), battery.getMinus());
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
circuit.connect(battery.getPlus(), switcher0.getCommon());
|
||||
circuit.connect(switcher0.getOutput0(), switcher1.getOutput0());
|
||||
circuit.connect(switcher0.getOutput1(), switcher1.getOutput1());
|
||||
circuit.connect(switcher1.getCommon(), light.getPlus());
|
||||
circuit.connect(light.getMinus(), battery.getMinus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test00() {
|
||||
@ -67,28 +66,22 @@ public class BatterySwitcher2x2Test {
|
||||
assertEquals(state1, switcher1.isState());
|
||||
|
||||
assertEquals(VOLTAGE, battery.getPlus().getVoltage());
|
||||
assertEquals(VOLTAGE, plus.getVoltage());
|
||||
|
||||
assertEquals(VOLTAGE, switcher0.getCommon().getVoltage());
|
||||
|
||||
assertEquals(voltage0, switcher0.getOutput0().getVoltage());
|
||||
assertEquals(voltage0, switcher00.getVoltage());
|
||||
assertEquals(voltage0, switcher1.getOutput0().getVoltage());
|
||||
|
||||
assertEquals(voltage1, switcher0.getOutput1().getVoltage());
|
||||
assertEquals(voltage1, switcher01.getVoltage());
|
||||
assertEquals(voltage1, switcher1.getOutput1().getVoltage());
|
||||
|
||||
assertEquals(voltage, switcher1.getCommon().getVoltage());
|
||||
assertEquals(voltage, output.getVoltage());
|
||||
assertEquals(voltage, light.getPlus().getVoltage());
|
||||
assertEquals(voltage, light.getVoltage());
|
||||
|
||||
assertEquals(0, light.getMinus().getVoltage());
|
||||
assertEquals(0, minus.getVoltage());
|
||||
assertFalse(light.isDefect());
|
||||
|
||||
assertEquals(0, battery.getMinus().getVoltage());
|
||||
|
||||
assertFalse(light.isDefect());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
package de.ph87.electro.circuit;
|
||||
|
||||
import de.ph87.electro.circuit.junction.Wire;
|
||||
import de.ph87.electro.circuit.part.PartBattery;
|
||||
import de.ph87.electro.circuit.part.other.PartLight;
|
||||
import de.ph87.electro.circuit.part.other.PartSwitch1x2;
|
||||
import de.ph87.electro.circuit.part.other.PartSwitchCross;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@ -14,31 +14,28 @@ public class BatterySwitcherCrossTest {
|
||||
|
||||
private static final double VOLTAGE = 3;
|
||||
|
||||
private final Circuit circuit = new Circuit();
|
||||
private static final Circuit circuit = new Circuit();
|
||||
|
||||
private final PartBattery battery = circuit.addBattery("Batterie", 1, 0, VOLTAGE);
|
||||
private static final PartBattery battery = circuit.addBattery("Batterie", 1, 0, VOLTAGE);
|
||||
|
||||
private final PartSwitch1x2 switcher0 = circuit.addSwitch1x2("Wechselschalter 0", 1, 1);
|
||||
private static final PartSwitch1x2 switcher0 = circuit.addSwitch1x2("Wechselschalter 0", 1, 1);
|
||||
|
||||
private final PartSwitchCross switcherX = circuit.addSwitchCross("Kreuzschalter", 1, 1);
|
||||
private static final PartSwitchCross switcherX = circuit.addSwitchCross("Kreuzschalter", 1, 1);
|
||||
|
||||
private final PartSwitch1x2 switcher1 = circuit.addSwitch1x2("Wechselschalter 1", 1, 1);
|
||||
private static final PartSwitch1x2 switcher1 = circuit.addSwitch1x2("Wechselschalter 1", 1, 1);
|
||||
|
||||
private final PartLight light = circuit.addLight("Licht", 1, 1, VOLTAGE);
|
||||
private static final PartLight light = circuit.addLight("Licht", 1, 1, VOLTAGE);
|
||||
|
||||
private final Wire plus = circuit.connect(battery.getPlus(), switcher0.getCommon());
|
||||
|
||||
private final Wire switcher00 = circuit.connect(switcher0.getOutput0(), switcherX.getCommon0());
|
||||
|
||||
private final Wire switcher01 = circuit.connect(switcher0.getOutput1(), switcherX.getCommon1());
|
||||
|
||||
private final Wire switcherX0 = circuit.connect(switcherX.getOutput0(), switcher1.getOutput0());
|
||||
|
||||
private final Wire switcherX1 = circuit.connect(switcherX.getOutput1(), switcher1.getOutput1());
|
||||
|
||||
private final Wire output = circuit.connect(switcher1.getCommon(), light.getPlus());
|
||||
|
||||
private final Wire minus = circuit.connect(light.getMinus(), battery.getMinus());
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
circuit.connect(battery.getPlus(), switcher0.getCommon());
|
||||
circuit.connect(switcher0.getOutput0(), switcherX.getCommon0());
|
||||
circuit.connect(switcher0.getOutput1(), switcherX.getCommon1());
|
||||
circuit.connect(switcherX.getOutput0(), switcher1.getOutput0());
|
||||
circuit.connect(switcherX.getOutput1(), switcher1.getOutput1());
|
||||
circuit.connect(switcher1.getCommon(), light.getPlus());
|
||||
circuit.connect(light.getMinus(), battery.getMinus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test000() {
|
||||
@ -98,35 +95,28 @@ public class BatterySwitcherCrossTest {
|
||||
assertEquals(state1, switcher1.isState());
|
||||
|
||||
assertEquals(VOLTAGE, battery.getPlus().getVoltage());
|
||||
assertEquals(VOLTAGE, plus.getVoltage());
|
||||
assertEquals(VOLTAGE, switcher0.getCommon().getVoltage());
|
||||
|
||||
assertEquals(voltage00, switcher0.getOutput0().getVoltage());
|
||||
assertEquals(voltage00, switcher00.getVoltage());
|
||||
assertEquals(voltage00, switcherX.getCommon0().getVoltage());
|
||||
|
||||
assertEquals(voltage01, switcher0.getOutput1().getVoltage());
|
||||
assertEquals(voltage01, switcher01.getVoltage());
|
||||
assertEquals(voltage01, switcherX.getCommon1().getVoltage());
|
||||
|
||||
assertEquals(voltageX0, switcherX.getOutput0().getVoltage());
|
||||
assertEquals(voltageX0, switcherX0.getVoltage());
|
||||
assertEquals(voltageX0, switcher1.getOutput0().getVoltage());
|
||||
|
||||
assertEquals(voltageX1, switcherX.getOutput1().getVoltage());
|
||||
assertEquals(voltageX1, switcherX1.getVoltage());
|
||||
assertEquals(voltageX1, switcher1.getOutput1().getVoltage());
|
||||
|
||||
assertEquals(voltage, switcher1.getCommon().getVoltage());
|
||||
assertEquals(voltage, output.getVoltage());
|
||||
assertEquals(voltage, light.getPlus().getVoltage());
|
||||
assertEquals(voltage, light.getVoltage());
|
||||
|
||||
assertEquals(0, light.getMinus().getVoltage());
|
||||
assertEquals(0, minus.getVoltage());
|
||||
assertFalse(light.isDefect());
|
||||
|
||||
assertEquals(0, battery.getMinus().getVoltage());
|
||||
|
||||
assertFalse(light.isDefect());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user