Пример #1
0
def test_random_arith(level=MAX_LEVEL, trials=1):
    """
    Create random elements of random rings and does some arithmetic
    with them, until a crash occurs, in which case an exception is
    raised.  Defaults to running a single trial, but more can be
    specified.  To run tests in an infinite loop, you could use:
        while True: test_random_arith(trials=100, print_seed=True)

    INPUT:

    - level -- (default: MAX_LEVEL); controls the types of rings to use
    - trials -- A positive integer (default 1); the number of trials
      to run.
    - seed -- the random seed to use; if not specified, uses a truly
      random seed.
    - print_seed -- If True (default False), prints the random seed chosen.

    EXAMPLES::

        sage: import sage.rings.tests
        sage: sage.rings.tests.test_random_arith(trials=2, seed=0)
        survived 0 tests (memory usage = ...)
        Rational Field
        -1/2 -1/95
        49/95
        survived 1 tests (memory usage = ...)
        Finite Field of size 49549
        2214 16474
        40662
        sage: sage.rings.tests.test_random_arith(trials=10)
        survived 0 tests...
        sage: sage.rings.tests.test_random_arith(trials=1000)   # long time (5 seconds?)
        survived 0 tests...
    """
    i = 0
    for x in random_rings(level):
        print("survived %s tests (memory usage = %s)" %
              (i, get_memory_usage()))
        i += 1
        print(x)
        a = x.random_element()
        b = x.random_element()
        print(a, b)
        print(a * b + a - b + 1)
        if i >= trials:
            return
Пример #2
0
def test_random_arith(level=MAX_LEVEL, trials=1):
    """
    Create random elements of random rings and does some arithmetic
    with them, until a crash occurs, in which case an exception is
    raised.  Defaults to running a single trial, but more can be
    specified.  To run tests in an infinite loop, you could use:
        while True: test_random_arith(trials=100, print_seed=True)

    INPUT:

    - level -- (default: MAX_LEVEL); controls the types of rings to use
    - trials -- A positive integer (default 1); the number of trials
      to run.
    - seed -- the random seed to use; if not specified, uses a truly
      random seed.
    - print_seed -- If True (default False), prints the random seed chosen.

    EXAMPLES::

        sage: import sage.rings.tests
        sage: sage.rings.tests.test_random_arith(trials=2, seed=0)
        survived 0 tests (memory usage = ...)
        Rational Field
        -1/2 -1/95
        49/95
        survived 1 tests (memory usage = ...)
        Finite Field of size 49549
        2214 16474
        40662
        sage: sage.rings.tests.test_random_arith(trials=10)
        survived 0 tests...
        sage: sage.rings.tests.test_random_arith(trials=1000)   # long time (5 seconds?)
        survived 0 tests...
    """
    i = 0
    for x in random_rings(level):
        print("survived %s tests (memory usage = %s)" %
              (i, get_memory_usage()))
        i += 1
        print(x)
        a = x.random_element(); b = x.random_element()
        print(a, b)
        print(a*b+a-b+1)
        if i >= trials:
            return
Пример #3
0
def test_random_elements(level=MAX_LEVEL, trials=1):
    """
    Create random elements of random rings until a crash occurs, in
    which case an exception is raised.  Defaults to running a single
    trial, but more can be specified.  To run tests in an infinite
    loop, you could use:
        while True: test_random_elements(trials=100, print_seed=True)

    INPUT:
        level -- (default: MAX_LEVEL); controls the types of rings to use
        trials -- A positive integer (default 1); the number of trials
                  to run.
        seed -- the random seed to use; if not specified, uses a truly
                random seed.
        print_seed -- If True (default False), prints the random seed chosen.

    EXAMPLES::

        sage: import sage.rings.tests
        sage: sage.rings.tests.test_random_elements(trials=2, seed=0)
        survived 0 tests (memory usage = ...)
        Rational Field
        -1/2
        ----
        survived 1 tests (memory usage = ...)
        Finite Field of size 49549
        2214
        ----
        sage: sage.rings.tests.test_random_elements(trials=10)
        survived 0 tests...
        sage: sage.rings.tests.test_random_elements(trials=1000)  # long time (5 seconds)
        survived 0 tests...
    """
    r = random_rings(level)
    i = 0
    for R in r:
        print "survived %s tests (memory usage = %s)"%(i, get_memory_usage())
        i += 1
        print R
        print R.random_element()
        print "----"
        if i >= trials:
            return