예제 #1
0
        public void trimTestResult()
        {
            this.singleLoopGraph();

            Graph g = new Graph(this.testMap);
            // The full graph with 0 as seed
            Slice slice = new Slice(new HashSet <int>(new int[] { 0, 1, 2, 3, 4 }), new HashSet <int>(new int[] { 0 }));

            this.obfr.Trim(slice, g);

            ResultSet result = this.obfr.Result;

            Assert.IsTrue(result.Contains(0));
            Assert.IsTrue(result.Contains(1));
            CollectionAssert.AreEquivalent(new int[] { 0 }, result.SCCById(0).ToList());
            CollectionAssert.AreEquivalent(new int[] { 1 }, result.SCCById(1).ToList());
        }
예제 #2
0
        public void AddTest()
        {
            ResultSet results = new ResultSet();

            results.Add(new HashSet <int> {
                1, 3
            });

            Assert.IsTrue(results.Contains(1));
            Assert.IsTrue(results.Contains(3));

            Assert.IsFalse(results.Contains(2));

            results.Add(new HashSet <int> {
                2
            });

            Assert.IsTrue(results.Contains(2));
        }
예제 #3
0
        public void trivialComponentsTest()
        {
            testMap[0] = new List <int>();
            testMap[1] = new List <int>();
            testMap[2] = new List <int>();


            foreach (SCCDetector detector in this.detectors)
            {
                Graph     g       = new Graph(testMap);
                ResultSet results = detector.Compute(g);

                Assert.AreEqual(3, results.List.Count);

                for (int i = 0; i < 3; i++)
                {
                    Assert.IsTrue(results.Contains(i));
                }
            }
        }
예제 #4
0
        public void concurrencyTrivialComponentsTest()
        {
            int size = 100;

            for (int i = 0; i < size; i++)
            {
                testMap[i] = new List <int>();
            }

            foreach (SCCDetector detector in this.concurrentDetectors)
            {
                Graph g = new Graph(testMap);

                ResultSet results = detector.Compute(g);

                Assert.IsTrue(results.List.Count == size);

                for (int i = 0; i < size; i++)
                {
                    Assert.IsTrue(results.Contains(i));
                }
            }
        }
예제 #5
0
        public void ConcurrencyTest()
        {
            ResultSet results = new ResultSet();

            Task[] tasks = new Task[50];

            for (int i = 0; i < 50; i++)
            {
                // Make a copy to capture the variable
                // https://stackoverflow.com/questions/271440/captured-variable-in-a-loop-in-c-sharp
                int copy = i;
                tasks[i] = Task.Factory.StartNew(() => AddToResultSet(results, copy));
            }

            Task.WaitAll(tasks);

            Assert.AreEqual(results.Count(), 50);

            for (int i = 0; i < 50; i++)
            {
                Assert.IsTrue(results.Contains(i));
            }
        }