import com.sun.speech.freetts.*; public class TestOutputVocal extends Thread { OutputVocal o1; OutputVocal o2; public TestOutputVocal() { System.out.println("Testing OutputVocal Class:"); // Intilase Class o1 = new OutputVocal(); o2 = new OutputVocal(); o1.serviceCommentator("What a great goal", true); o2.serviceCommentator("Offside for always cheating Liverpool", 2); // Run Tests and final call if (testSettors1() && testSetters2() && testVoiceParams()) { System.out.println("OutputVocal Class Passed :)"); System.out.println("-------------------------------"); } else { System.out.println("OutputVocal Class Failed"); System.out.println("-------------------------------"); } } public static void main(String[] args) { new TestPmode(); } public boolean testSettors1() { if (o1.getNextComment().equals("What a great goal") && o1.isStats()) { System.out.println("Setters Test Passed"); return true; } else { System.out.println("! Set and Get Test Failed"); return false; } } public boolean testSetters2() { if (o2.getNextComment().equals("Offside for always cheating Liverpool") && !o2.isStats() && o2.getNextCommentParam() == 2) { System.out.println("Set and Get Test Passed"); return true; } else { System.out.println("! Set and Get Test Failed"); return false; } } public boolean testVoiceParams(){ o1.disableDeallocationVoice(); //for testing purposes if(testVoiceParameters()){ System.out.println("Voice Parameters Assignment Testing Passed"); return true; }else{ System.out.println("! Voice Parameters Assignment Testing Failed"); return false; } } private boolean testVoiceParameters(){ boolean pass = true; Output o = new Output(2); OutputVocal oV = o.getVo(); o.out("Test1", OutputVocal.EXCITED_VOICE); pass &= testVoiceParamSet(OutputVocal.EXCITED_VOICE,oV); o.out("Test2", OutputVocal.BEFORE_MATCH_VOICE); pass &= testVoiceParamSet(OutputVocal.BEFORE_MATCH_VOICE,oV); o.out("Test3", OutputVocal.GOAL_VOICE); pass &= testVoiceParamSet(OutputVocal.GOAL_VOICE,oV); o.out("Test4", OutputVocal.SLIGHTLY_EXCITED_VOICE); pass &= testVoiceParamSet(OutputVocal.SLIGHTLY_EXCITED_VOICE,oV); return true; } private boolean testVoiceParamSet(int paramExpected, OutputVocal o1) { boolean pass = true; Voice v = o1.getMainVoice(); float pitch = v.getPitch(); float rate = v.getRate(); float vol = v.getVolume(); float pitchExpected = 0, rateExpected = 0, volExpected = 1.0f; switch (paramExpected) { case OutputVocal.EXCITED_VOICE: pitchExpected = 115; rateExpected = 165; break; case OutputVocal.SLIGHTLY_EXCITED_VOICE: pitchExpected = 110; rateExpected = 155; break; case OutputVocal.BEFORE_MATCH_VOICE: pitchExpected = 105; rateExpected = 150; break; case OutputVocal.GOAL_VOICE: pitchExpected = 120; rateExpected = 175; volExpected = 1.3f; break; } pass &= (pitchExpected == pitch); pass &= (rateExpected == rate); pass &= (volExpected == vol); return pass; } }