예제 #1
0
        public void TestPathingString3()
        {
            string        pathingString  = @"There [are;might be;could be] [4;5;] lights;It's dark in here;";
            List <string> pathingOptions = new List <string>()
            {
                "There are 4 lights"
                , "There are 5 lights"
                , "There are  lights"
                , "There might be 4 lights"
                , "There might be 5 lights"
                , "There might be  lights"
                , "There could be 4 lights"
                , "There could be 5 lights"
                , "There could be  lights"
                , "It's dark in here"
                , ""
            };

            HashSet <string> pathingResults = new HashSet <string>();

            for (int i = 0; i < 1000; i++)
            {
                string pathedString = VoiceAttackPlugin.SpeechFromScript(pathingString);
                pathingResults.Add(pathedString);
            }

            Assert.IsTrue(pathingResults.SetEquals(new HashSet <string>(pathingOptions)));
        }
예제 #2
0
        private static IDictionary <string, string> GetMapping(string layout)
        {
            try
            {
                string mappingFile = Path.Combine(Paths.MappingsDirectory.FullName, $"{layout}.yml");

                if (!File.Exists(mappingFile))
                {
                    if (layout != "en-GB")
                    {
                        VoiceAttackPlugin.Log($"Could not find {layout}.yml, defaulting to en-GB.yml for mapping", VoiceAttackColor.Gray);
                        return(GetMapping("en-GB"));
                    }

                    VoiceAttackPlugin.Log("Could not set keybindings, no mappings files were found", VoiceAttackColor.Red);
                    return(new Dictionary <string, string>());
                }

                VoiceAttackPlugin.Log($"Using mappings in '{mappingFile}'", VoiceAttackColor.Gray);

                var entries = File.ReadAllLines(mappingFile)
                              .Where(x => !string.IsNullOrWhiteSpace(x) && x.Contains(":"));
                return(entries.ToDictionary(entry => entry.Split(':')[0].Trim(), entry => entry.Split(':')[1].Trim()));
            }
            catch (Exception ex)
            {
                VoiceAttackPlugin.Log(ex, $"Could not get mappings from {layout}.yml");
                throw;
            }
        }
예제 #3
0
        public void TestPathingString7()
        {
            string        pathingString  = @"[{TXT:Ship model} {TXT:Ship callsign (spoken)};This is {TXT:Ship model} {TXT:Ship callsign (spoken)}] [requesting docking permission;requesting docking clearance;requesting permission to dock;requesting clearance to dock].";
            List <string> pathingOptions = new List <string>()
            {
                "{TXT:Ship model} {TXT:Ship callsign (spoken)} requesting docking permission."
                , "This is {TXT:Ship model} {TXT:Ship callsign (spoken)} requesting docking permission."
                , "{TXT:Ship model} {TXT:Ship callsign (spoken)} requesting docking clearance."
                , "This is {TXT:Ship model} {TXT:Ship callsign (spoken)} requesting docking clearance."
                , "{TXT:Ship model} {TXT:Ship callsign (spoken)} requesting clearance to dock."
                , "This is {TXT:Ship model} {TXT:Ship callsign (spoken)} requesting clearance to dock."
                , "{TXT:Ship model} {TXT:Ship callsign (spoken)} requesting permission to dock."
                , "This is {TXT:Ship model} {TXT:Ship callsign (spoken)} requesting permission to dock."
            };

            HashSet <string> pathingResults = new HashSet <string>();

            for (int i = 0; i < 1000; i++)
            {
                string pathedString = VoiceAttackPlugin.SpeechFromScript(pathingString);
                pathingResults.Add(pathedString);
            }

            Assert.IsTrue(pathingResults.SetEquals(new HashSet <string>(pathingOptions)));
        }
예제 #4
0
        private static IEnumerable <Variable> GetVariables(XElement xml, IDictionary <string, string> mapping)
        {
            IList <Variable> variables = new List <Variable>();

            foreach (var bindingNode in xml.Elements().Where(i => i.Elements().Any()))
            {
                try
                {
                    var name = bindingNode.Name.LocalName;

                    var primary   = bindingNode.Element("Primary");
                    var secondary = bindingNode.Element("Secondary");

                    if (primary == null)
                    {
                        //VoiceAttackPlugin.Log($"Skipping {name}, no bindings set");
                        continue;
                    }

                    XElement active = null;

                    if (IsApplicableBinding(primary))
                    {
                        active = primary;
                    }
                    else if (IsApplicableBinding(secondary))
                    {
                        active = secondary;
                    }
                    else
                    {
                        //VoiceAttackPlugin.Log($"Skipping {name}, not applicable");
                        continue;
                    }

                    if (active == null)
                    {
                        continue;
                    }

                    var modifiers = active.Elements("Modifier").ToList();

                    if (modifiers.Any(x => !IsApplicableBinding(x)))
                    {
                        //VoiceAttackPlugin.Log($"Skipping {name}, modifier not applicable");
                    }

                    string value = GetKeyBinding(active.Attribute("Key").Value, modifiers.Select(x => x.Attribute("Key").Value), mapping);

                    variables.Add(new Variable(name, value));
                }
                catch (Exception ex)
                {
                    VoiceAttackPlugin.Log(ex, $"Could not process {bindingNode.Name} keybinding");
                }
            }

            return(variables);
        }
예제 #5
0
        public void VoiceAttackPluginTests_ShutdownFSUIPCInterfaceOnExit()
        {
            var       mockInterface = new Mock <IFSUIPCInterface>();
            MyVAProxy proxy         = new MyVAProxy();

            proxy.SessionState.Add(VoiceAttackPlugin.SESSIONSTATE.KEY_FSUIPCINTERFACE,
                                   mockInterface.Object);

            // Call Exit1
            VoiceAttackPlugin.VA_Exit1(proxy);

            mockInterface.Verify(x => x.shutdown(), Times.AtMost(1));
        }
예제 #6
0
 private static string GetLayout(XElement xml)
 {
     try
     {
         var layoutElement = xml.Element("KeyboardLayout");
         return(layoutElement != null ? layoutElement.Value : "en-US");
     }
     catch (Exception ex)
     {
         VoiceAttackPlugin.Log(ex, "Could not get layout from keybindings");
         throw;
     }
 }
예제 #7
0
        public void TestOutfittingCosts()
        {
            Dictionary <string, object>    state          = new Dictionary <string, object>();
            Dictionary <string, short?>    shortIntValues = new Dictionary <string, short?>();
            Dictionary <string, string>    textValues     = new Dictionary <string, string>();
            Dictionary <string, int?>      intValues      = new Dictionary <string, int?>();
            Dictionary <string, decimal?>  decimalValues  = new Dictionary <string, decimal?>();
            Dictionary <string, bool?>     booleanValues  = new Dictionary <string, bool?>();
            Dictionary <string, DateTime?> dateTimeValues = new Dictionary <string, DateTime?>();
            Dictionary <string, object>    extendedValues = new Dictionary <string, object>();

            VoiceAttackPlugin.VA_Init1(ref state, ref shortIntValues, ref textValues, ref intValues, ref decimalValues, ref booleanValues, ref dateTimeValues, ref extendedValues);
        }
예제 #8
0
        public void VoiceAttackPluginTests_InvokesMethodAndArgsOnFSUIPCInterface_2()
        {
            var       mockInterface = new Mock <IFSUIPCInterface>();
            MyVAProxy proxy         = new MyVAProxy();

            proxy.SessionState.Add(VoiceAttackPlugin.SESSIONSTATE.KEY_FSUIPCINTERFACE,
                                   mockInterface.Object);
            proxy.Context = "beginMonitoringEvents:";

            // Call Invoke1
            VoiceAttackPlugin.VA_Invoke1(proxy);

            mockInterface.Verify(x => x.beginMonitoringEvents(), Times.AtMost(1));
        }
예제 #9
0
        public void VoiceAttackPluginTests_InvokesMethodAndArgsOnFSUIPCInterface_1()
        {
            var       mockInterface = new Mock <IFSUIPCInterface>();
            MyVAProxy proxy         = new MyVAProxy();

            proxy.SessionState.Add(VoiceAttackPlugin.SESSIONSTATE.KEY_FSUIPCINTERFACE,
                                   mockInterface.Object);
            proxy.Context = "readOffset:ABC;2;myVar";

            // Call Invoke1
            VoiceAttackPlugin.VA_Invoke1(proxy);

            mockInterface.Verify(x => x.readOffset(0xABC, typeof(short), "myVar"), Times.AtMost(1));
        }
예제 #10
0
        private static string GetKey(string key, IDictionary <string, string> mapping)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                return(key);
            }

            key = key.Replace("Key_", "");

            if (!mapping.ContainsKey(key))
            {
                VoiceAttackPlugin.Log($"The '{key}' key is not assigned in the mappings file", VoiceAttackColor.Yellow);
                return("");
            }

            return($"[{mapping[key]}]");
        }
예제 #11
0
        public void TestPathingString5()
        {
            string        pathingString  = @"You leave me [no choice].";
            List <string> pathingOptions = new List <string>()
            {
                "You leave me no choice."
            };

            HashSet <string> pathingResults = new HashSet <string>();

            for (int i = 0; i < 1000; i++)
            {
                string pathedString = VoiceAttackPlugin.SpeechFromScript(pathingString);
                pathingResults.Add(pathedString);
            }

            Assert.IsTrue(pathingResults.SetEquals(new HashSet <string>(pathingOptions)));
        }
예제 #12
0
        public static IList <Variable> SetBindings(string rawXml)
        {
            try
            {
                XElement xml = XElement.Parse(rawXml);

                var layout  = GetLayout(xml);
                var mapping = GetMapping(layout);
                var keys    = GetVariables(xml, mapping).ToList();

                return(keys);
            }
            catch (Exception ex)
            {
                VoiceAttackPlugin.Log(ex, "Could not set keybindings");
                return(new List <Variable>());
            }
        }
예제 #13
0
        public void TestPathingString6()
        {
            string        pathingString  = @"[There can be only one.]";
            List <string> pathingOptions = new List <string>()
            {
                "There can be only one."
            };

            HashSet <string> pathingResults = new HashSet <string>();

            for (int i = 0; i < 1000; i++)
            {
                string pathedString = VoiceAttackPlugin.SpeechFromScript(pathingString);
                pathingResults.Add(pathedString);
            }

            Assert.IsTrue(pathingResults.SetEquals(new HashSet <string>(pathingOptions)));
        }
예제 #14
0
        public void TestPathingString1()
        {
            string        pathingString  = @"There are [4;5] lights";
            List <string> pathingOptions = new List <string>()
            {
                "There are 4 lights"
                , "There are 5 lights"
            };

            HashSet <string> pathingResults = new HashSet <string>();

            for (int i = 0; i < 1000; i++)
            {
                string pathedString = VoiceAttackPlugin.SpeechFromScript(pathingString);
                pathingResults.Add(pathedString);
            }

            Assert.IsTrue(pathingResults.SetEquals(new HashSet <string>(pathingOptions)));
        }
예제 #15
0
        public void TestPathingString2()
        {
            string        pathingString  = @"There are [4;5;] lights";
            List <string> pathingOptions = new List <string>()
            {
                "There are 4 lights"
                , "There are 5 lights"
                , "There are  lights"
            };

            HashSet <string> pathingResults = new HashSet <string>();

            for (int i = 0; i < 1000; i++)
            {
                string pathedString = VoiceAttackPlugin.SpeechFromScript(pathingString);
                pathingResults.Add(pathedString);
            }

            HashSet <string> expectedHashSet = new HashSet <string>(pathingOptions.Select(CondenseSpaces));

            Assert.IsTrue(pathingResults.SetEquals(expectedHashSet));
        }
예제 #16
0
        public void TestVAVisitStarSystems()
        {
            Dictionary <string, object>    state          = new Dictionary <string, object>();
            Dictionary <string, short?>    shortIntValues = new Dictionary <string, short?>();
            Dictionary <string, string>    textValues     = new Dictionary <string, string>();
            Dictionary <string, int?>      intValues      = new Dictionary <string, int?>();
            Dictionary <string, decimal?>  decimalValues  = new Dictionary <string, decimal?>();
            Dictionary <string, bool?>     booleanValues  = new Dictionary <string, bool?>();
            Dictionary <string, DateTime?> dateTimeValues = new Dictionary <string, DateTime?>();
            Dictionary <string, object>    extendedValues = new Dictionary <string, object>();

            VoiceAttackPlugin.VA_Init1(ref state, ref shortIntValues, ref textValues, ref intValues, ref decimalValues, ref booleanValues, ref dateTimeValues, ref extendedValues);

            VoiceAttackPlugin.updateSystem("LFT 926");
            VoiceAttackPlugin.VA_Invoke1("system", ref state, ref shortIntValues, ref textValues, ref intValues, ref decimalValues, ref booleanValues, ref dateTimeValues, ref extendedValues);

            VoiceAttackPlugin.updateSystem("Shinrarta Dezhra");
            VoiceAttackPlugin.VA_Invoke1("system", ref state, ref shortIntValues, ref textValues, ref intValues, ref decimalValues, ref booleanValues, ref dateTimeValues, ref extendedValues);

            VoiceAttackPlugin.updateSystem("LFT 926");
            VoiceAttackPlugin.VA_Invoke1("system", ref state, ref shortIntValues, ref textValues, ref intValues, ref decimalValues, ref booleanValues, ref dateTimeValues, ref extendedValues);
        }
예제 #17
0
        public void VoiceAttackPluginTests_InitialisesNewFSUIPCInterface()
        {
            var mockInterface = new Mock <IFSUIPCInterface>();
            var mockFactory   = new Mock <IFSUIPCFactory>();

            mockFactory.Setup(factory => factory.createFSUIPCInterface(It.IsAny <IFSUIPC>(),
                                                                       It.IsAny <IOffsetFactory>())).Returns(mockInterface.Object);

            MyVAProxy proxy = new MyVAProxy();

            VoiceAttackPlugin.SetFSUIPCFactory(proxy, mockFactory.Object);

            // Call Init1
            VoiceAttackPlugin.VA_Init1(proxy);

            Assert.IsTrue(proxy.SessionState.ContainsKey(
                              VoiceAttackPlugin.SESSIONSTATE.KEY_FSUIPCINTERFACE));
            Assert.IsInstanceOfType(proxy.SessionState[
                                        VoiceAttackPlugin.SESSIONSTATE.KEY_FSUIPCINTERFACE], typeof(IFSUIPCInterface));

            mockInterface.Verify(x => x.initialise(proxy), Times.AtMost(1));
        }
예제 #18
0
        public void TestPathingString4()
        {
            string        pathingString  = @";;;;;;Seven;;;";
            List <string> pathingOptions = new List <string>()
            {
                ""
                , "Seven"
            };

            int sevenCount = 0;

            for (int i = 0; i < 10000; i++)
            {
                string pathedString = VoiceAttackPlugin.SpeechFromScript(pathingString);
                if (pathedString == "Seven")
                {
                    sevenCount++;
                }
            }

            Assert.IsTrue(sevenCount > 750);
            Assert.IsTrue(sevenCount < 1500);
        }
예제 #19
0
 public void TestVAPluginHumanize1()
 {
     Assert.AreEqual("on the way to 12 and a half thousand", VoiceAttackPlugin.humanize(12345));
 }
예제 #20
0
 public void TestVAPluginHumanize3()
 {
     Assert.AreEqual("zero", VoiceAttackPlugin.humanize(0));
 }
예제 #21
0
 public void TestVAPluginHumanize2()
 {
     Assert.AreEqual(null, VoiceAttackPlugin.humanize(null));
 }