#16244: Simplify TestSuite's some_elements role and logic (no random sampling)
-------------------------------------+-------------------------------------
       Reporter:  nthiery            |        Owner:
           Type:  defect             |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-6.2
      Component:  doctest framework  |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Nicolas M. ThiƩry  |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  
u/nthiery/simplify_testsuite_s_some_elements_role_and_logic__no_random_sampling_|
  2486f804d260370ee1d9a7a9b3a7962a36ea0e65
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------
Changes (by nthiery):

 * cc: roed, saraedum (added)


Old description:

> Currently `TestSuite` (more precisely `InstanceTester.some_elements`)
> tries to be fancy by choosing "some elements" using a random sample. The
> random sample is built using Python's `random.sample`, which requires its
> input to be a Sequence (the i-th element can be fetched with o[i]), or
> some dict-like object. This can get brittle with other kinds of inputs
> where `__getitem__` is used for other purposes, or where unranking is
> just computationally expensive. The `some_elements` method also assumes
> `__len__` to be implemented and cheap enough.
>
> Example:
> {{{
> FF = IntegerModRing(29)
> tester = FF._tester()
> list(tester.some_elements(CartesianProduct(FF, FF, FF)))
> *bang*
> }}}
>
> In fact the following is close to fail, and just works because the error
> raised during the sample is caught.
> {{{
> tester.some_elements(FF)
> }}}
>
> This ticket reduces the role of `InstanceTester.some_elements` to just do
> some argument parsing and ensure that at most "max_run" elements are
> returned. It only requires the input to be iterable.
>
> If we want to have fancy random samples, we should define a specific
> protocol (typically P.sample()) for it, or just let parents decide on the
> appropriate strategy by defining some_elements appropriately.
>
> This was originaly analyzed in #15919.

New description:

 Since #14284, `TestSuite` (more precisely `InstanceTester.some_elements`)
 tries to be fancy by choosing "some elements" using a random sample. The
 random sample is built using Python's `random.sample`, which requires its
 input to be a Sequence (i.e. the i-th element can be fetched with o[i]),
 or some dict-like object. This can get brittle with inputs where
 `__getitem__` is used for other purposes, or where unranking is just
 computationally expensive. The `some_elements` method also assumes
 `__len__` to be implemented and cheap enough.

 Example:
 {{{
 sage: FF = IntegerModRing(29)  # needs to be >21 otherwise random.sample
 uses a different strategy
 sage: tester = FF._tester(elements=FF, max_runs=5)
 sage: list(tester.some_elements())
 ...
 ValueError: first letter of variable name must be a letter
 }}}


 This ticket reduces the role of `InstanceTester.some_elements` to just do
 some argument parsing and ensure that at most "max_run" elements are
 returned. It only requires the input to be iterable.

 If we want to have fancy random samples, we should define a specific
 protocol (typically P.sample()) for it, or just let parents decide on the
 appropriate strategy by defining some_elements appropriately.

 This was originaly analyzed in #15919.

--

--
Ticket URL: <http://trac.sagemath.org/ticket/16244#comment:3>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to