Esempio n. 1
0
with AssertError(TypeError):
    example.agg(-18)

with AssertError(TypeError):
    example.agg("howdy ho!")

assert_eq(
    example.sum_of_products([
        range(1, 4),  # 3! = 6
        [2, 2, 2],  # 8
        (i**2 for i in range(1, 20) if '7' in str(i))  # 7**2 * 17**2 = 14161
    ]),
    6 + 8 + 14161)

f = example.fib(10)
assert_isinstance(f, list)
assert_eq(example.digits(123), [3, 2, 1])
assert_eq(example.names(), ['jim', 'victor', 'loa'])
assert_eq(example.points(), [(1, 2), (2, 3), (3, 4)])
assert_eq(example.matrix(), [(1, 2, 3), (2, 3, 4), (3, 4, 5)])

people = example.people()
assert_isinstance(people, list)
assert_eq([x.id for x in people], [15, 47, 7])
assert_eq([x.age for x in people], [20, 98, 3])
del people


def half_use_list():
    l = list(islice(example.strings(), 2))
Esempio n. 2
0
# See http://cens.ioc.ee/projects/f2py2e/usersguide/index.html for
# f2py users guide
import example
import numpy

print example.fib(12)

x = numpy.arange(10.)

yf = example.cumsum(x)
yn = numpy.cumsum(x)

numpy.testing.assert_array_almost_equal(yf, yn)
Esempio n. 3
0
import example

from swimport.tests.resources import *

assert_eq(example.fib(5, 0, 1), 5)
assert_eq(example.fib(10, ...), 55)
assert_eq(example.fib(5, 1), 5)

with AssertError((TypeError, NotImplementedError)):
    example.fib(10, None)

with AssertError(TypeError):
    example.accept_only_notimplemented(...)

assert_true(example.accept_only_notimplemented(NotImplemented))

assert_eq(example.count("abc\0oaia", 'a', 1, 6), 1)
assert_eq(example.count("abc\0oaia", 'a', 1, None), 0)
assert_eq(example.count("abc\0oaia", 'a', None, 6), 2)
assert_eq(example.count("abc\0oaia", 'a', None, None), 1)

assert_is(example.get_ellipsis(), ...)
assert_is(example.get_none(), None)
assert_is(example.get_ni(), NotImplemented)

for s in (None, NotImplemented, ...):
    c = example.code(s)
    efc = example.from_code(example.code(s))
    assert_is(efc, s)
Esempio n. 4
0
import numpy as N

import example

n = 10
fn = example.fib(n)

print 'Fibonacci numbers:'
print fn

# Check validity
assert N.alltrue(fn[2:]== fn[1:-1]+fn[:-2]), "Fibonacci mismatch"

Esempio n. 5
0
import example

print(example.fib(5))
Esempio n. 6
0
#!/usr/bin/env python
"""Simple demo of Fibonacci numbers construction  in Fortran."""

from __future__ import print_function

import numpy as np

from example import fib

npts = 17
a = np.empty(npts)
fib(a)

print('The first', npts, 'Fibonacci numbers:\n', a)
Esempio n. 7
0
#cython: language_level=3
import pyximport; pyximport.install()
import example
print(example.fib(2000))





'''
pyximport: Cython Compilation for Developers
If your module doesn’t require any extra C libraries or a special build setup, then you can use the pyximport module, originally developed by Paul Prescod, to load .pyx files directly on import, without having to run your setup.py file each time you change your code. It is shipped and installed with Cython and can be used like this:
'''