25.2 Test Structures and Types

665auxiliary 628+   (626 660 669 728)  661a  670
macro V == CycleIndexVariable;
macro T ==  SparseIndexedPowerProduct(V, I);
local integerPartitions(n: I, bound: I): Generator T == generate {
        import from V, T;
        zero? n => yield 1$T;
        for m in min(n, bound) .. 1 by -1 repeat {
                for p in integerPartitions(n-m, min(m, bound)) repeat {
                        yield p * power(m::V, 1);
                }
        }
}
local cycleType(p: P): T == {
        import from V;
        t: T := 1;
        for l in p repeat t := t * power((#l)::V, 1);
        t;
}
local partitionTest(
    n: I,
    expectedStructures: List P,
    expectedTypes: List P
): () == {
        import from Partition I;
        s := set([generator(0..prev n)])$SetSpecies(I);
        k: I := 0;
        for a in structures(s) repeat k := next k;
        assertEquals(I, #expectedStructures, k);
        for a in expectedStructures for p in structures(s) repeat {
                assertEquals(P, a, p::P);
        }
        k := 0;
        for a in isomorphismTypes(s) repeat k := next k;
        assertEquals(I, #expectedTypes, k);
        for a in expectedTypes for p in isomorphismTypes(s) repeat {
                assertEquals(P, a, p::P);
        }
        k := 0;
        for t in integerPartitions(n, n) repeat k := next k;
        assertEquals(I, #expectedTypes, k);
        for a in expectedTypes for t in integerPartitions(n, n) repeat {
                assertEquals(T, cycleType a, t);
        }
}

Uses CycleIndexVariable 329, Generator 617, I 47, Partition 146, SetSpecies 117, and SparseIndexedPowerProduct 506.
666atest set partition 666a  (660)  666b
testPartition0(): () == partitionTest(0, [[]], [[]]);
666btest set partition 666a+   (660)  666a  666c
testPartition1(): () == partitionTest(1, [[[0]]], [[[0]]]);
666ctest set partition 666a+   (660)  666b  667a
testPartition2(): () == partitionTest(2, [
        [[0,1]],
        [[0], [1]]
    ],
    [
        [[0,1]],
        [[0], [1]]
    ]
);
667atest set partition 666a+   (660)  666c  667b
testPartition3(): () == partitionTest(3, [
        [[0,1,2]],
        [[0,1],[2]],
        [[0,2],[1]],
        [[0],[1,2]],
        [[0],[1],[2]]
    ],
    [
        [[0,1,2]],
        [[0,1],[2]],
        [[0],[1],[2]]
    ]
);
667btest set partition 666a+   (660)  667a
testPartition4(): () == partitionTest(4, [
        [[0,1,2,3]],      -- [1,0,0,0]
        [[0,1,2],[3]],    -- [2,0,0,1]
        [[0,1,3],[2]],    -- [2,0,1,0]
        [[0,1],[2,3]],    -- [2,0,1,1]
        [[0,1],[2],[3]],  -- [3,0,1,2]
        [[0,2,3],[1]],    -- [2,1,0,0]
        [[0,2],[1,3]],    -- [2,1,0,1]
        [[0,2],[1],[3]],  -- [3,1,0,2]
        [[0,3],[1,2]],    -- [2,1,1,0]
        [[0],[1,2,3]],    -- [2,1,1,1]
        [[0],[1,2],[3]],  -- [3,1,1,2]
        [[0,3],[1],[2]],  -- [3,1,2,0]
        [[0],[1,3],[2]],  -- [3,1,2,1]
        [[0],[1],[2,3]],  -- [3,1,2,2]
        [[0],[1],[2],[3]] -- [4,1,2,3]
    ],
    [
        [[0,1,2,3]],
        [[0,1,2],[3]],
        [[0,1],[2,3]],
        [[0,1],[2],[3]],
        [[0],[1],[2],[3]]
    ]
);