public void ConstructorTest()
        {
            int n = 10;
            DisjointSetForest forest = new DisjointSetForest(n);

            Assert.IsNotNull(forest);
        }
        public void MakeUnionTest()
        {
            int n = 2;
            DisjointSetForest forest = new DisjointSetForest(n);

            forest.MakeUnion(0, 1);
            Assert.AreEqual(0, forest[1]);
        }
        public void GetRootTest()
        {
            int n = 2;
            DisjointSetForest forest = new DisjointSetForest(n);

            forest.MakeUnion(0, 1);
            Assert.AreEqual(0, forest.GetRoot(1));
        }
        public void GetTest()
        {
            int n = 10;
            DisjointSetForest forest = new DisjointSetForest(n);

            for (int i = 0; i < n; i++)
            {
                Assert.AreEqual(-1, forest[i]);
            }
        }
        public void GetSetsTest()
        {
            int n = 6;
            DisjointSetForest forest = new DisjointSetForest(n);

            forest.MakeUnion(0, 1);
            forest.MakeUnion(2, 3);
            forest.MakeUnion(4, 5);
            int[][] sets        = forest.GetSets();
            int[][] expected    = new int[][] { new[] { 0, 1 }, new[] { 2, 3 }, new[] { 4, 5 } };
            string  failMessage = "Expected " + Arrays.DeepToString(expected) + " but was " + Arrays.DeepToString(sets);

            Assert.IsTrue(Compares.DeepEquals(expected, sets), failMessage);
        }
        /// <summary>
        /// The automorphism partition is a partition of the elements of the group.
        ///
        /// <returns>a partition of the elements of group</returns>
        /// </summary>
        public Partition GetAutomorphismPartition()
        {
            int n = group.Count;
            DisjointSetForest forest = new DisjointSetForest(n);

            group.Apply(new AutomorphismPartitionBacktracker(n, forest));

            // convert to a partition
            Partition partition = new Partition();

            foreach (var set in forest.GetSets())
            {
                partition.AddCell(set);
            }

            // necessary for comparison by string
            partition.Order();
            return(partition);
        }
 public AutomorphismPartitionBacktracker(int n, DisjointSetForest forest)
 {
     this.n      = n;
     this.forest = forest;
     inOrbit     = new bool[n];
 }