public void CountPairs(int[] arr, int expectedResult) { var sut = new PairCounter(); var result = sut.CountPairs(arr); result.Should().Be(expectedResult); }
void Start() { comparer = new CardComparer(CardComparerCallback); InitCards(); remainingPairs.Value = cards.Length / 2; pairCounter = new PairCounter(remainingPairs, OnGameOver); }
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 }
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); }
public void TestFixtureSetUp() { pairsTested = new PairCounter(); }
public void OneTimeSetUp() { pairsTested = new PairCounter(); }