From aed6bc03650b3daf88fbc6804f14968f13c1a0e0 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Mon, 17 Dec 2012 16:45:50 +0000 Subject: [PATCH] SpeechSynthesisTest: calculate the added and removed voices in the getVoices method. --- .../espeak/test/SpeechSynthesisTest.java | 76 +++++++++---------- 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/android/eSpeakTests/src/com/reecedunn/espeak/test/SpeechSynthesisTest.java b/android/eSpeakTests/src/com/reecedunn/espeak/test/SpeechSynthesisTest.java index 5cc9cbda..7965e719 100644 --- a/android/eSpeakTests/src/com/reecedunn/espeak/test/SpeechSynthesisTest.java +++ b/android/eSpeakTests/src/com/reecedunn/espeak/test/SpeechSynthesisTest.java @@ -103,6 +103,8 @@ public class SpeechSynthesisTest extends AndroidTestCase }; private List mVoices = null; + private Set mAdded = new HashSet(); + private Set mRemoved = new HashSet(); public List getVoices() { @@ -111,6 +113,34 @@ public class SpeechSynthesisTest extends AndroidTestCase final SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback); mVoices = synth.getAvailableVoices(); assertThat(mVoices, is(notNullValue())); + + Set voices = new HashSet(); + for (Voice data : mVoices) + { + voices.add(data.name); + } + + Set expected = new HashSet(); + for (VoiceData.Voice data : VoiceData.voices) + { + expected.add(data.name); + } + + for (String voice : voices) + { + if (!expected.contains(voice)) + { + mAdded.add(voice); + } + } + + for (String voice : expected) + { + if (!voices.contains(voice)) + { + mRemoved.add(voice); + } + } } return mVoices; } @@ -138,52 +168,14 @@ public class SpeechSynthesisTest extends AndroidTestCase public void testAddedVoices() { - Set voices = new HashSet(); - for (Voice data : getVoices()) - { - voices.add(data.name); - } - - Set expected = new HashSet(); - for (VoiceData.Voice data : VoiceData.voices) - { - expected.add(data.name); - } - - Set added = new HashSet(); - for (String voice : voices) - { - if (!expected.contains(voice)) - { - added.add(voice); - } - } - assertThat(added.toString(), is("[]")); + getVoices(); // Ensure that the voice data has been populated. + assertThat(mAdded.toString(), is("[]")); } public void testRemovedVoices() { - Set voices = new HashSet(); - for (Voice data : getVoices()) - { - voices.add(data.name); - } - - Set expected = new HashSet(); - for (VoiceData.Voice data : VoiceData.voices) - { - expected.add(data.name); - } - - Set removed = new HashSet(); - for (String voice : expected) - { - if (!voices.contains(voice)) - { - removed.add(voice); - } - } - assertThat(removed.toString(), is("[]")); + getVoices(); // Ensure that the voice data has been populated. + assertThat(mRemoved.toString(), is("[]")); } public void testVoiceData()