From 25e6d6d4204e2ae0b98e134623fc58f1e7ffc0fa Mon Sep 17 00:00:00 2001 From: hneemann Date: Tue, 19 Apr 2016 08:40:33 +0200 Subject: [PATCH] ensure examples a buildable --- src/main/dig/combinatorial/MultiplyTest.dig | 566 ++++++++++-------- src/main/dig/processor/SWAP.dig | 181 +++--- src/main/dig/processor/SWAPN.dig | 213 +++---- .../digital/integration/TestExamples.java | 63 ++ .../digital/integration/ToBreakRunner.java | 16 +- 5 files changed, 599 insertions(+), 440 deletions(-) create mode 100644 src/test/java/de/neemann/digital/integration/TestExamples.java diff --git a/src/main/dig/combinatorial/MultiplyTest.dig b/src/main/dig/combinatorial/MultiplyTest.dig index 1da376eaa..3142701c4 100644 --- a/src/main/dig/combinatorial/MultiplyTest.dig +++ b/src/main/dig/combinatorial/MultiplyTest.dig @@ -1,248 +1,324 @@ - 1 - - - Multiply.dig - - - 0 - - - Seven-Seg-Hex - - - 0 - - - Seven-Seg-Hex - - - 0 - - - Seven-Seg-Hex - - - 0 - - - Seven-Seg-Hex - - - 0 - - - In - - - Label - P - - - Bits - 4 - - - Default - 4 - - - - 0 - - - Splitter - - - Input Splitting - 4 - - - Output Splitting - 1*4 - - - - 0 - - - Splitter - - - Input Splitting - 4 - - - Output Splitting - 1*4 - - - - 0 - - - In - - - Label - Q - - - Bits - 4 - - - Default - 9 - - - - 0 - - - Splitter - - - Input Splitting - 1*4 - - - Output Splitting - 4 - - - - 0 - - - Splitter - - - Input Splitting - 1*4 - - - Output Splitting - 4 - - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 1 + + + Multiply.dig + + + 0 + + + Seven-Seg-Hex + + + 0 + + + Seven-Seg-Hex + + + 0 + + + Seven-Seg-Hex + + + 0 + + + Seven-Seg-Hex + + + 0 + + + In + + + Label + P + + + Bits + 4 + + + Default + 4 + + + + 0 + + + Splitter + + + Input Splitting + 4 + + + Output Splitting + 1*4 + + + + 0 + + + Splitter + + + Input Splitting + 4 + + + Output Splitting + 1*4 + + + + 0 + + + In + + + Label + Q + + + Bits + 4 + + + Default + 9 + + + + 0 + + + Splitter + + + Input Splitting + 1*4 + + + Output Splitting + 4 + + + + 0 + + + Splitter + + + Input Splitting + 1*4 + + + Output Splitting + 4 + + + + 0 + + + Const + + + rotation + + + + Value + 0 + + + + 1 + + + Const + + + rotation + + + + Value + 0 + + + + 1 + + + Const + + + rotation + + + + Value + 0 + + + + 1 + + + Const + + + rotation + + + + Value + 0 + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/dig/processor/SWAP.dig b/src/main/dig/processor/SWAP.dig index f9d05be6f..2d191eb19 100644 --- a/src/main/dig/processor/SWAP.dig +++ b/src/main/dig/processor/SWAP.dig @@ -1,91 +1,96 @@ - - - In - - - Label - Di - - - Default - 16 - - - - 0 - - - Splitter - - - Input Splitting - 16 - - - Output Splitting - 8,8 - - - - 0 - - - Splitter - - - Input Splitting - 8,8 - - - Output Splitting - 16 - - - - 0 - - - Out - - - Label - Do - - - Bits - 16 - - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 1 + + + In + + + Label + Di + + + Bits + 16 + + + Default + 16 + + + + 0 + + + Splitter + + + Input Splitting + 16 + + + Output Splitting + 8,8 + + + + 0 + + + Splitter + + + Input Splitting + 8,8 + + + Output Splitting + 16 + + + + 0 + + + Out + + + Label + Do + + + Bits + 16 + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/dig/processor/SWAPN.dig b/src/main/dig/processor/SWAPN.dig index 9e4498ba9..94c1093d4 100644 --- a/src/main/dig/processor/SWAPN.dig +++ b/src/main/dig/processor/SWAPN.dig @@ -1,107 +1,112 @@ - - - In - - - Label - Di - - - Default - 16 - - - - 0 - - - Splitter - - - Input Splitting - 16 - - - Output Splitting - 4,4,4,4 - - - - 0 - - - Splitter - - - Input Splitting - 4,4,4,4 - - - Output Splitting - 16 - - - - 0 - - - Out - - - Label - Do - - - Bits - 16 - - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 1 + + + In + + + Label + Di + + + Bits + 16 + + + Default + 16 + + + + 0 + + + Splitter + + + Input Splitting + 16 + + + Output Splitting + 4,4,4,4 + + + + 0 + + + Splitter + + + Input Splitting + 4,4,4,4 + + + Output Splitting + 16 + + + + 0 + + + Out + + + Label + Do + + + Bits + 16 + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/de/neemann/digital/integration/TestExamples.java b/src/test/java/de/neemann/digital/integration/TestExamples.java new file mode 100644 index 000000000..0b24563d9 --- /dev/null +++ b/src/test/java/de/neemann/digital/integration/TestExamples.java @@ -0,0 +1,63 @@ +package de.neemann.digital.integration; + +import de.neemann.digital.core.NodeException; +import de.neemann.digital.draw.elements.PinException; +import junit.framework.TestCase; + +import java.io.File; +import java.io.IOException; + +/** + * Reads all examples and tries to create the model. + * Makes sure that all examples are creatable (one can build the model) + * Does not ensure that they work correctly! + * + * @author hneemann + */ +public class TestExamples extends TestCase { + + public void testExamples() throws Exception { + File res = Resources.getRoot(); + File src = res.getParentFile().getParentFile(); + File examples = new File(src, "/main/dig"); + assertEquals(17, scan(new File(examples, "combinatorial"))); + assertEquals(18, scan(new File(examples, "sequential"))); + assertEquals(16, scan(new File(examples, "processor"))); + assertEquals(4, scan(new File(examples, "hazard"))); + } + + private int scan(File path) { + int count = 0; + File[] files = path.listFiles(); + if (files != null) { + for (File f : files) { + if (f.isDirectory()) { + if (f.getName().charAt(0) != '.') { + count += scan(f); + } + } else { + if (f.getName().endsWith(".dig")) { + check(f); + count++; + } + } + } + } + return count; + } + + /** + * Loads the model and initializes it + * + * @param dig the model file + */ + private void check(File dig) { + try { + new ToBreakRunner(dig); + assertTrue(true); + } catch (PinException | NodeException | IOException e) { + assertTrue(dig.getPath() + ": " + e.getMessage(), false); + } + + } +} diff --git a/src/test/java/de/neemann/digital/integration/ToBreakRunner.java b/src/test/java/de/neemann/digital/integration/ToBreakRunner.java index 2aecbb8b8..f7de03dcb 100644 --- a/src/test/java/de/neemann/digital/integration/ToBreakRunner.java +++ b/src/test/java/de/neemann/digital/integration/ToBreakRunner.java @@ -36,7 +36,18 @@ public class ToBreakRunner { * @throws NodeException */ public ToBreakRunner(String file) throws IOException, PinException, NodeException { - File filename = new File(Resources.getRoot(), file); + this(new File(Resources.getRoot(), file)); + } + + /** + * Creates a new instance + * + * @param filename the file to load + * @throws IOException + * @throws PinException + * @throws NodeException + */ + public ToBreakRunner(File filename) throws IOException, PinException, NodeException { ElementLibrary library = new ElementLibrary(); ShapeFactory shapeFactory = new ShapeFactory(library); circuit = Circuit.loadCircuit(filename, shapeFactory); @@ -46,8 +57,6 @@ public class ToBreakRunner { ModelDescription md = new ModelDescription(circuit, library); model = md.createModel(); model.init(true); - - assertTrue(model.isFastRunModel()); } /** @@ -58,6 +67,7 @@ public class ToBreakRunner { * @throws NodeException */ public ToBreakRunner runToBreak(int steps) throws NodeException { + assertTrue(model.isFastRunModel()); assertEquals(steps, model.runToBreak()); return this; }