aboutsummaryrefslogtreecommitdiffstats
path: root/tests/com/jsyn/util/TestVoiceAllocator.java
diff options
context:
space:
mode:
authorRubbaBoy <[email protected]>2020-07-06 02:33:28 -0400
committerPhil Burk <[email protected]>2020-10-30 11:19:34 -0700
commit46888fae6eb7b1dd386f7af7d101ead99ae61981 (patch)
tree8969bbfd68d2fb5c0d8b86da49ec2eca230a72ab /tests/com/jsyn/util/TestVoiceAllocator.java
parentc51e92e813dd481603de078f0778e1f75db2ab05 (diff)
Restructured project, added gradle, JUnit, logger, and more
Added Gradle (and removed ant), modernized testing via the JUnit framework, moved standalone examples from the tests directory to a separate module, removed sparsely used Java logger and replaced it with SLF4J. More work could be done, however this is a great start to greatly improving the health of the codebase.
Diffstat (limited to 'tests/com/jsyn/util/TestVoiceAllocator.java')
-rw-r--r--tests/com/jsyn/util/TestVoiceAllocator.java111
1 files changed, 0 insertions, 111 deletions
diff --git a/tests/com/jsyn/util/TestVoiceAllocator.java b/tests/com/jsyn/util/TestVoiceAllocator.java
deleted file mode 100644
index fd5ba0b..0000000
--- a/tests/com/jsyn/util/TestVoiceAllocator.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2009 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.util;
-
-import junit.framework.TestCase;
-
-import com.jsyn.instruments.SubtractiveSynthVoice;
-import com.jsyn.unitgen.UnitVoice;
-
-public class TestVoiceAllocator extends TestCase {
- VoiceAllocator allocator;
- int max = 4;
- private UnitVoice[] voices;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- voices = new UnitVoice[max];
- for (int i = 0; i < max; i++) {
- voices[i] = new SubtractiveSynthVoice();
- }
-
- allocator = new VoiceAllocator(voices);
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- public void testAllocation() {
- assertEquals("get max", max, allocator.getVoiceCount());
-
- int tag1 = 61;
- int tag2 = 62;
- int tag3 = 63;
- int tag4 = 64;
- int tag5 = 65;
- int tag6 = 66;
- UnitVoice voice1 = allocator.allocate(tag1);
- assertTrue("voice should be non-null", (voice1 != null));
-
- UnitVoice voice2 = allocator.allocate(tag2);
- assertTrue("voice should be non-null", (voice2 != null));
- assertTrue("new voice ", (voice2 != voice1));
-
- UnitVoice voice = allocator.allocate(tag1);
- assertTrue("should be voice1 again ", (voice == voice1));
-
- voice = allocator.allocate(tag2);
- assertTrue("should be voice2 again ", (voice == voice2));
-
- UnitVoice voice3 = allocator.allocate(tag3);
- @SuppressWarnings("unused")
- UnitVoice voice4 = allocator.allocate(tag4);
-
- UnitVoice voice5 = allocator.allocate(tag5);
- assertTrue("ran out so get voice1 as oldest", (voice5 == voice1));
-
- voice = allocator.allocate(tag2);
- assertTrue("should be voice2 again ", (voice == voice2));
-
- // Now voice 3 should be the oldest cuz voice 2 was touched.
- UnitVoice voice6 = allocator.allocate(tag6);
- assertTrue("ran out so get voice3 as oldest", (voice6 == voice3));
- }
-
- public void testOff() {
- int tag1 = 61;
- int tag2 = 62;
- int tag3 = 63;
- int tag4 = 64;
- int tag5 = 65;
- int tag6 = 66;
- UnitVoice voice1 = allocator.allocate(tag1);
- UnitVoice voice2 = allocator.allocate(tag2);
- UnitVoice voice3 = allocator.allocate(tag3);
- UnitVoice voice4 = allocator.allocate(tag4);
-
- assertTrue("voice 3 should start on", allocator.isOn(tag3));
- allocator.off(tag3);
- assertEquals("voice 3 should now be off", false, allocator.isOn(tag3));
-
- allocator.off(tag2);
-
- UnitVoice voice5 = allocator.allocate(tag5);
- assertTrue("should get voice3 cuz off first", (voice5 == voice3));
- UnitVoice voice6 = allocator.allocate(tag6);
- assertTrue("should get voice2 cuz off second", (voice6 == voice2));
- voice3 = allocator.allocate(tag3);
- assertTrue("should get voice1 cuz on first", (voice3 == voice1));
-
- voice1 = allocator.allocate(tag1);
- assertTrue("should get voice4 cuz next up", (voice1 == voice4));
- }
-}