Exemplo n.º 1
0
        static void RunHashTable(TestCaseOptions opt)
        {
            int[] testParams = new int[] { 50, 10, 10 };
            SetupParams(opt.Params, testParams);
            int   n          = testParams[0];
            int   capacity   = testParams[1];
            int   numResults = testParams[2];
            float loadFactor = 1f;
            var   ht         = new StubHashTable <Guid, int>(capacity, loadFactor);
            var   keys       = new List <Guid>();

            for (var i = 0; i < n; i++)
            {
                var guid = Guid.NewGuid();
                keys.Add(guid);
                ht[guid] = i;
            }
            var chainSizes = ht.Store.Select(ele => ele?.Count ?? 0).ToArray();

            Console.WriteLine("HashTable Entries for n entries: {0} capacity: {1} ", n, capacity);
            var arr = new string[keys.Count];

            for (var i = 0; i < keys.Count; i++)
            {
                arr[i] = string.Format("{0}: {1}", keys[i], ht[keys[i]]);
            }
            DisplayResults(arr, numResults, "\n");
        }
Exemplo n.º 2
0
        static void RunEditDistance(TestCaseOptions opt)
        {
            Console.Write("Run using defaults? (Y/N):");
            var    runDefaults = Console.ReadLine().Trim();
            string a, b;

            a = "editing";
            b = "distance";
            if (runDefaults.ToLower().Equals("n"))
            {
                Console.Write("\nEnter first string:");
                a = Console.ReadLine();
                Console.Write("\nEnter second string:");
                b = Console.ReadLine();
            }
            var editDistResult = DynamicProgramming.EditDistance(a, b);

            Console.WriteLine("Editing Distance of {0}, {1}: {2}", a, b, editDistResult[a.Length, b.Length]);

            var sb = new StringBuilder();
            var backtrackResult = DynamicProgramming.EditDistanceBacktrack(editDistResult, a, b);

            foreach (var alignment in backtrackResult)
            {
                sb.AppendFormat("[{0}:{1}] ", alignment.Item1, alignment.Item2);
            }
            Console.WriteLine("Outputting Alignment {0}", sb.ToString());
        }
Exemplo n.º 3
0
        static void RunSieveOfEratosthenes(TestCaseOptions opt)
        {
            int[] testParams = new int[] { Int32.MaxValue / 100, 10 };
            SetupParams(opt.Params, testParams);
            int numPrimes  = testParams[0];
            int numResults = testParams[1];
            var arr        = Numeric.GetPrimes(numPrimes);

            Console.WriteLine("N: {0:N0}. Primes Found: {1:N0}", testParams[0], arr.Length);
            DisplayResults(arr, numResults);
        }
Exemplo n.º 4
0
        static void RunUniversalHashingFamily(TestCaseOptions opt)
        {
            int[] testParams = new int[] { 100, 100, 10 };
            SetupParams(opt.Params, testParams);
            var hashCount  = testParams[0];
            var bucketSize = testParams[1];
            var numResults = testParams[2];
            var hashes     = new uint[hashCount];
            var hashFunc   = Hashing.UniversalHashingFamily();

            for (var i = 0; i < hashCount; i++)
            {
                hashes[i] = hashFunc((uint)i) % (uint)bucketSize;
            }
            Console.WriteLine("Universal Hash Family values for x: [0-{0}] ", hashCount);
            DisplayResults(hashes, numResults);
        }
Exemplo n.º 5
0
        static void RunKnapsackWithoutRepetitions(TestCaseOptions opt)
        {
            Console.Write("Run using defaults? (Y/N):");
            var runDefaults = Console.ReadLine().Trim();

            Tuple <int, int>[] items;
            int[] knapsackWeights;
            if (runDefaults.ToLower().Equals("y") || runDefaults == string.Empty)
            {
                items = new Tuple <int, int>[] {
                    new Tuple <int, int>(10, 60),
                    new Tuple <int, int>(20, 100),
                    new Tuple <int, int>(30, 120),
                };
                knapsackWeights = new int[] { 10, 20, 30, 40, 50, 60 };
            }
            else
            {
                Console.Write("Enter num knapsack items:");
                var numItems = Convert.ToInt32(Console.ReadLine().Trim());
                items = new Tuple <int, int> [numItems];
                for (var i = 0; i < numItems; i++)
                {
                    Console.Write("\nEnter weight and value for item {0}:", i + 1);
                    var knapItem = ReadLineParseInts();
                    items[i] = new Tuple <int, int>(Convert.ToInt32(knapItem[0]), Convert.ToInt32(knapItem[1]));
                }
                Console.Write("\nEnter optimal knapsack weights to test:");
                var weights = ReadLineParseInts();
                knapsackWeights = new int[weights.Length];
                for (var i = 0; i < weights.Length; i++)
                {
                    knapsackWeights[i] = Convert.ToInt32(weights[i]);
                }
            }
            foreach (var capacity in knapsackWeights)
            {
                var result = DynamicProgramming.KnapsackWithoutRepetitions(capacity, items);
                Console.WriteLine("Knapsack without Repetitions, knapsack capacity {0}, max total value {1}", capacity, result[capacity, items.Length]);
                var backtrack = DynamicProgramming.KnapsackWithoutRepetitionsBacktrack(capacity, items);
                var output    = Helper.Display(backtrack);
                Console.WriteLine("{0}", output);
            }
        }
Exemplo n.º 6
0
        static void RunEditDistanceOnGeneSequence(TestCaseOptions opt)
        {
            Console.Write("Run using defaults? (Y/N):");
            var runDefaults = Console.ReadLine().Trim();
            int count = 10, length = 15;

            if (runDefaults.ToLower().Equals("n"))
            {
                Console.Write("\nEnter sequence count and length:");
                var inputs = ReadLineParseInts();
                count  = inputs[0];
                length = inputs[1];
            }
            var sequencePairs = GenerateNucleotideSequencePairs(count, length);

            foreach (var pair in sequencePairs)
            {
                var editDistResult = DynamicProgramming.EditDistance(pair.Item1, pair.Item2);
                Console.WriteLine("Editing Distance of {0}, {1}: {2}", pair.Item1, pair.Item2, editDistResult[pair.Item1.Length, pair.Item2.Length]);
            }
        }
Exemplo n.º 7
0
        private static TestCase GetTestCase(TestCaseOptions testCaseOptions, string fullyQualifiedName, string displayName, int lineNumber, string filePath)
        {
            var testCase = new TestCase()
            {
                FullyQualifiedName = fullyQualifiedName,
                DisplayName        = displayName,
                LineNumber         = lineNumber,
                ExecutorUri        = NodejsConstants.ExecutorUri,
                Source             = testCaseOptions.Source,
                CodeFilePath       = filePath,
            };

            testCase.SetPropertyValue(JavaScriptTestCaseProperties.TestFramework, testCaseOptions.TestFramework.ToString());
            testCase.SetPropertyValue(JavaScriptTestCaseProperties.WorkingDir, testCaseOptions.WorkingDir);
            testCase.SetPropertyValue(JavaScriptTestCaseProperties.ProjectRootDir, testCaseOptions.WorkingDir);
            // TODO: We might only want to check that this is not empty. The value changes depending on the environment.
            //testCase.SetPropertyValue(JavaScriptTestCaseProperties.NodeExePath, nodeExePath);
            testCase.SetPropertyValue(JavaScriptTestCaseProperties.TestFile, filePath);
            testCase.SetPropertyValue(JavaScriptTestCaseProperties.ConfigDirPath, testCaseOptions.ConfigDirPath);

            return(testCase);
        }
Exemplo n.º 8
0
        static void RunLongestCommonSubsequence(TestCaseOptions opt)
        {
            Console.Write("Run using defaults? (Y/N):");
            var    runDefaults = Console.ReadLine().Trim();
            string a, b;

            a = "editing";
            b = "distance";
            if (runDefaults.ToLower().Equals("n"))
            {
                Console.Write("\nEnter first string:");
                a = Console.ReadLine();
                Console.Write("\nEnter second string:");
                b = Console.ReadLine();
            }
            var result = DynamicProgramming.LongestCommonSubsequence(a, b);

            Console.WriteLine("LCS for input sequences {0}, {1}: {2}", a, b, result[a.Length, b.Length]);
            var backtrackResult = DynamicProgramming.LCSBacktrack(result, a, b);

            Console.WriteLine("Outputting Alignment {0}", new string(backtrackResult));
        }
Exemplo n.º 9
0
        static void RunHashTableDistribution(TestCaseOptions opt)
        {
            int[] testParams = new int[] { 50, 10 };
            SetupParams(opt.Params, testParams);
            int   n          = testParams[0];
            int   capacity   = testParams[1];
            float loadFactor = n;
            var   ht         = new StubHashTable <Guid, int>(capacity, loadFactor);
            var   keys       = new List <Guid>();

            for (var i = 0; i < n; i++)
            {
                var guid = Guid.NewGuid();
                keys.Add(guid);
                ht[guid] = i;
            }
            var chainLengths = ht.Store.Select(ele => (double)(ele?.Count ?? 0)).ToList();

            Console.WriteLine("HashTable Distribution for n: {0} capacity: {1}", n, capacity);
            Console.WriteLine("Mean: {0} Median: {1} Mode: {2}", chainLengths.Average(), Helper.Median(chainLengths), Helper.Mode(chainLengths));
            var sd = Helper.StandardDeviation(chainLengths);

            Console.WriteLine("Standard Deviation {0}", sd);
        }
Exemplo n.º 10
0
        private static List <TestCase> GetTestCases(ProjectName projectName, SupportedFramework testFramework)
        {
            var testCaseOptions = new TestCaseOptions()
            {
                TestFramework = testFramework,
                WorkingDir    = GetProjectDirPath(projectName),
                Source        = GetProjectFilePath(projectName),
                ConfigDirPath = projectName == ProjectName.NodeAppWithAngularTests ? GetProjectDirPath(projectName) : null
            };

            switch (testFramework)
            {
            case SupportedFramework.Jasmine:
            {
                var filePath = Path.Combine(GetProjectDirPath(projectName), "JasmineUnitTest.js");
                return(new List <TestCase>()
                    {
                        GetTestCase(testCaseOptions, "JasmineUnitTest.js::Test Suite 1::Test 1", "Test 1", 1, filePath),
                        GetTestCase(testCaseOptions, "JasmineUnitTest.js::Test Suite 1::Test 2", "Test 2", 1, filePath),
                    });
            }

            case SupportedFramework.ExportRunner:
            {
                var filePath = Path.Combine(GetProjectDirPath(projectName), "ExportRunnerUnitTest.js");
                return(new List <TestCase>()
                    {
                        GetTestCase(testCaseOptions, "ExportRunnerUnitTest.js::global::Test 1", "Test 1", 1, filePath),
                        GetTestCase(testCaseOptions, "ExportRunnerUnitTest.js::global::Test 2", "Test 2", 1, filePath),
                    });
            }

            case SupportedFramework.Jest:
            {
                var filePath = Path.Combine(GetProjectDirPath(projectName), "JestUnitTest.js");
                return(new List <TestCase>()
                    {
                        GetTestCase(testCaseOptions, "JestUnitTest.js::Test Suite 1::Test 1 - This shouldn't fail", "Test 1 - This shouldn't fail", 3, filePath),
                        GetTestCase(testCaseOptions, "JestUnitTest.js::Test Suite 1::Test 2 - This should fail", "Test 2 - This should fail", 7, filePath),
                    });
            }

            case SupportedFramework.Mocha:
            {
                var filePath = Path.Combine(GetProjectDirPath(projectName), "MochaUnitTest.js");
                return(new List <TestCase>()
                    {
                        GetTestCase(testCaseOptions, "MochaUnitTest.js::Test Suite 1::Test 1", "Test 1", 1, filePath),
                        GetTestCase(testCaseOptions, "MochaUnitTest.js::Test Suite 1::Test 2", "Test 2", 1, filePath),
                    });
            }

            case SupportedFramework.Tape:
            {
                var filePath = Path.Combine(GetProjectDirPath(projectName), "TapeUnitTest.js");
                return(new List <TestCase>()
                    {
                        GetTestCase(testCaseOptions, "TapeUnitTest.js::global::Test A", "Test A", 1, filePath),
                        GetTestCase(testCaseOptions, "TapeUnitTest.js::global::Test B", "Test B", 1, filePath),
                    });
            }

            case SupportedFramework.Angular:
                return(new List <TestCase>()
                {
                    GetTestCase(testCaseOptions, @"src\app\app.component.spec.ts::AppComponent::should create the app", "should create the app", 14, Path.Combine(GetProjectDirPath(projectName), @"src\app\app.component.spec.ts")),
                    GetTestCase(testCaseOptions, @"src\app\app.component.spec.ts::AppComponent::should have as title 'my-app'", "should have as title 'my-app'", 20, Path.Combine(GetProjectDirPath(projectName), @"src\app\app.component.spec.ts")),
                    GetTestCase(testCaseOptions, @"src\app\app.component.spec.ts::AppComponent::should render title", "should render title", 26, Path.Combine(GetProjectDirPath(projectName), @"src\app\app.component.spec.ts")),
                    GetTestCase(testCaseOptions, @"src\app\customTest.spec.ts::CustomTest::should succeed", "should succeed", 4, Path.Combine(GetProjectDirPath(projectName), @"src\app\customTest.spec.ts")),
                    GetTestCase(testCaseOptions, @"src\app\customTest.spec.ts::CustomTest::should fail", "should fail", 8, Path.Combine(GetProjectDirPath(projectName), @"src\app\customTest.spec.ts")),
                });
            }

            throw new NotImplementedException($"ProjectName {projectName} has not been implemented.");
        }
Exemplo n.º 11
0
 public void Tac2Cil(TestCaseOptions options)
 {
     TestSourceCodeByReturnValue("Tests.Resources." + options.File, options.ClassName, options.MethodName, options.Parameter, ProviderType.CECIL, true);
 }