32 Test Sparse Indexed Power Products

In this file we test src/poly/idxpp.as.nw.

743* 13+   733  749
-------------------------------------------------------------------
----
---- Combinat
---- Copyright (C) Ralf Hemmecke <ralf@hemmecke.de>
---- svn co svn://svn.risc.uni-linz.ac.at/hemmecke/combinat/
----
-------------------------------------------------------------------

#assert DontNeedLibraryTestCases
#include "testcases"

TestSparseIndexedPowerProduct: TestCaseType with {
#include "idxpp.signatures.as"
} == add {
        import from TestCaseTools;
        macro V == CycleIndexVariable;
        import from Z, V, Q;
        test one 742a
        test times 742b
        test weight 745b
        test compare 735a
        test divisors 746b
}

Defines:
TestSparseIndexedPowerProduct, never used.

Uses CycleIndexVariable 329, Q 47, and Z 47.
744atest one 742a+   (733 743 749)  742a  751b
testOne1(): () == {
        macro T == SparseIndexedPowerProduct(V, Q);
        t: T := 1;
        assertEquals(T, 1, t);
        assertTrue(one? t);
}

Uses Q 47 and SparseIndexedPowerProduct 506.
744btest times 742b+   (733 743 749)  742b  745a
testTimes1(): () == {
        macro T == SparseIndexedPowerProduct(V, Q);
        import from MachineInteger;
        t1: T := power(1::V, 1);
        t2: T := power(2::V, 1);
        t4: T := power(1::V, 3/4);
        assertEquals(T, t1*t2, t2*t1);
        assertEquals(T, t1*t1, power(1::V, 2/1));
        assertEquals(T, t1*t1*t1, t4*t4*t4*t4);
        assertEquals(T, t1*t4*t2*t2, t2*t4*t2*t1);
        assertTrue(T has with {/: (%, %) -> %});
}

Uses MachineInteger 67, Q 47, and SparseIndexedPowerProduct 506.
745atest times 742b+   (733 743 749)  744b  752
testTimes2(): () == {
        macro T == SparseIndexedPowerProduct(Q, Q);
        macro UnBug == BugWorkaround(T has with {/:(%, %)->%});
        t1: T := power(1, 1);
        t2: T := power(2/3, 1);
        t3: T := power(3/5, 1);
        assertTrue(T has with {/: (%, %) -> %});
        UnBug assertEquals(T, t3/(t1*t2), t3/t2/t1);
        UnBug assertEquals(T, t3/(t1*t2), t3/t2/t1);
        UnBug assertEquals(T, power(1,-1)*power(2/3,-1)*t3, t3/t2/t1);
}

Uses BugWorkaround 48, Q 47, and SparseIndexedPowerProduct 506.
745btest weight 745b  (743)  745c
testWeight1(): () == {
        macro T == SparseIndexedPowerProduct(Q, Q);
        assertFalse(T has with {weight: % -> Q});
}

Uses Q 47 and SparseIndexedPowerProduct 506.
745ctest weight 745b+   (743)  745b
testWeight2(): () == {
        macro T == SparseIndexedPowerProduct(V, I);
        assertTrue(T has with {weight: % -> I});
        import from MachineInteger;
        t1: T := power(1::V, 22);
        t2: T := power(2::V, 7);
        t4: T := power(4::V, 67);
        assertEquals(I, 22, weight t1);
        assertEquals(I, 14, weight t2);
        assertEquals(I, 268, weight t4);
        assertEquals(I, 362, weight(t1*t1*t1*t2*t2*t4)); --3*1*22+2*2*7+1*4*67
}

Uses I 47, MachineInteger 67, and SparseIndexedPowerProduct 506.
746atest compare 735a+   (733 743)  736a
testCompare1(): () == {
        macro T == SparseIndexedPowerProduct(V, I);
        import from MachineInteger;
        t1: T := power(1::V, 5);
        t2: T := power(5::V, 1);
        assertTrue(compare(t1, t2) > 0);
        assertTrue(t1 > t2);
}

Uses I 47, MachineInteger 67, and SparseIndexedPowerProduct 506.
746btest divisors 746b  (743)  747a
divisorsTest(t: SparseIndexedPowerProduct(I, I), expected: List I): () == {
        macro T == SparseIndexedPowerProduct(I, I);
        import from I, T, List I;
        BugWorkaround(T has with {divisors: % -> Generator %}){
                divisors: List I := empty;
                for d in divisors t repeat {
                        i: I := 1;
                        for ep in d repeat {
                                (e, p) := ep;
                                i := p^e * i;
                        }
                        divisors := cons(i, divisors);
                }
                assertEquals(List I, expected, sort! divisors);
        }
}

Uses BugWorkaround 48, Generator 617, I 47, and SparseIndexedPowerProduct 506.
747atest divisors 746b+   (743)  746b  747b
testDivisors1(): () == {
        import from I, List I;
        t: SparseIndexedPowerProduct(I, I) := 1;
        divisorsTest(t, [1]);
}

Uses I 47 and SparseIndexedPowerProduct 506.
747btest divisors 746b+   (743)  747a  747c
testDivisors2(): () == {
        import from I, List I;
        macro T == SparseIndexedPowerProduct(I, I);
        t: T := power(2, 1) * power(3, 2) * power(5, 1); -- 2*9*5=90
        divisorsTest(t, [1,2,3,5,6,9,10,15,18,30,45,90]);
}

Uses I 47 and SparseIndexedPowerProduct 506.
747ctest divisors 746b+   (743)  747b
testDivisors3(): () == {
        import from I, List I;
        macro T == SparseIndexedPowerProduct(I, I);
        t: T := power(2, 1) * power(3, 2) * power(17, 1) * power(19, 2);
        divisorsTest(t, [
                1, 2, 3, 6, 9, 17, 18, 19, 34, 38, 51, 57, 102, 114,
                153, 171, 306, 323, 342, 361, 646, 722, 969, 1083,
                1938, 2166, 2907, 3249, 5814, 6137, 6498, 12274,
                18411, 36822, 55233, 110466
            ]
        );
}

Uses I 47 and SparseIndexedPowerProduct 506.