aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/jsyn/unitgen/Circuit.java9
-rw-r--r--src/test/java/com/jsyn/unitgen/TestCircuit.java44
2 files changed, 53 insertions, 0 deletions
diff --git a/src/main/java/com/jsyn/unitgen/Circuit.java b/src/main/java/com/jsyn/unitgen/Circuit.java
index 01cb860..db516a7 100644
--- a/src/main/java/com/jsyn/unitgen/Circuit.java
+++ b/src/main/java/com/jsyn/unitgen/Circuit.java
@@ -119,4 +119,13 @@ public class Circuit extends UnitGenerator {
return port;
}
+ /**
+ * The units are guaranteed to be in the same order
+ * as they were added.
+ *
+ * @return an array of units that have been added to this circuit.
+ */
+ UnitGenerator[] getUnits() {
+ return units.toArray(new UnitGenerator[0]);
+ }
}
diff --git a/src/test/java/com/jsyn/unitgen/TestCircuit.java b/src/test/java/com/jsyn/unitgen/TestCircuit.java
new file mode 100644
index 0000000..c620abf
--- /dev/null
+++ b/src/test/java/com/jsyn/unitgen/TestCircuit.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2021 Phil Burk, Mobileer Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.jsyn.unitgen;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * Test Circuit class
+ */
+public class TestCircuit {
+
+ @Test
+ public void testAddGetUnits() {
+ Circuit circuit = new Circuit();
+ SineOscillator sine = new SineOscillator();
+ circuit.add(sine);
+ UnitGenerator units[] = circuit.getUnits();
+ assertTrue(circuit != null, "null units array");
+ assertEquals(sine, units[0], "sine");
+
+ SawtoothOscillator saw = new SawtoothOscillator();
+ circuit.add(saw);
+ units = circuit.getUnits();
+ assertTrue(circuit != null, "null units array");
+ assertEquals(sine, units[0], "sine");
+ assertEquals(saw, units[1], "saw");
+ }
+}