Position serialization FIX
This commit is contained in:
parent
81375c94e9
commit
857d7252a6
@ -9,19 +9,12 @@ import de.ph87.electro.circuit.wire.Wire;
|
||||
import de.ph87.electro.circuit.wire.WireDto;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static de.ph87.electro.circuit.CircuitIOService.write;
|
||||
|
||||
@Slf4j
|
||||
@NoArgsConstructor
|
||||
public class Circuit {
|
||||
|
||||
@ -46,19 +39,9 @@ public class Circuit {
|
||||
|
||||
public void connect(final Junction a, final Junction b) {
|
||||
wires.add(new Wire(a, b));
|
||||
evaluateAndRender();
|
||||
}
|
||||
|
||||
public void evaluateAndRender() {
|
||||
try {
|
||||
final File file = new File("./data/circuit.json");
|
||||
if (file.getParentFile().mkdirs()) {
|
||||
log.info("Directory created: {}", file.getParent());
|
||||
}
|
||||
write(this, new FileOutputStream(file));
|
||||
} catch (IOException e) {
|
||||
log.error(e.toString());
|
||||
}
|
||||
public void evaluate() {
|
||||
Calculation.calculate(this);
|
||||
parts.forEach(Part::render);
|
||||
}
|
||||
@ -67,10 +50,11 @@ public class Circuit {
|
||||
if (parts.contains(part)) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
if (isFree(part.getPosition())) {
|
||||
if (!isFree(part.getPosition())) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
parts.add(part);
|
||||
part.render();
|
||||
}
|
||||
return part;
|
||||
}
|
||||
|
||||
@ -122,7 +106,6 @@ public class Circuit {
|
||||
wires.remove(wire);
|
||||
wire.getA().getWires().remove(wire);
|
||||
wire.getB().getWires().remove(wire);
|
||||
evaluateAndRender();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,14 +1,20 @@
|
||||
package de.ph87.electro.circuit;
|
||||
|
||||
import de.ph87.electro.circuit.part.Position;
|
||||
import de.ph87.electro.circuit.part.parts.PartBattery;
|
||||
import de.ph87.electro.circuit.part.parts.PartLight;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static de.ph87.electro.CONFIG.*;
|
||||
import static de.ph87.electro.circuit.CircuitIOService.write;
|
||||
import static de.ph87.electro.circuit.part.Position.RST;
|
||||
|
||||
@Slf4j
|
||||
public class CircuitPanel extends JPanel {
|
||||
|
||||
private final Circuit circuit = new Circuit();
|
||||
@ -17,10 +23,11 @@ public class CircuitPanel extends JPanel {
|
||||
|
||||
public CircuitPanel() {
|
||||
new CircuitPanelDropTarget(this, circuit);
|
||||
final PartBattery battery = circuit.addPart(new PartBattery(Position.ofRaster(0, 0)));
|
||||
final PartLight light = circuit.addPart(new PartLight(Position.ofRaster(0, 1)));
|
||||
final PartBattery battery = circuit.addPart(new PartBattery(RST(0, 0)));
|
||||
final PartLight light = circuit.addPart(new PartLight(RST(0, 1)));
|
||||
circuit.connect(battery.getMinus(), light.getA());
|
||||
circuit.connect(light.getB(), battery.getPlus());
|
||||
circuit.evaluate();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,4 +67,23 @@ public class CircuitPanel extends JPanel {
|
||||
circuit.streamWires().forEach(wire -> wire.draw(g));
|
||||
}
|
||||
|
||||
public void evaluate() {
|
||||
circuit.evaluate();
|
||||
save();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
// TODO make async
|
||||
try {
|
||||
final File file = new File("./data/circuit.json");
|
||||
if (file.getParentFile().mkdirs()) {
|
||||
log.info("Directory created: {}", file.getParent());
|
||||
}
|
||||
write(circuit, new FileOutputStream(file));
|
||||
} catch (IOException e) {
|
||||
log.error(e.toString());
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ public class CircuitPanelDropTarget extends AbstractDropTarget {
|
||||
|
||||
public void addPart(final Part part) {
|
||||
circuit.addPart(part);
|
||||
circuitPanel.repaint();
|
||||
circuitPanel.evaluate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package de.ph87.electro.circuit;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.Position;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.wire.Wire;
|
||||
|
||||
import java.awt.*;
|
||||
@ -47,7 +47,7 @@ class CircuitPanelMouseAdapter extends MouseAdapter {
|
||||
final Optional<Wire> wireOptional = circuit.findWireByPosition(position);
|
||||
if (wireOptional.isPresent()) {
|
||||
circuit.removeWire(wireOptional.get());
|
||||
circuitPanel.repaint();
|
||||
circuitPanel.evaluate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -56,12 +56,11 @@ class CircuitPanelMouseAdapter extends MouseAdapter {
|
||||
switch (event.getButton()) {
|
||||
case BUTTON1:
|
||||
partOptional.ifPresent(Part::action);
|
||||
circuit.evaluateAndRender();
|
||||
circuitPanel.repaint();
|
||||
circuitPanel.evaluate();
|
||||
break;
|
||||
case BUTTON3:
|
||||
partOptional.ifPresent(Part::clockwise);
|
||||
circuitPanel.repaint();
|
||||
circuitPanel.save();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -117,10 +116,14 @@ class CircuitPanelMouseAdapter extends MouseAdapter {
|
||||
final Position position = new Position(event);
|
||||
if (partDrag != null) {
|
||||
circuit.movePart(partDrag, position);
|
||||
circuitPanel.save();
|
||||
}
|
||||
|
||||
if (junctionDrag != null) {
|
||||
circuit.findJunctionByAbsolute(position).filter(destination -> destination != junctionDrag).ifPresent(destination -> circuit.connect(junctionDrag, destination));
|
||||
circuit.findJunctionByAbsolute(position).filter(destination -> destination != junctionDrag).ifPresent(destination -> {
|
||||
circuit.connect(junctionDrag, destination);
|
||||
circuitPanel.evaluate();
|
||||
});
|
||||
}
|
||||
|
||||
partDrag = null;
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
package de.ph87.electro.circuit.calculation;
|
||||
|
||||
import de.ph87.electro.circuit.Circuit;
|
||||
import de.ph87.electro.circuit.wire.Wire;
|
||||
import de.ph87.electro.circuit.part.InnerConnection;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.parts.PartBattery;
|
||||
import de.ph87.electro.circuit.part.parts.PartLight;
|
||||
import de.ph87.electro.circuit.wire.Wire;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@ -43,8 +43,8 @@ public abstract class Part {
|
||||
protected Part(final PartDto dto) {
|
||||
this.uuid = dto.getUuid();
|
||||
this.name = dto.getName();
|
||||
setPosition(dto.getPosition());
|
||||
this.orientation = dto.getOrientation();
|
||||
setPosition(new Position(dto.getPosition()));
|
||||
}
|
||||
|
||||
protected Junction newJunction(final Part owner, final String name, final int x, final int y) {
|
||||
|
||||
@ -1,36 +1,32 @@
|
||||
package de.ph87.electro.circuit.part;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.parts.*;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.List;
|
||||
import java.awt.*;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.MINIMAL_CLASS)
|
||||
public class PartDto {
|
||||
public abstract class PartDto {
|
||||
|
||||
private String uuid;
|
||||
|
||||
private String name;
|
||||
|
||||
private Position position;
|
||||
private Point position;
|
||||
|
||||
private Orientation orientation;
|
||||
|
||||
private List<JunctionDto> junctions;
|
||||
|
||||
protected PartDto(final Part part) {
|
||||
this.uuid = part.getUuid();
|
||||
this.name = part.getName();
|
||||
this.position = part.getPosition();
|
||||
this.position = part.getPosition().absolute;
|
||||
this.orientation = part.getOrientation();
|
||||
this.junctions = part.getJunctions().stream().map(JunctionDto::new).toList();
|
||||
}
|
||||
|
||||
public static PartDto of(final Part abstractPart) {
|
||||
|
||||
@ -22,14 +22,26 @@ public final class Position {
|
||||
|
||||
public final Point raster;
|
||||
|
||||
public Position(final int x, final int y) {
|
||||
this.absolute = new Point(x, y);
|
||||
this.raster = new Point(x / RASTER, y / RASTER);
|
||||
this.inside = new Point(x % RASTER, y % RASTER);
|
||||
public static Position ABS(final double absoluteX, final double absoluteY) {
|
||||
return new Position((int) round(absoluteX), (int) round(absoluteY));
|
||||
}
|
||||
|
||||
public static Position ofRaster(final int x, final int y) {
|
||||
return new Position(x * RASTER, y * RASTER);
|
||||
public static Position RST(final int x, final int y) {
|
||||
return ABS(x * RASTER, y * RASTER);
|
||||
}
|
||||
|
||||
private Position(final int absoluteX, final int absoluteY) {
|
||||
this.absolute = new Point(absoluteX, absoluteY);
|
||||
this.raster = new Point(absoluteX / RASTER, absoluteY / RASTER);
|
||||
this.inside = new Point(absoluteX % RASTER, absoluteY % RASTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (!(obj instanceof final Position other)) {
|
||||
return false;
|
||||
}
|
||||
return absolute.equals(other.absolute);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,10 +49,6 @@ public final class Position {
|
||||
return absolute.hashCode();
|
||||
}
|
||||
|
||||
public Position(final double x, final double y) {
|
||||
this((int) round(x), (int) round(y));
|
||||
}
|
||||
|
||||
public Position(final Point point) {
|
||||
this(point.x, point.y);
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.Orientation;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.Position;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@ -12,6 +12,7 @@ import java.awt.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static de.ph87.electro.CONFIG.*;
|
||||
import static de.ph87.electro.circuit.part.Position.ABS;
|
||||
|
||||
@Getter
|
||||
@ToString(callSuper = true, onlyExplicitlyIncluded = true)
|
||||
@ -39,10 +40,6 @@ public class PartBattery extends Part {
|
||||
@ToString.Include
|
||||
private double resistance = 0.05;
|
||||
|
||||
public PartBattery() {
|
||||
this(Position.ZERO);
|
||||
}
|
||||
|
||||
public PartBattery(final Position position) {
|
||||
super("Batterie", position);
|
||||
minus = newJunction(this, "MINUS", P10, P50);
|
||||
@ -59,10 +56,10 @@ public class PartBattery extends Part {
|
||||
@Override
|
||||
protected void _render() {
|
||||
render.clockwise(getOrientation());
|
||||
render.line(new Position(P10, P50), new Position(P50 - GAP / 2 - MINUS_W / 2, P50), Color.BLACK, SYMBOL_STROKE);
|
||||
render.line(new Position(P50 + GAP / 2 + PLUS_W / 2, P50), new Position(P90, P50), Color.BLACK, SYMBOL_STROKE);
|
||||
render.rect(new Position(P50 - MINUS_W - GAP / 2, P50 - MINUS_H / 2), MINUS_W, MINUS_H, null, null, Color.BLACK);
|
||||
render.rect(new Position(P50 + GAP / 2, P50 - PLUS_H / 2), PLUS_W, PLUS_H, null, null, Color.BLACK);
|
||||
render.line(ABS(P10, P50), ABS(P50 - GAP / 2 - MINUS_W / 2, P50), Color.BLACK, SYMBOL_STROKE);
|
||||
render.line(ABS(P50 + GAP / 2 + PLUS_W / 2, P50), ABS(P90, P50), Color.BLACK, SYMBOL_STROKE);
|
||||
render.rect(ABS(P50 - MINUS_W - GAP / 2, P50 - MINUS_H / 2), MINUS_W, MINUS_H, null, null, Color.BLACK);
|
||||
render.rect(ABS(P50 + GAP / 2, P50 - PLUS_H / 2), PLUS_W, PLUS_H, null, null, Color.BLACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.PartOther;
|
||||
import de.ph87.electro.circuit.part.Position;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -17,10 +17,6 @@ public class PartJunctionCorner extends PartOther {
|
||||
|
||||
private final Junction j1;
|
||||
|
||||
public PartJunctionCorner() {
|
||||
this(Position.ZERO);
|
||||
}
|
||||
|
||||
public PartJunctionCorner(final Position position) {
|
||||
super("", position);
|
||||
j0 = newJunction(this, "J0", P10, P10);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.PartOther;
|
||||
import de.ph87.electro.circuit.part.Position;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -17,10 +17,6 @@ public class PartJunctionEdge extends PartOther {
|
||||
|
||||
private final Junction j1;
|
||||
|
||||
public PartJunctionEdge() {
|
||||
this(Position.ZERO);
|
||||
}
|
||||
|
||||
public PartJunctionEdge(final Position position) {
|
||||
super("", position);
|
||||
j0 = newJunction(this, "J0", P10, P50);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.PartOther;
|
||||
import de.ph87.electro.circuit.part.Position;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -14,10 +14,6 @@ public class PartJunctionMiddle extends PartOther {
|
||||
|
||||
private final Junction junction;
|
||||
|
||||
public PartJunctionMiddle() {
|
||||
this(Position.ZERO);
|
||||
}
|
||||
|
||||
public PartJunctionMiddle(final Position position) {
|
||||
super("", position);
|
||||
junction = newJunction(this, "J", P50, P50);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.*;
|
||||
import de.ph87.electro.circuit.part.InnerConnection;
|
||||
import de.ph87.electro.circuit.part.Orientation;
|
||||
import de.ph87.electro.circuit.part.PartOther;
|
||||
import de.ph87.electro.circuit.part.Position;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
@ -10,6 +13,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static de.ph87.electro.CONFIG.*;
|
||||
import static de.ph87.electro.circuit.part.Position.ABS;
|
||||
import static java.lang.Math.abs;
|
||||
import static java.lang.Math.round;
|
||||
|
||||
@ -49,10 +53,6 @@ public class PartLight extends PartOther {
|
||||
|
||||
private Color color = BULB_OFF_COLOR;
|
||||
|
||||
public PartLight() {
|
||||
this(Position.ZERO);
|
||||
}
|
||||
|
||||
public PartLight(final Position position) {
|
||||
super("Licht", position);
|
||||
a = newJunction(this, "A", P10, P50);
|
||||
@ -89,11 +89,11 @@ public class PartLight extends PartOther {
|
||||
@Override
|
||||
protected void _render() {
|
||||
render.line(a, b, Color.BLACK, SYMBOL_STROKE);
|
||||
render.circle(new Position(P50, P50), BULB_RADIUS, Color.BLACK, SYMBOL_STROKE, color);
|
||||
render.circle(ABS(P50, P50), BULB_RADIUS, Color.BLACK, SYMBOL_STROKE, color);
|
||||
|
||||
final double diag = 0.33 * RASTER;
|
||||
render.line(new Position(diag, diag), new Position(RASTER - diag, RASTER - diag), Color.BLACK, SYMBOL_STROKE);
|
||||
render.line(new Position(diag, RASTER - diag), new Position(RASTER - diag, diag), Color.BLACK, SYMBOL_STROKE);
|
||||
render.line(ABS(diag, diag), ABS(RASTER - diag, RASTER - diag), Color.BLACK, SYMBOL_STROKE);
|
||||
render.line(ABS(diag, RASTER - diag), ABS(RASTER - diag, diag), Color.BLACK, SYMBOL_STROKE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.InnerConnection;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.PartOther;
|
||||
import de.ph87.electro.circuit.part.Position;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@ -25,10 +25,6 @@ public class PartSwitch1x1 extends PartOther {
|
||||
@Setter
|
||||
private boolean state = false;
|
||||
|
||||
public PartSwitch1x1() {
|
||||
this(Position.ZERO);
|
||||
}
|
||||
|
||||
public PartSwitch1x1(final Position position) {
|
||||
super("Ausschalter", position);
|
||||
common = newJunction(this, "C", P10, P50);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.InnerConnection;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.PartOther;
|
||||
import de.ph87.electro.circuit.part.Position;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@ -26,10 +26,6 @@ public class PartSwitch1x2 extends PartOther {
|
||||
@Setter
|
||||
private boolean state = false;
|
||||
|
||||
public PartSwitch1x2() {
|
||||
this(Position.ZERO);
|
||||
}
|
||||
|
||||
public PartSwitch1x2(final Position position) {
|
||||
super("Wechselschalter", position);
|
||||
common = newJunction(this, "C", P10, P50);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.InnerConnection;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.PartOther;
|
||||
import de.ph87.electro.circuit.part.Position;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@ -28,10 +28,6 @@ public class PartSwitchCross extends PartOther {
|
||||
@Setter
|
||||
private boolean state = false;
|
||||
|
||||
public PartSwitchCross() {
|
||||
this(Position.ZERO);
|
||||
}
|
||||
|
||||
public PartSwitchCross(final Position position) {
|
||||
super("Kreuzschalter", position);
|
||||
common0 = newJunction(this, "C0", P10, P25);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.wire;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.Position;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package de.ph87.electro.sidebar;
|
||||
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.Position;
|
||||
import de.ph87.electro.circuit.part.parts.*;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -27,14 +28,14 @@ public class Sidebar extends JPanel {
|
||||
});
|
||||
add(toggleDetails);
|
||||
|
||||
add(new PartBattery());
|
||||
add(new PartJunctionCorner());
|
||||
add(new PartJunctionEdge());
|
||||
add(new PartJunctionMiddle());
|
||||
add(new PartLight());
|
||||
add(new PartSwitch1x1());
|
||||
add(new PartSwitch1x2());
|
||||
add(new PartSwitchCross());
|
||||
add(new PartBattery(Position.ZERO));
|
||||
add(new PartJunctionCorner(Position.ZERO));
|
||||
add(new PartJunctionEdge(Position.ZERO));
|
||||
add(new PartJunctionMiddle(Position.ZERO));
|
||||
add(new PartLight(Position.ZERO));
|
||||
add(new PartSwitch1x1(Position.ZERO));
|
||||
add(new PartSwitch1x2(Position.ZERO));
|
||||
add(new PartSwitchCross(Position.ZERO));
|
||||
setPreferredSize(new Dimension(0, 200));
|
||||
}
|
||||
|
||||
|
||||
12
src/test/java/de/ph87/electro/circuit/AssertHelper.java
Normal file
12
src/test/java/de/ph87/electro/circuit/AssertHelper.java
Normal file
@ -0,0 +1,12 @@
|
||||
package de.ph87.electro.circuit;
|
||||
|
||||
import static java.lang.Math.abs;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class AssertHelper {
|
||||
|
||||
public static void assertVoltage(final double expected, final double actual) {
|
||||
assertTrue(abs(expected - actual) <= 0.1);
|
||||
}
|
||||
|
||||
}
|
||||
@ -8,14 +8,16 @@ import de.ph87.electro.circuit.wire.Wire;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static de.ph87.electro.circuit.part.Position.RST;
|
||||
|
||||
@Slf4j
|
||||
class CalculationServiceTest {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
final Circuit circuit = new Circuit();
|
||||
final PartBattery battery = circuit.addPart(new PartBattery());
|
||||
final PartLight light = circuit.addPart(new PartLight());
|
||||
final PartBattery battery = circuit.addPart(new PartBattery(RST(0, 0)));
|
||||
final PartLight light = circuit.addPart(new PartLight(RST(0, 1)));
|
||||
circuit.connect(battery.getMinus(), light.getA());
|
||||
circuit.connect(battery.getPlus(), light.getB());
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package de.ph87.electro.circuit.io;
|
||||
|
||||
import de.ph87.electro.circuit.Circuit;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.parts.PartBattery;
|
||||
import de.ph87.electro.circuit.part.parts.PartLight;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -14,6 +14,7 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static de.ph87.electro.circuit.CircuitIOService.read;
|
||||
import static de.ph87.electro.circuit.CircuitIOService.write;
|
||||
import static de.ph87.electro.circuit.part.Position.RST;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class CircuitIOServiceTest {
|
||||
@ -21,8 +22,8 @@ class CircuitIOServiceTest {
|
||||
@Test
|
||||
void serialization() throws IOException {
|
||||
final Circuit circuit = new Circuit();
|
||||
final PartBattery battery = circuit.addPart(new PartBattery());
|
||||
final PartLight light = circuit.addPart(new PartLight());
|
||||
final PartBattery battery = circuit.addPart(new PartBattery(RST(0, 0)));
|
||||
final PartLight light = circuit.addPart(new PartLight(RST(0, 1)));
|
||||
circuit.connect(battery.getPlus(), light.getB());
|
||||
circuit.connect(light.getA(), battery.getMinus());
|
||||
check(circuit);
|
||||
@ -31,13 +32,14 @@ class CircuitIOServiceTest {
|
||||
private void check(final Circuit original) throws IOException {
|
||||
final ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
write(original, output);
|
||||
|
||||
System.out.println(output.toString(StandardCharsets.UTF_8));
|
||||
|
||||
final ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
|
||||
final Circuit reloaded = read(input);
|
||||
|
||||
original.evaluateAndRender();
|
||||
reloaded.evaluateAndRender();
|
||||
original.evaluate();
|
||||
reloaded.evaluate();
|
||||
|
||||
assertEquals(original.getPartCount(), reloaded.getPartCount());
|
||||
original.streamParts().forEach(originalPart -> {
|
||||
|
||||
@ -4,7 +4,8 @@ import de.ph87.electro.circuit.Circuit;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static de.ph87.electro.circuit.AssertHelper.assertVoltage;
|
||||
import static de.ph87.electro.circuit.part.Position.RST;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
public class BatteryLightTest {
|
||||
@ -13,9 +14,9 @@ public class BatteryLightTest {
|
||||
|
||||
private static final Circuit CIRCUIT = new Circuit();
|
||||
|
||||
private static final PartBattery battery = CIRCUIT.addPart(new PartBattery());
|
||||
private static final PartBattery battery = CIRCUIT.addPart(new PartBattery(RST(0, 0)));
|
||||
|
||||
private static final PartLight light = CIRCUIT.addPart(new PartLight());
|
||||
private static final PartLight light = CIRCUIT.addPart(new PartLight(RST(0, 1)));
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
@ -25,14 +26,14 @@ public class BatteryLightTest {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
CIRCUIT.evaluateAndRender();
|
||||
CIRCUIT.evaluate();
|
||||
|
||||
assertEquals(VOLTAGE, battery.getPlus().getVoltage());
|
||||
assertEquals(VOLTAGE, light.getB().getVoltage());
|
||||
assertEquals(VOLTAGE, light.getPotentialDifference());
|
||||
assertVoltage(VOLTAGE, battery.getPlus().getVoltage());
|
||||
assertVoltage(VOLTAGE, light.getB().getVoltage());
|
||||
assertVoltage(VOLTAGE, light.getPotentialDifference());
|
||||
|
||||
assertEquals(0, light.getA().getVoltage());
|
||||
assertEquals(0, battery.getMinus().getVoltage());
|
||||
assertVoltage(0, light.getA().getVoltage());
|
||||
assertVoltage(0, battery.getMinus().getVoltage());
|
||||
|
||||
assertFalse(light.isDefect());
|
||||
}
|
||||
|
||||
@ -4,6 +4,8 @@ import de.ph87.electro.circuit.Circuit;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static de.ph87.electro.circuit.AssertHelper.assertVoltage;
|
||||
import static de.ph87.electro.circuit.part.Position.RST;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
@ -13,11 +15,11 @@ public class BatterySwitcher1x1Test {
|
||||
|
||||
private static final Circuit CIRCUIT = new Circuit();
|
||||
|
||||
private static final PartBattery battery = CIRCUIT.addPart(new PartBattery());
|
||||
private static final PartBattery battery = CIRCUIT.addPart(new PartBattery(RST(0, 0)));
|
||||
|
||||
private static final PartSwitch1x1 switcher = CIRCUIT.addPart(new PartSwitch1x1());
|
||||
private static final PartSwitch1x1 switcher = CIRCUIT.addPart(new PartSwitch1x1(RST(0, 1)));
|
||||
|
||||
private static final PartLight light = CIRCUIT.addPart(new PartLight());
|
||||
private static final PartLight light = CIRCUIT.addPart(new PartLight(RST(1, 0)));
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
@ -37,23 +39,23 @@ public class BatterySwitcher1x1Test {
|
||||
}
|
||||
|
||||
private void test(final boolean state) {
|
||||
final double voltage = state ? VOLTAGE : Double.NaN;
|
||||
final double voltage = state ? VOLTAGE : 0.0;
|
||||
|
||||
switcher.setState(state);
|
||||
|
||||
CIRCUIT.evaluateAndRender();
|
||||
CIRCUIT.evaluate();
|
||||
|
||||
assertEquals(state, switcher.isState());
|
||||
|
||||
assertEquals(VOLTAGE, battery.getPlus().getVoltage());
|
||||
assertEquals(VOLTAGE, switcher.getCommon().getVoltage());
|
||||
assertVoltage(VOLTAGE, battery.getPlus().getVoltage());
|
||||
assertVoltage(VOLTAGE, switcher.getCommon().getVoltage());
|
||||
|
||||
assertEquals(voltage, switcher.getOutput().getVoltage());
|
||||
assertEquals(voltage, light.getB().getVoltage());
|
||||
assertEquals(voltage, light.getPotentialDifference());
|
||||
assertVoltage(voltage, switcher.getOutput().getVoltage());
|
||||
assertVoltage(voltage, light.getB().getVoltage());
|
||||
assertVoltage(voltage, light.getPotentialDifference());
|
||||
|
||||
assertEquals(0, light.getA().getVoltage());
|
||||
assertEquals(0, battery.getMinus().getVoltage());
|
||||
assertVoltage(0, light.getA().getVoltage());
|
||||
assertVoltage(0, battery.getMinus().getVoltage());
|
||||
|
||||
assertFalse(light.isDefect());
|
||||
}
|
||||
|
||||
@ -4,6 +4,8 @@ import de.ph87.electro.circuit.Circuit;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static de.ph87.electro.circuit.AssertHelper.assertVoltage;
|
||||
import static de.ph87.electro.circuit.part.Position.RST;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
@ -13,13 +15,13 @@ public class BatterySwitcher1x2Test {
|
||||
|
||||
private static final Circuit CIRCUIT = new Circuit();
|
||||
|
||||
private static final PartBattery battery = CIRCUIT.addPart(new PartBattery());
|
||||
private static final PartBattery battery = CIRCUIT.addPart(new PartBattery(RST(0, 0)));
|
||||
|
||||
private static final PartSwitch1x2 switcher = CIRCUIT.addPart(new PartSwitch1x2());
|
||||
private static final PartSwitch1x2 switcher = CIRCUIT.addPart(new PartSwitch1x2(RST(0, 2)));
|
||||
|
||||
private static final PartLight light0 = CIRCUIT.addPart(new PartLight());
|
||||
private static final PartLight light0 = CIRCUIT.addPart(new PartLight(RST(1, 1)));
|
||||
|
||||
private static final PartLight light1 = CIRCUIT.addPart(new PartLight());
|
||||
private static final PartLight light1 = CIRCUIT.addPart(new PartLight(RST(1, 3)));
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
@ -41,29 +43,29 @@ public class BatterySwitcher1x2Test {
|
||||
}
|
||||
|
||||
private void test(final boolean state) {
|
||||
final double voltage0 = state ? Double.NaN : VOLTAGE;
|
||||
final double voltage1 = state ? VOLTAGE : Double.NaN;
|
||||
final double voltage0 = state ? 0.0 : VOLTAGE;
|
||||
final double voltage1 = state ? VOLTAGE : 0.0;
|
||||
|
||||
switcher.setState(state);
|
||||
|
||||
CIRCUIT.evaluateAndRender();
|
||||
CIRCUIT.evaluate();
|
||||
|
||||
assertEquals(state, switcher.isState());
|
||||
|
||||
assertEquals(VOLTAGE, battery.getPlus().getVoltage());
|
||||
assertEquals(VOLTAGE, switcher.getCommon().getVoltage());
|
||||
assertVoltage(VOLTAGE, battery.getPlus().getVoltage());
|
||||
assertVoltage(VOLTAGE, switcher.getCommon().getVoltage());
|
||||
|
||||
assertEquals(voltage0, switcher.getOutput0().getVoltage());
|
||||
assertEquals(voltage0, light0.getB().getVoltage());
|
||||
assertEquals(voltage0, light0.getPotentialDifference());
|
||||
assertVoltage(voltage0, switcher.getOutput0().getVoltage());
|
||||
assertVoltage(voltage0, light0.getB().getVoltage());
|
||||
assertVoltage(voltage0, light0.getPotentialDifference());
|
||||
|
||||
assertEquals(voltage1, switcher.getOutput1().getVoltage());
|
||||
assertEquals(voltage1, light1.getB().getVoltage());
|
||||
assertEquals(voltage1, light1.getPotentialDifference());
|
||||
assertVoltage(voltage1, switcher.getOutput1().getVoltage());
|
||||
assertVoltage(voltage1, light1.getB().getVoltage());
|
||||
assertVoltage(voltage1, light1.getPotentialDifference());
|
||||
|
||||
assertEquals(0, light0.getA().getVoltage());
|
||||
assertEquals(0, light1.getA().getVoltage());
|
||||
assertEquals(0, battery.getMinus().getVoltage());
|
||||
assertVoltage(0, light0.getA().getVoltage());
|
||||
assertVoltage(0, light1.getA().getVoltage());
|
||||
assertVoltage(0, battery.getMinus().getVoltage());
|
||||
|
||||
assertFalse(light0.isDefect());
|
||||
assertFalse(light1.isDefect());
|
||||
|
||||
@ -4,6 +4,8 @@ import de.ph87.electro.circuit.Circuit;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static de.ph87.electro.circuit.AssertHelper.assertVoltage;
|
||||
import static de.ph87.electro.circuit.part.Position.RST;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
@ -13,13 +15,13 @@ public class BatterySwitcher2x2Test {
|
||||
|
||||
private static final Circuit CIRCUIT = new Circuit();
|
||||
|
||||
private static final PartBattery battery = CIRCUIT.addPart(new PartBattery());
|
||||
private static final PartBattery battery = CIRCUIT.addPart(new PartBattery(RST(0, 0)));
|
||||
|
||||
private static final PartSwitch1x2 switcher0 = CIRCUIT.addPart(new PartSwitch1x2());
|
||||
private static final PartSwitch1x2 switcher0 = CIRCUIT.addPart(new PartSwitch1x2(RST(0, 1)));
|
||||
|
||||
private static final PartSwitch1x2 switcher1 = CIRCUIT.addPart(new PartSwitch1x2());
|
||||
private static final PartSwitch1x2 switcher1 = CIRCUIT.addPart(new PartSwitch1x2(RST(1, 1)));
|
||||
|
||||
private static final PartLight light = CIRCUIT.addPart(new PartLight());
|
||||
private static final PartLight light = CIRCUIT.addPart(new PartLight(RST(1, 0)));
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
@ -51,33 +53,33 @@ public class BatterySwitcher2x2Test {
|
||||
}
|
||||
|
||||
private void test(final boolean state0, final boolean state1) {
|
||||
final double voltage0 = state0 ? Double.NaN : VOLTAGE;
|
||||
final double voltage1 = state0 ? VOLTAGE : Double.NaN;
|
||||
final double voltage0 = state0 ? 0.0 : VOLTAGE;
|
||||
final double voltage1 = state0 ? VOLTAGE : 0.0;
|
||||
final double voltage = state1 ? voltage1 : voltage0;
|
||||
|
||||
switcher0.setState(state0);
|
||||
switcher1.setState(state1);
|
||||
|
||||
CIRCUIT.evaluateAndRender();
|
||||
CIRCUIT.evaluate();
|
||||
|
||||
assertEquals(state0, switcher0.isState());
|
||||
assertEquals(state1, switcher1.isState());
|
||||
|
||||
assertEquals(VOLTAGE, battery.getPlus().getVoltage());
|
||||
assertEquals(VOLTAGE, switcher0.getCommon().getVoltage());
|
||||
assertVoltage(VOLTAGE, battery.getPlus().getVoltage());
|
||||
assertVoltage(VOLTAGE, switcher0.getCommon().getVoltage());
|
||||
|
||||
assertEquals(voltage0, switcher0.getOutput0().getVoltage());
|
||||
assertEquals(voltage0, switcher1.getOutput0().getVoltage());
|
||||
assertVoltage(voltage0, switcher0.getOutput0().getVoltage());
|
||||
assertVoltage(voltage0, switcher1.getOutput0().getVoltage());
|
||||
|
||||
assertEquals(voltage1, switcher0.getOutput1().getVoltage());
|
||||
assertEquals(voltage1, switcher1.getOutput1().getVoltage());
|
||||
assertVoltage(voltage1, switcher0.getOutput1().getVoltage());
|
||||
assertVoltage(voltage1, switcher1.getOutput1().getVoltage());
|
||||
|
||||
assertEquals(voltage, switcher1.getCommon().getVoltage());
|
||||
assertEquals(voltage, light.getB().getVoltage());
|
||||
assertEquals(voltage, light.getPotentialDifference());
|
||||
assertVoltage(voltage, switcher1.getCommon().getVoltage());
|
||||
assertVoltage(voltage, light.getB().getVoltage());
|
||||
assertVoltage(voltage, light.getPotentialDifference());
|
||||
|
||||
assertEquals(0, light.getA().getVoltage());
|
||||
assertEquals(0, battery.getMinus().getVoltage());
|
||||
assertVoltage(0, light.getA().getVoltage());
|
||||
assertVoltage(0, battery.getMinus().getVoltage());
|
||||
|
||||
assertFalse(light.isDefect());
|
||||
}
|
||||
|
||||
@ -4,6 +4,8 @@ import de.ph87.electro.circuit.Circuit;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static de.ph87.electro.circuit.AssertHelper.assertVoltage;
|
||||
import static de.ph87.electro.circuit.part.Position.RST;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
@ -13,15 +15,15 @@ public class BatterySwitcherCrossTest {
|
||||
|
||||
private static final Circuit CIRCUIT = new Circuit();
|
||||
|
||||
private static final PartBattery battery = CIRCUIT.addPart(new PartBattery());
|
||||
private static final PartBattery battery = CIRCUIT.addPart(new PartBattery(RST(0, 0)));
|
||||
|
||||
private static final PartSwitch1x2 switcher0 = CIRCUIT.addPart(new PartSwitch1x2());
|
||||
private static final PartSwitch1x2 switcher0 = CIRCUIT.addPart(new PartSwitch1x2(RST(0, 1)));
|
||||
|
||||
private static final PartSwitchCross switcherX = CIRCUIT.addPart(new PartSwitchCross());
|
||||
private static final PartSwitchCross switcherX = CIRCUIT.addPart(new PartSwitchCross(RST(1, 1)));
|
||||
|
||||
private static final PartSwitch1x2 switcher1 = CIRCUIT.addPart(new PartSwitch1x2());
|
||||
private static final PartSwitch1x2 switcher1 = CIRCUIT.addPart(new PartSwitch1x2(RST(2, 1)));
|
||||
|
||||
private static final PartLight light = CIRCUIT.addPart(new PartLight());
|
||||
private static final PartLight light = CIRCUIT.addPart(new PartLight(RST(2, 0)));
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
@ -75,8 +77,8 @@ public class BatterySwitcherCrossTest {
|
||||
}
|
||||
|
||||
private void test(final boolean state0, final boolean stateX, final boolean state1) {
|
||||
final double voltage00 = state0 ? Double.NaN : VOLTAGE;
|
||||
final double voltage01 = state0 ? VOLTAGE : Double.NaN;
|
||||
final double voltage00 = state0 ? 0.0 : VOLTAGE;
|
||||
final double voltage01 = state0 ? VOLTAGE : 0.0;
|
||||
final double voltageX0 = stateX ? voltage01 : voltage00;
|
||||
final double voltageX1 = stateX ? voltage00 : voltage01;
|
||||
final double voltage = state1 ? voltageX1 : voltageX0;
|
||||
@ -85,33 +87,33 @@ public class BatterySwitcherCrossTest {
|
||||
switcherX.setState(stateX);
|
||||
switcher1.setState(state1);
|
||||
|
||||
CIRCUIT.evaluateAndRender();
|
||||
CIRCUIT.evaluate();
|
||||
|
||||
assertEquals(state0, switcher0.isState());
|
||||
assertEquals(stateX, switcherX.isState());
|
||||
assertEquals(state1, switcher1.isState());
|
||||
|
||||
assertEquals(VOLTAGE, battery.getPlus().getVoltage());
|
||||
assertEquals(VOLTAGE, switcher0.getCommon().getVoltage());
|
||||
assertVoltage(VOLTAGE, battery.getPlus().getVoltage());
|
||||
assertVoltage(VOLTAGE, switcher0.getCommon().getVoltage());
|
||||
|
||||
assertEquals(voltage00, switcher0.getOutput0().getVoltage());
|
||||
assertEquals(voltage00, switcherX.getCommon0().getVoltage());
|
||||
assertVoltage(voltage00, switcher0.getOutput0().getVoltage());
|
||||
assertVoltage(voltage00, switcherX.getCommon0().getVoltage());
|
||||
|
||||
assertEquals(voltage01, switcher0.getOutput1().getVoltage());
|
||||
assertEquals(voltage01, switcherX.getCommon1().getVoltage());
|
||||
assertVoltage(voltage01, switcher0.getOutput1().getVoltage());
|
||||
assertVoltage(voltage01, switcherX.getCommon1().getVoltage());
|
||||
|
||||
assertEquals(voltageX0, switcherX.getOutput0().getVoltage());
|
||||
assertEquals(voltageX0, switcher1.getOutput0().getVoltage());
|
||||
assertVoltage(voltageX0, switcherX.getOutput0().getVoltage());
|
||||
assertVoltage(voltageX0, switcher1.getOutput0().getVoltage());
|
||||
|
||||
assertEquals(voltageX1, switcherX.getOutput1().getVoltage());
|
||||
assertEquals(voltageX1, switcher1.getOutput1().getVoltage());
|
||||
assertVoltage(voltageX1, switcherX.getOutput1().getVoltage());
|
||||
assertVoltage(voltageX1, switcher1.getOutput1().getVoltage());
|
||||
|
||||
assertEquals(voltage, switcher1.getCommon().getVoltage());
|
||||
assertEquals(voltage, light.getB().getVoltage());
|
||||
assertEquals(voltage, light.getPotentialDifference());
|
||||
assertVoltage(voltage, switcher1.getCommon().getVoltage());
|
||||
assertVoltage(voltage, light.getB().getVoltage());
|
||||
assertVoltage(voltage, light.getPotentialDifference());
|
||||
|
||||
assertEquals(0, light.getA().getVoltage());
|
||||
assertEquals(0, battery.getMinus().getVoltage());
|
||||
assertVoltage(0, light.getA().getVoltage());
|
||||
assertVoltage(0, battery.getMinus().getVoltage());
|
||||
|
||||
assertFalse(light.isDefect());
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user