Ejemplo n.º 1
0
class ChunkGeneratorTest( TestCase ):
	''' '''

	def setUp( self ):
		''' '''
		self.fileObj = FileObjectMock()
		self.position = Vec3( 0, 0, 0 )

		self.encoder = EncoderSetup.create()
		self.playerFactory = PlayerFactorySetup.create()
		self.blockTypeFactory = BlockTypeFactorySetup.create()
		self.chunkSize = 16

		self.generator = ChunkGeneratorSetup.create( encoder = self.encoder
				, playerFactory = self.playerFactory
				, blockTypeFactory = self.blockTypeFactory
				, chunkSize = self.chunkSize
				)
		return None

	def it_should_generate_properly( self ):
		''' '''
		self.assertIsNone( self.generator.generate(self.fileObj, self.position) )

		world = self.playerFactory.fromName( '__WORLD__' )
		air = self.blockTypeFactory.fromName( 'air' ).newBlock( world )
		string = self.encoder.encodeBlock( air ) * ( self.chunkSize ** 3 )

		self.fileObj.open()
		self.fileObj.seek( 0 )

		self.assertEqual( self.fileObj.read(), string )

		self.fileObj.close()
		return None
Ejemplo n.º 2
0
class Generating( TestCase ):
	''' '''

	def setUp(self):
		''' '''
		self.chunkSize = 16
		self.playerFactory = PlayerFactorySetup.create()
		self.blockTypeFactory = BlockTypeFactorySetup.create()

		self.encoder = EncoderSetup.create( blockTypeFactory = self.blockTypeFactory
				, playerFactory = self.playerFactory
				)
		self.generator = ChunkGeneratorSetup.create( chunkSize = self.chunkSize
				, playerFactory = self.playerFactory
				, blockTypeFactory = self.blockTypeFactory
				)
		self.position = Vec3( 0, 0, 0 )
		self.fileObj = FileObjectMock()

		self.chunk = ChunkSetup.create( fileObj = self.fileObj, encoder = self.encoder
				, generator = self.generator, chunkSize = self.chunkSize
				, position = self.position
				)
		return None

	def it_should_create_a_chunk(self):
		''' '''
		self.fileObj.setExists( False )
		node = NodePath()

		self.assertIsNone( self.chunk.load(node) )

		self.fileObj.open()
		self.fileObj.seek(0)
		blockLength = self.encoder.size()
		nrOfBlocks = self.chunkSize ** 3

		# check if something is wrinten to the file, and that it make some sence.
		self.assertEqual( len(self.fileObj.read()), blockLength * nrOfBlocks )

		self.fileObj.close() 
		return None
Ejemplo n.º 3
0
	def setUp( self ):
		''' '''
		self.fileObj = FileObjectMock()
		self.position = Vec3( 0, 0, 0 )

		self.encoder = EncoderSetup.create()
		self.playerFactory = PlayerFactorySetup.create()
		self.blockTypeFactory = BlockTypeFactorySetup.create()
		self.chunkSize = 16

		self.generator = ChunkGeneratorSetup.create( encoder = self.encoder
				, playerFactory = self.playerFactory
				, blockTypeFactory = self.blockTypeFactory
				, chunkSize = self.chunkSize
				)
		return None