Beispiel #1
0
        public void AddSingletonCellTest()
        {
            Partition p = new Partition();

            p.AddSingletonCell(0);
            Assert.AreEqual(1, p.Count);
            Assert.AreEqual(1, p.NumberOfElements());
        }
Beispiel #2
0
        public void IsDiscreteTest()
        {
            int       size = 5;
            Partition p    = new Partition();

            for (int i = 0; i < size; i++)
            {
                p.AddSingletonCell(i);
            }
            Assert.IsTrue(p.IsDiscrete());
        }
Beispiel #3
0
        public void SetAsPermutationTest()
        {
            int       partitionSize   = 5;
            int       permutationSize = 3;
            Partition partition       = new Partition();

            for (int i = 0; i < partitionSize; i++)
            {
                partition.AddSingletonCell(i);
            }
            Permutation permutation = partition.SetAsPermutation(permutationSize);

            for (int i = 0; i < permutationSize; i++)
            {
                Assert.AreEqual(i, permutation[i]);
            }
        }
Beispiel #4
0
        public void ToPermutationTest()
        {
            int       size      = 5;
            Partition partition = new Partition();

            for (int i = 0; i < size; i++)
            {
                partition.AddSingletonCell(i);
            }
            Permutation permutation = partition.ToPermutation();

            Assert.AreEqual(size, permutation.Count);
            for (int i = 0; i < size; i++)
            {
                Assert.AreEqual(i, permutation[i]);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Splits this partition by taking the cell at cellIndex and making two
        /// new cells - the first with the rest of the elements from that cell
        /// and the second with the singleton splitElement.
        /// </summary>
        /// <param name="cellIndex">the index of the cell to split on</param>
        /// <param name="splitElement">the element to put in its own cell</param>
        /// <returns>a new (finer) Partition</returns>
        public Partition SplitAfter(int cellIndex, int splitElement)
        {
            Partition r = new Partition();

            // copy the blocks up to blockIndex
            for (int j = 0; j < cellIndex; j++)
            {
                r.AddCell(this.CopyBlock(j));
            }

            // split the block at block index
            SortedSet <int> splitBlock = this.CopyBlock(cellIndex);

            splitBlock.Remove(splitElement);
            r.AddCell(splitBlock);
            r.AddSingletonCell(splitElement);

            // copy the blocks after blockIndex, shuffled up by one
            for (int j = cellIndex + 1; j < this.Count; j++)
            {
                r.AddCell(this.CopyBlock(j));
            }
            return(r);
        }