import unittest
from worldengine.plates import Step, center_land, world_gen
from worldengine.world import World

from tests.draw_test import TestBase


class TestGeneration(TestBase):

    def setUp(self):
        super(TestGeneration, self).setUp()

    def test_world_gen_does_not_explode_badly(self):
        # FIXME remove me when proper tests are in place
        # Very stupid test that just verify nothing explode badly
        world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))

    @staticmethod
    def _mean_elevation_at_borders(world):
        borders_total_elevation = 0.0
        for y in range(world.height):
            borders_total_elevation += world.elevation_at((0, y))
            borders_total_elevation += world.elevation_at((world.width - 1, y))
        for x in range(1, world.width - 1):
            borders_total_elevation += world.elevation_at((x, 0))
            borders_total_elevation += world.elevation_at((x, world.height - 1))

        n_cells_on_border = world.width * 2 + world.height * 2 - 4
        return borders_total_elevation / n_cells_on_border

    def test_center_land(self):
        w = World.from_pickle_file("%s/plates_279.world" % self.tests_data_dir)

        # We want to have less land than before at the borders
        el_before = TestGeneration._mean_elevation_at_borders(w)
        center_land(w)
        el_after = TestGeneration._mean_elevation_at_borders(w)
        self.assertTrue(el_after <= el_before)


if __name__ == '__main__':
    unittest.main()

[((42, 4, 42, 19), 'unittest.main', 'unittest.main', ({}, {}), '()', False, 'import unittest\n'), ((32, 12, 32, 79), 'worldengine.world.World.from_pickle_file', 'World.from_pickle_file', ({(32, 35, 32, 78): "'%s/plates_279.world' % self.tests_data_dir"}, {}), "('%s/plates_279.world' % self.tests_data_dir)", False, 'from worldengine.world import World\n'), ((36, 8, 36, 22), 'worldengine.plates.center_land', 'center_land', ({(36, 20, 36, 21): 'w'}, {}), '(w)', False, 'from worldengine.plates import Step, center_land, world_gen\n'), ((16, 43, 16, 67), 'worldengine.plates.Step.get_by_name', 'Step.get_by_name', ({(16, 60, 16, 66): '"""full"""'}, {}), "('full')", False, 'from worldengine.plates import Step, center_land, world_gen\n')]