コード例 #1
0
def run(kwargs):
    expected = "sanity testmode algorithm".split()
    for expect in expected:
        if expect not in kwargs:
            raise TypeError("Expected argument '%s' not found" % expect)

    arguments = kwargs.pop('sanity')

    if len(kwargs) < len(arguments):
        raise TypeError("Missing Arguements: %s" %
                        ' '.join([a for a in arguments if a not in kwargs]))

    testmode = kwargs['testmode']
    if testmode:
        import contract
        from Genetic import mutation, crossover, fitness, individual, population
        from Genetic.individual import Individual  #@UnusedImport
        contract.checkmod(__name__)
        for mod in [
                crossover, fitness, individual, mutation, population,
                selection, vis
        ]:
            contract.checkmod(mod)

    kwargs.pop('algorithm')(kwargs)
コード例 #2
0
ファイル: GA.py プロジェクト: UmairT/Genetic-Framework
def run(kwargs):
	expected = "sanity testmode algorithm".split()
	for expect in expected:
		if expect not in kwargs:
			raise TypeError("Expected argument '%s' not found" %expect)

	arguments = kwargs.pop('sanity')
	
	if len(kwargs) < len(arguments):
		raise TypeError("Missing Arguements: %s" %' '.join([a for a in arguments if a not in kwargs]))

	testmode = kwargs['testmode']
	if testmode:
		import contract
		from Genetic import mutation, crossover, fitness, individual, population
		from Genetic.individual import Individual #@UnusedImport 
		contract.checkmod(__name__)
		for mod in [crossover, fitness, individual, mutation, population, selection, vis]:
			contract.checkmod(mod)
	
	kwargs.pop('algorithm')(kwargs)
コード例 #3
0
def extract_text(element):
    # for testing
    if type(element) in (list, tuple):
        return u''.join([extract_text(x) for x in element])
    elif isinstance(element, Text):
        return element.text
    else:
        return u''.join([extract_text(x) for i1, i2, x in \
                         element.iter_childs()])
    return u''


if debug:
    #enable contract checking
    import contract
    contract.checkmod(__name__)
    print "enabled contracts"


def test_00():
    "homogenize"
    global debug
    debug = True
    assert str(homogenize([G([T('X')]), T('0'), T('1')])) == \
        "[G([T('X'), T('0'), T('1')])]"


def test_01():
    "is_homogeneous"
    assert not is_homogeneous([G([T('X')]), T('0'), T('1')])
    for x in G([T('X')]), G([T('0'), T('1')]):
コード例 #4
0
ファイル: block_system.py プロジェクト: kyphelps/pynecraft
        
    def grid_to_world(self, v):
        """Convert a grid coordinate vector to the rendering system's coordinates"""
        return v * self.block_size

    # Nat Nat Nat -> Boolean
    def valid_coords(self, x, y, z):
        """Determine if the given world coords are valid.

        pre:
            isinstance(x, int) or isinstance(x, float)
            isinstance(y, int) or isinstance(x, float)
            isinstance(z, int) or isinstance(x, float)
        """
        return (0 <= x < self.size.x and
                0 <= y < self.size.y and
                0 <= z < self.size.z)

    # X, Y, Z [Chunk -> [X Y Z -> 'A]] -> 'A
    def delegate_to_chunk(self, x, y, z, f):
        """Call f on the chunk at coords (x, y, z)

        pre:
            self.valid_coords(x, y, z)
        """
        chunk = self.get_chunk(x, y, z)
        print x, y, z, chunk.x_off, chunk.y_off, chunk.z_off
        return f(chunk)(x - chunk.x_off, y - chunk.y_off, z - chunk.z_off)

contract.checkmod(__name__)
コード例 #5
0
ファイル: testdbc6.py プロジェクト: TahaS10/m1s2
def _test():
    import contract, doctest, testdbc6

    contract.checkmod(testdbc6)
    return doctest.testmod(testdbc6)
コード例 #6
0
ファイル: testdbc7.py プロジェクト: dtbinh/m1s2-1
def _test():
    import contract, doctest, testdbc7
    contract.checkmod(testdbc7)
    return doctest.testmod(testdbc7)
コード例 #7
0
def _test():
    import contract, doctest, testdbc1
    contract.checkmod(testdbc1, contract.CHECK_ALL)
    return doctest.testmod(testdbc1)
コード例 #8
0
ファイル: tester.py プロジェクト: Zildj1an/cassopi
if __name__ == '__main__':
    from sys import argv

    print 'Running tests.'

    print 'Importing given module'
    try:
        module = my_import(argv[1])
    except Exception, e:
        print 'Error while trying to import given module.'
        print e
        quit()

    print 'Checking contracts'
    try:
        import contract
        contract.checkmod(module)
    except Exception, e:
        print 'Error while trying to check contracts!'
        print e

    print 'Checking doctests'
    import doctest
    doctest.testmod(module)

    # add coverage test here

    # unit tests?

    print 'Tests finished.'
コード例 #9
0
ファイル: testdbc4.py プロジェクト: TahaS10/m1s2
def _test():
    import contract, doctest, testdbc4
    contract.checkmod(testdbc4, contract.CHECK_PRECONDITIONS)
    return doctest.testmod(testdbc4)