diff options
author | Phil Burk <[email protected]> | 2021-10-30 10:55:40 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2021-10-30 10:55:40 -0700 |
commit | e87459a16189a1935d6035a6a2ace0e615903352 (patch) | |
tree | af95ad56e6bfa7493b0b8c9d8245408032bcc4cc /src | |
parent | ff6a638feaaf2df38929e77c6a81975ba560282b (diff) |
Add getUnits() method to Circuit. (#104)
Add new TestCircuit unit test.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/jsyn/unitgen/Circuit.java | 9 | ||||
-rw-r--r-- | src/test/java/com/jsyn/unitgen/TestCircuit.java | 44 |
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"); + } +} |