Skip to content

Commit

Permalink
Add basic tests for MidiHandler, AnalysisPlugin and AudioAnalyser
Browse files Browse the repository at this point in the history
  • Loading branch information
lacimarsik committed Aug 11, 2016
1 parent 6357b0c commit 1811d13
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ public MidiDevice getMidiDevice(String name) {
return MidiSystem.getMidiDevice(info);
}
} catch (MidiUnavailableException e) {

e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.harmony_analyser.application.services;

import org.harmony_analyser.plugins.AnalysisPlugin;
import org.junit.*;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
* Unit tests for AudioAnalyser class
*/

public class AudioAnalyserTest {
private AudioAnalyser audioAnalyser;
private File testWavFile, testReportFixture;
private List<String> inputFiles;
private String resultFile;

// XXX: Until Mockito is added as dependency and mocks are in practice, expect the fail scenario rather than proper call

@Before
public void setUp() {
audioAnalyser = new AudioAnalyser();
inputFiles = new ArrayList<>();
inputFiles.add("test.wav-chromas.txt");
inputFiles.add("wrongfile");
resultFile = "result.txt";
}

@Test(expected = AnalysisPlugin.IncorrectInputException.class)
public void shouldRunAnalysis() throws AudioAnalyser.LoadFailedException, AnalysisPlugin.IncorrectInputException, IOException {
audioAnalyser.runAnalysis(inputFiles, resultFile, "harmanal:transition_complexity");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.harmony_analyser.application.services;

import org.junit.Before;
import org.junit.Test;

/**
* Unit tests for MidiHandler class
*/

public class MidiHandlerTest {
private MidiHandler midiHandler;

@Before
public void setUp() {
midiHandler = new MidiHandler();
}

@Test
public void shouldGetInputDeviceList() {
midiHandler.getInputDeviceList();
}
}
27 changes: 27 additions & 0 deletions src/test/java/org/harmony_analyser/plugins/AnalysisPluginTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.harmony_analyser.plugins;

import org.harmony_analyser.plugins.vamp_plugins.*;

import org.junit.*;
import java.util.*;

/**
* Unit tests for AnalysisPlugin class
*/

public class AnalysisPluginTest {
private ChordinoPlugin chordino;
private List<String> inputFiles;

@Before
public void setUp() throws Exception {
chordino = new ChordinoPlugin();
inputFiles = new ArrayList<>();
inputFiles.add("test.mp3");
}

@Test(expected = AnalysisPlugin.IncorrectInputException.class)
public void shouldCheckInputFiles() throws AnalysisPlugin.IncorrectInputException {
chordino.checkInputFiles(inputFiles);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@

@SuppressWarnings("ConstantConditions")

public class HarmanalPluginTest {
public class TransitionComplexityPluginTest {
private File testWavFile, testReportFixture;
private List<String> inputFilesVamp, inputFilesHarmanal;
private List<String> inputFilesVamp, inputFilesComplexity;

@Before
public void setUp() {
ClassLoader classLoader = getClass().getClassLoader();
testWavFile = new File(classLoader.getResource("test.wav").getFile());
inputFilesVamp = new ArrayList<>();
inputFilesVamp.add(testWavFile.toString());
inputFilesHarmanal = new ArrayList<>();
inputFilesHarmanal.add(testWavFile.toString() + "-chromas.txt");
inputFilesHarmanal.add(testWavFile.toString() + "-segmentation.txt");
inputFilesComplexity = new ArrayList<>();
inputFilesComplexity.add(testWavFile.toString() + "-chromas.txt");
inputFilesComplexity.add(testWavFile.toString() + "-segmentation.txt");
testReportFixture = new File(classLoader.getResource("test-reportFixture.txt").getFile());
}

@Test
public void shouldCreateReportAndResult() {
public void shouldCreateReport() {
try {
new NNLSPlugin().analyse(inputFilesVamp, testWavFile.toString() + "-chromas.txt");
new ChordinoPlugin().analyse(inputFilesVamp, testWavFile.toString() + "-segmentation.txt");
new TransitionComplexityPlugin().analyse(inputFilesHarmanal, testWavFile.toString() + "-report.txt");
new TransitionComplexityPlugin().analyse(inputFilesComplexity, testWavFile.toString() + "-report.txt");
BufferedReader readerReport = new BufferedReader(new FileReader(testWavFile.toString() + "-report.txt"));
BufferedReader readerFixture = new BufferedReader(new FileReader(testReportFixture));
StringBuilder reportString = new StringBuilder();
Expand Down

0 comments on commit 1811d13

Please sign in to comment.