Exemple #1
0
def getints(minint = 0, maxint = 1, number=RES_LEN):
    """Returns a list of partly random ints
    
    The list starts with the numbers from INTPOOL['mandatory'], continues with
    INTPOOL['extra'] and finishes with uniformly distributed random ints.
    
    Parameters
    ----------
    minint: int, defaults to 0
    \tLower bound of ints in ist
    maxint: int, defaults to 1
    \tUpper bound of ints in ist
    number: int, defaults to RES_LEN (1000)
    \tLength of list
    
    """
    res = INTPOOL['mandatory'][:number]
    res = [x for x in res if minint <= x <= maxint]
    left = number - len(res)
    if left > 0:
        res += INTPOOL['extra'][:left]
    res = [x for x in res if minint <= x <= maxint]
    left = number - len(res)
    while left > 0:
        res += [gmpy.rand('next', maxint - minint) + gmpy.mpz(minint)]
        left -= 1
    return res
Exemple #2
0
 def _get_randchar():
     """Returns random 8 bit character"""
     
     character = None
     while character is None or character == '\n':
         character = chr(gmpy.rand('next', 255))
     
     return character
Exemple #3
0
 def test_setitem(self):
     """Single and multiple item assignment test"""
     
     self.data_array[0, 0, 0] = "'Test'"
     ##assert len(self.grid.unredo.undolist) == 1
     self.data_array[0, 0, 0] = "'Tes'"
     ##assert len(self.grid.unredo.undolist) == 2
     
     assert self.data_array[0, 0, 0] == "'Tes'"
     for teststring in v.getstrings(number=100, maxlength=1000):
         x, y, z = [gmpy.rand('next', maxdim) \
                         for maxdim in self.data_array.shape]
         self.data_array[x, y, z] = "".join(["'", teststring, "'"])
         
         assert self.data_array[x, y, z] == "".join(["'", teststring, "'"])
Exemple #4
0
def getstrings(number=1, maxlength = 255):
    """Returns a list of partly random strings
    
    The list starts with the numbers from STRPOOL['mandatory'], continues
    with STRPOOL['extra'] and finishes with random strings.
    
    Parameters
    ----------
    number: int, defaults to RES_LEN (1000)
    \tLength of list
    maxlength: int, defaults to 255
    \tCaps long list lengths
    
    """
    
    def _get_randchar():
        """Returns random 8 bit character"""
        
        character = None
        while character is None or character == '\n':
            character = chr(gmpy.rand('next', 255))
        
        return character
    
    res = STRPOOL['mandatory'][:number]
    while '\n' in res:
        res.remove('\n')
    
    left = number - len(res)
    if left > 0:
        res += STRPOOL['extra'][:left]
    left = number - len(res)
    
    while left > 0:
        stringlength = gmpy.rand('next', maxlength)
        randstring = "".join(_get_randchar() for i in xrange(stringlength))
        res += []
        left -= 1
    
    return res
Exemple #5
0
# (at your option) any later version.
#
# pyspread is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------------------

"""Helper class for unit testing that provides random variables."""

import gmpy

gmpy.rand('seed', 1)

RES_LEN = 1000

INTPOOL = \
    {'mandatory': [0, 1, -1, 2**16, -2**16, 2**32, -2**32, 2**52, -2**52],
     'extra': [2, -2, 2**5000+1, -2**5000-1, 2**15, -2**15, 2**31+1, -2**31-1]}

STRPOOL = \
    {'mandatory': ["", " ", "\t", "\n", "0", "print"],
     'extra': ["a" * 1000]}

def getints(minint = 0, maxint = 1, number=RES_LEN):
    """Returns a list of partly random ints
    
    The list starts with the numbers from INTPOOL['mandatory'], continues with
Exemple #6
0
path.insert(0, "..") 
path.insert(0, "../..") 

import types

import gmpy
import numpy

import wx

app= wx.App()

import _pyspread._interfaces as _interfaces
import vartypes as v

gmpy.rand('seed', 2)


class Test(object):
    """Test of free functions"""
    
   
    def test_sorted_keys(self):
        keys = [(1, 0, 0), (2, 0, 0), (0, 1, 0), (0, 99, 0), (0, 0, 0), 
                (0, 0, 99), (1, 2, 3)]
        assert list(_interfaces.sorted_keys(keys, (0, 1, 0))) == \
             [(0, 1, 0), (0, 99, 0), (1, 2, 3), (0, 0, 99), (0, 0, 0), 
              (1, 0, 0), (2, 0, 0)]
        sk = list(_interfaces.sorted_keys(keys, (0, 3, 0), reverse=True))
        assert sk == [(0, 1, 0), (2, 0, 0), (1, 0, 0), (0, 0, 0), (0, 0, 99), 
              (1, 2, 3), (0, 99, 0)]