private void CheckPartitions(int n) { // Some sets to make sure partition and conjugate only appear once. // Also tests equality, hash set. HashSet <IntegerPartition> set = new HashSet <IntegerPartition>(); HashSet <IntegerPartition> conjugateSet = new HashSet <IntegerPartition>(); foreach (IntegerPartition partition in IntegerPartition.GetPartitions(n)) { Assert.IsTrue(partition != null); // Values should add to number. int vCount = 0; foreach (int v in partition.Values) { Assert.IsTrue(v > 0); vCount += v; } Assert.IsTrue(vCount == n); // Elements should add to number. int eCount = 0; foreach (Element e in partition.Elements) { Assert.IsTrue(e.Value > 0); Assert.IsTrue(e.Multiplicity > 0); eCount += e.Value * e.Multiplicity; } Assert.IsTrue(eCount == n); // Partition should be generated only once Assert.IsTrue(!set.Contains(partition)); set.Add(partition); IntegerPartition conjugate = partition.Conjugate(); // Conjugate values should add to same number int cCount = 0; foreach (int c in conjugate.Values) { Assert.IsTrue(c > 0); cCount += c; } Assert.IsTrue(cCount == n); // Conjugate should be generated only once Assert.IsTrue(!conjugateSet.Contains(conjugate)); conjugateSet.Add(conjugate); // Rank should fulfill inequality and be related to conjugate rank Assert.IsTrue((-n < partition.Rank) && (partition.Rank < n)); Assert.IsTrue(conjugate.Rank == -partition.Rank); // Double-conjugating should return us to the original Assert.IsTrue(conjugate.Conjugate() == partition); } }
private long PartitionFunction(int n) { return(IntegerPartition.GetPartitions(n).LongCount()); }