Пример #1
0
        public void CountPairs(int[] arr, int expectedResult)
        {
            var sut    = new PairCounter();
            var result = sut.CountPairs(arr);

            result.Should().Be(expectedResult);
        }
Пример #2
0
 void Start()
 {
     comparer = new CardComparer(CardComparerCallback);
     InitCards();
     remainingPairs.Value = cards.Length / 2;
     pairCounter          = new PairCounter(remainingPairs, OnGameOver);
 }
Пример #3
0
        public void Test(int[] dimensions, int bestSoFar, int targetCases)
        {
            int features = dimensions.Length;

            string[][] sources = new string[features][];

            for (int i = 0; i < features; i++)
            {
                string featureName = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Substring(i, 1);

                int n = dimensions[i];
                sources[i] = new string[n];
                for (int j = 0; j < n; j++)
                {
                    sources[i][j] = featureName + j.ToString();
                }
            }

            ICombiningStrategy strategy = new PairwiseStrategy();

            PairCounter pairs = new PairCounter();
            int         cases = 0;

            foreach (NUnit.Framework.Internal.TestCaseParameters parms in strategy.GetTestCases(sources))
            {
                for (int i = 1; i < features; i++)
                {
                    for (int j = 0; j < i; j++)
                    {
                        string a = parms.Arguments[i] as string;
                        string b = parms.Arguments[j] as string;
                        pairs[a + b] = null;
                    }
                }

                ++cases;
            }

            int expectedPairs = 0;

            for (int i = 1; i < features; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    expectedPairs += dimensions[i] * dimensions[j];
                }
            }

            Assert.That(pairs.Count, Is.EqualTo(expectedPairs), "Number of pairs is incorrect");
            Assert.That(cases, Is.AtMost(bestSoFar), "Regression: Number of test cases exceeded target previously reached");
#if DEBUG
            //Assert.That(cases, Is.AtMost(targetCases), "Number of test cases exceeded target");
#endif
        }
Пример #4
0
            public static OSResult guessOS(string[] foundServices)
            {
                OSResult result;

                // Initialize objects
                NeuralNetwork.Network net = new NeuralNetwork.Network();

                // Load in data to memory
                if (!File.Exists(Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents", "Gerbil", "memstore", "OSServiceTraining.ini")))
                {
                    return(new OSResult("ERROR", 0.0f));
                }
                string[] trainingData = File.ReadAllLines(Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents", "Gerbil", "memstore", "OSServiceTraining.ini"));
                // Calculate weights
                PairCounter pc = new PairCounter();

                foreach (string i in trainingData)
                {
                    string sName = i.Split('=')[0];
                    string fOS   = i.Split('=')[1];
                    pc.Add(new Pair(sName, fOS));
                }
                Dictionary <Pair, float> connectionWeights = getPercentagesFromPair(pc.getResults());

                // TODO: Train network
                foreach (KeyValuePair <Pair, float> i in connectionWeights)
                {
                    net.addInput(i.Key.item1);
                    net.addOutput(i.Key.item2, i.Key.item1 + "Connector", i.Value, i.Key.item1);
                }
                // Feed data into tranined neural network
                foreach (string i in foundServices)
                {
                    try
                    {
                        net.fireInput(i);
                    }
                    catch (NeuralNetwork.NodeNotFoundException e)
                    {
                        // Serive does not exist, since we are not in training mode, ignore.
                    }
                    catch
                    {
                        // A serious engine error occured. Throw fatal error.
                        throw new FatalEngineException();
                    }
                }
                // Get outputs
                Dictionary <string, float> results = net.getResults();
                string resultName      = "Unknown";
                float  resultCertainty = 0.0f;
                float  maxCertainty    = 0.0f;

                // Find most likely answer
                foreach (KeyValuePair <string, float> i in results)
                {
                    if (i.Value > resultCertainty)
                    {
                        resultName      = i.Key;
                        resultCertainty = i.Value;
                        maxCertainty   += i.Value;
                    }
                }
                resultCertainty = resultCertainty / maxCertainty;
                result          = new OSResult(resultName, resultCertainty);
                return(result);
            }
Пример #5
0
 public void TestFixtureSetUp()
 {
     pairsTested = new PairCounter();
 }
Пример #6
0
 public void OneTimeSetUp()
 {
     pairsTested = new PairCounter();
 }