Skip to content

Commit 6062eb9

Browse files
committed
Consolidate unit tests
1 parent b10655f commit 6062eb9

1 file changed

Lines changed: 24 additions & 111 deletions

File tree

Tests/SpeechTests.cs

Lines changed: 24 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
using Microsoft.VisualStudio.TestTools.UnitTesting;
44
using NAudio.Wave;
55
using System.IO;
6+
using System.Linq;
67
using System.Speech.Synthesis;
78
using System.Threading;
8-
using Utilities;
99

1010
namespace Tests
1111
{
@@ -19,43 +19,17 @@ public void start ()
1919
}
2020

2121
[DataTestMethod, DoNotParallelize]
22-
[DataRow( "This is your <phoneme alphabet=\"ipa\" ph=\"leɪkɒn\">Lakon</phoneme>.", true )]
23-
[DataRow( "You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ˈdɛltə\">delta</phoneme> system.", true )]
24-
[DataRow( "You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ˈlaʊ.təns\">Luyten's</phoneme> <phoneme alphabet=\"ipa\" ph=\"stɑː\">Star</phoneme> system.", true )]
25-
[DataRow( "You are travelling to the <phoneme alphabet=\"ipa\" ph=\"bliːiː\">Bleae</phoneme> <phoneme alphabet=\"ipa\" ph=\"θuːə\">Thua</phoneme> system.", true )]
26-
[DataRow( "You are travelling to the Amnemoi system.", false )]
27-
public void TestStarSystemPhonemes (string inputSpeech, bool useSSML)
22+
[DataRow( "This is your <phoneme alphabet=\"ipa\" ph=\"leɪkɒn\">Lakon</phoneme>." )]
23+
[DataRow( "You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ˈdɛltə\">delta</phoneme> system." )]
24+
[DataRow( "You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ˈlaʊ.təns\">Luyten's</phoneme> <phoneme alphabet=\"ipa\" ph=\"stɑː\">Star</phoneme> system." )]
25+
[DataRow( "You are travelling to the <phoneme alphabet=\"ipa\" ph=\"bliːiː\">Bleae</phoneme> <phoneme alphabet=\"ipa\" ph=\"θuːə\">Thua</phoneme> system." )]
26+
[DataRow( "You are travelling to the Amnemoi system." )]
27+
[DataRow( "You are docked at Jameson Memorial in the <phoneme alphabet=\"ipa\" ph=\"ʃɪnˈrɑːrtə\">Shinrarta</phoneme> <phoneme alphabet=\"ipa\" ph=\"ˈdezɦrə\">Dezhra</phoneme> system." )]
28+
[DataRow( @"Destination confirmed. your <phoneme alphabet=""ipa"" ph=""ˈkəʊbrə"">cobra</phoneme> <phoneme alphabet=""ipa"" ph=""mɑːk"">Mk.</phoneme> <phoneme alphabet=""ipa"" ph=""θriː"">III</phoneme> is travelling to the L T T 1 7 8 6 8 system. This is your first visit to this system. L T T 1 7 8 6 8 is a Federation Corporate with a population of Over 65 thousand souls, aligned to <phoneme alphabet=""ipa"" ph=""fəˈlɪʃɪə"">Felicia</phoneme> <phoneme alphabet=""ipa"" ph=""ˈwɪntəs"">Winters</phoneme>. Kungurutii Gold Power Org is the immediate faction. There are 2 orbital stations and a single planetary station in this system." )]
29+
[DataRow( @"<phoneme alphabet=""ipa"" ph=""iˈlɛktrə"">Electra</phoneme>" )]
30+
public void TestPhonetics (string inputSpeech)
2831
{
29-
EventWaitHandle waitHandle = new AutoResetEvent(false);
30-
31-
using ( var stream = new MemoryStream() )
32-
using ( var synth = new SpeechSynthesizer() )
33-
{
34-
synth.SetOutputToWaveStream( stream );
35-
36-
if ( useSSML )
37-
{
38-
synth.SpeakSsml($"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"https://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\">{inputSpeech}</speak>" );
39-
}
40-
else
41-
{
42-
synth.Speak( inputSpeech );
43-
}
44-
45-
stream.Seek( 0, SeekOrigin.Begin );
46-
47-
var source = new WaveFileReader(stream);
48-
49-
var soundOut = new WasapiOut();
50-
soundOut.PlaybackStopped += ( s, e ) => waitHandle.Set();
51-
52-
soundOut.Init( source );
53-
soundOut.Play();
54-
55-
waitHandle.WaitOne();
56-
soundOut.Dispose();
57-
source.Dispose();
58-
}
32+
SpeechService.Speak(new EddiSpeech(inputSpeech));
5933
}
6034

6135
[TestMethod, DoNotParallelize]
@@ -78,7 +52,6 @@ public void TestSsml (string edModel, string ssml)
7852
[TestMethod, DoNotParallelize]
7953
public void TestSsml2 ()
8054
{
81-
Logging.Verbose = true;
8255
SpeechService.Instance.Say( ShipDefinitions.FromEDModel( "Vulture" ), @"<break time=""100ms""/>We're on our way to " + Translations.GetTranslation( "i Bootis" ) + "." );
8356
}
8457

@@ -178,21 +151,22 @@ public void TestChorus ( int chorusLevel )
178151
SpeechService.Instance.Speak( $"Chorus level {chorusLevel}", null, 0, 0, chorusLevel, 0, false, 0 );
179152
}
180153

181-
[TestMethod, DoNotParallelize]
182-
public void TestRadio ()
154+
[DataTestMethod, DoNotParallelize]
155+
[DataRow( "Your python has touched down." )]
156+
[DataRow( "Anaconda golf foxtrot lima one niner six eight returning from orbit." )]
157+
public void TestRadio (string msg)
183158
{
184-
SpeechService.Instance.Say( ShipDefinitions.FromEDModel( "Python" ), "Anaconda golf foxtrot lima one niner six eight returning from orbit.", 3, null, true );
159+
SpeechService.Speak(new EddiSpeech(msg, radio: true));
185160
}
186161

187162
[DataTestMethod, DoNotParallelize]
188-
[DataRow( 0 )]
189-
[DataRow( 100 )]
190-
[DataRow( 200 )]
191-
[DataRow( 400 )]
192-
[DataRow( 800 )]
193-
public void TestEchoDelay (int echoDelayMs)
163+
[DataRow( 1 )]
164+
[DataRow( 2 )]
165+
[DataRow( 3 )]
166+
public void TestEchoDelay (int landingPadSize)
194167
{
195-
SpeechService.Instance.Speak( $"Echo delay {echoDelayMs}", null, echoDelayMs, 0, 0, 0, false, 0 );
168+
var shipSize = LandingPadSize.AllOfThem.First( s => s.sizeIndex == landingPadSize );
169+
SpeechService.Speak( new EddiSpeech( $"Echo delay for a {shipSize} ship.", shipSize: shipSize ) );
196170
}
197171

198172
[TestMethod, DoNotParallelize]
@@ -217,72 +191,11 @@ public void TestDropOff ()
217191
SpeechService.Instance.Speak( "Testing drop-off.", null, 50, 1, 30, 40, true, 0 );
218192
}
219193

220-
[TestMethod, DoNotParallelize]
221-
public void TestSpeechServicePhonemes ()
222-
{
223-
Logging.Verbose = true;
224-
SpeechService.Instance.Speak( "You are docked at Jameson Memorial in the <phoneme alphabet=\"ipa\" ph=\"ʃɪnˈrɑːrtə\">Shinrarta</phoneme> <phoneme alphabet=\"ipa\" ph=\"ˈdezɦrə\">Dezhra</phoneme> system.", null, 50, 1, 30, 40, true, 0 );
225-
}
226-
227-
[TestMethod, DoNotParallelize]
228-
public void TestSpeechServiceQueue ()
229-
{
230-
var thread1 = new Thread(() => SpeechService.Instance.Say(null, "Hello."))
231-
{
232-
IsBackground = true
233-
};
234-
235-
var thread2 = new Thread(() => SpeechService.Instance.Say(null, "Goodbye."))
236-
{
237-
IsBackground = true
238-
};
239-
240-
thread1.Start();
241-
thread2.Start();
242-
243-
thread1.Join();
244-
thread2.Join();
245-
}
246-
247-
[TestMethod, DoNotParallelize]
248-
public void TestSpeechServicePhonetics1 ()
249-
{
250-
SpeechService.Instance.Say( null, @"Destination confirmed. your <phoneme alphabet=""ipa"" ph=""ˈkəʊbrə"">cobra</phoneme> <phoneme alphabet=""ipa"" ph=""mɑːk"">Mk.</phoneme> <phoneme alphabet=""ipa"" ph=""θriː"">III</phoneme> is travelling to the L T T 1 7 8 6 8 system. This is your first visit to this system. L T T 1 7 8 6 8 is a Federation Corporate with a population of Over 65 thousand souls, aligned to <phoneme alphabet=""ipa"" ph=""fəˈlɪʃɪə"">Felicia</phoneme> <phoneme alphabet=""ipa"" ph=""ˈwɪntəs"">Winters</phoneme>. Kungurutii Gold Power Org is the immediate faction. There are 2 orbital stations and a single planetary station in this system." );
251-
}
252-
253-
[TestMethod, DoNotParallelize]
254-
public void TestSpeechServiceStress ()
255-
{
256-
Logging.Verbose = true;
257-
for ( var i = 0; i < 3; i++ )
258-
{
259-
SpeechService.Instance.Say( null, "A two-second test." );
260-
}
261-
262-
Thread.Sleep( 5000 );
263-
}
264-
265-
[TestMethod, DoNotParallelize]
266-
public void TestSpeechServiceRadio ()
267-
{
268-
Logging.Verbose = true;
269-
SpeechService.Instance.Say( null, "Your python has touched down.", 3, null, true );
270-
}
271-
272194
[TestMethod, DoNotParallelize]
273195
public void TestSpeechNullInvalidVoice ()
274196
{
275-
// Test null voice
276-
SpeechService.Instance.Say( null, "Testing null voice", 3, null, false );
277-
// Test invalid voice
278-
SpeechService.Instance.Say( null, "Testing invalid voice", 3, "No such voice", false );
279-
}
280-
281-
[TestMethod, DoNotParallelize]
282-
public void TestSpeechPhonemes ()
283-
{
284-
var line = @"<phoneme alphabet=""ipa"" ph=""iˈlɛktrə"">Electra</phoneme>";
285-
SpeechService.Instance.Speak( line, null, 0, 40, 0, 0, false, 0 );
197+
SpeechService.Speak( new EddiSpeech( "Testing null voice", null ) );
198+
SpeechService.Speak( new EddiSpeech( "Testing non-valid voice", "No such voice" ) );
286199
}
287200
}
288201
}

0 commit comments

Comments
 (0)