Re: Unit testing

Chris Angelico <[email protected]>
Newsgroups gmane.comp.lang.pike.user
Message-ID <CAPTjJmp7YU_dJ=aJad9Y4JR7OCCrLKJNAK_dHWX92NHr7eKxCw@mail.gmail.com>
On Sat, Oct 18, 2014 at 9:00 PM, Tor Edvardsson @ Pike  importmöte för
mailinglistan <[email protected]> wrote:
> Python unit testing
> method named test*

Which Python framework did you look at? I'm guessing unittest, but
that's far from the only one. There's another fairly popular one that
may be worth considering: doctest. In Python, it looks something like
this (excerpted from the example):

def factorial(n):
    """Return the factorial of n, an exact integer >= 0.

    >>> [factorial(n) for n in range(6)]
    [1, 1, 2, 6, 24, 120]
    >>> factorial(30)
    265252859812191058636308480000000
    """
    ... code here ...

The Pike version could make use of the new 8.0 string literal syntax:

constant test_factorial=#[
> mixed all=enumerate(6); factorial(all[*]);
(1) Result: ({ /* 6 elements */
                1,
                1,
                2,
                6,
                24,
                120
            })
> factorial(30);
(2) Result: 265252859812191058636308480000000
#];
int factorial(int(0..) n)
{
    return n?`*(@enumerate(n,1,1)):1;
}

(Side point: It seems that enumerate(6)[*] isn't legal, although it
would be if the 6 is replaced with something that can't be
compile-time optimized. Not sure why [*] can't follow literal arrays.
Would be nice if it could - if only for this kind of thing.)

I've used this kind of technique (an associated constant) for a few
tricks. It's a convenient way of attaching metadata to a
function.Would it be useful here?

ChrisA
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.