Exemplo n.º 1
0
    def __eq__(self, other):
        if isinstance(other, self.__class__):

            return _equal(self.data, other.data) and _equal(
                self.quantiles, other.quantiles)
        else:
            return False
Exemplo n.º 2
0
    def __eq__(self, other):
        if isinstance(other, self.__class__):

            return _equal(self.data, other.data) and _equal(
                self.thresholds, other.thresholds)
        else:
            return False
Exemplo n.º 3
0
    def test_dictionary_equality(self):
        a = {}
        b = {}

        a['foo'] = 'bar'

        self.assertFalse(_equal(a, b))

        b['foo'] = 'bar'

        self.assertTrue(_equal(a, b))
Exemplo n.º 4
0
    def test_dictionary_equality(self):
        a = {}
        b = {}

        a['foo'] = 'bar'

        self.assertFalse(_equal(a,b))

        b['foo'] = 'bar'

        self.assertTrue(_equal(a,b))
Exemplo n.º 5
0
 def test_hdf5_serialize_unserialize(self):
     filename = None
     try:
         w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
         f = tempfile.NamedTemporaryFile(delete=False)
         f.close()
         filename = f.name
         serialized = save_world_to_hdf5(w, filename)
         unserialized = load_world_to_hdf5(filename)
         self.assertEqual(Set(w.layers.keys()),
                          Set(unserialized.layers.keys()))
         self.assertEqual(w.layers['humidity'].quantiles,
                          unserialized.layers['humidity'].quantiles)
         for l in w.layers.keys():
             self.assertEqual(w.layers[l], unserialized.layers[l],
                              "Comparing %s" % l)
         self.assertTrue(_equal(w.ocean_level, unserialized.ocean_level))
         self.assertEquals(w.seed, unserialized.seed)
         self.assertEquals(w.n_plates, unserialized.n_plates)
         self.assertEquals(w.step, unserialized.step)
         self.assertEqual(sorted(dir(w)), sorted(dir(unserialized)))
         #self.assertEqual(w, unserialized)
     finally:
         if filename:
             os.remove(filename)
Exemplo n.º 6
0
 def test_protobuf_serialize_unserialize(self):
     w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
     serialized = w.protobuf_serialize()
     unserialized = World.protobuf_unserialize(serialized)
     self.assertEqual(set(w.layers.keys()), set(unserialized.layers.keys()))
     for l in w.layers.keys():
         self.assertEqual(w.layers[l], unserialized.layers[l], "Comparing %s" % l)
     self.assertTrue(_equal(w.ocean_level,       unserialized.ocean_level))
     self.assertEquals(w.seed,                   unserialized.seed)
     self.assertEquals(w.n_plates,               unserialized.n_plates)
     self.assertEquals(w.step,                   unserialized.step)
     self.assertEqual(sorted(dir(w)),            sorted(dir(unserialized)))
     self.assertEqual(w, unserialized)
Exemplo n.º 7
0
 def test_traversal(self):
     test_map = numpy.zeros((20, 20))
     line = numpy.array(20)
     line.fill(1.0)
     test_map[10, :] = line
     test_map[10, 18] = 0.0
     path_data = numpy.array([[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9],
                              [1, 9], [2, 9], [3, 9], [4, 9], [5, 9], [6, 9], [7, 9], [8, 9], [9, 9],
                              [10, 9], [11, 9], [12, 9], [13, 9], [14, 9], [15, 9], [16, 9], [17, 9],
                              [18, 9], [18, 10], [18, 11], [18, 12], [18, 13], [18, 14], [18, 15],
                              [18, 16], [18, 17], [18, 18], [18, 19], [19, 19]])
     shortest_path = astar.PathFinder().find(test_map, [0, 0], [19, 19])
     self.assertTrue(_equal(path_data, numpy.array(shortest_path)))
Exemplo n.º 8
0
 def test_protobuf_serialize_unserialize(self):
     w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
     serialized = w.protobuf_serialize()
     unserialized = World.protobuf_unserialize(serialized)
     self.assertEqual(Set(w.layers.keys()), Set(unserialized.layers.keys()))
     for l in w.layers.keys():
         self.assertEqual(w.layers[l], unserialized.layers[l],
                          "Comparing %s" % l)
     self.assertTrue(_equal(w.ocean_level, unserialized.ocean_level))
     self.assertEquals(w.seed, unserialized.seed)
     self.assertEquals(w.n_plates, unserialized.n_plates)
     self.assertEquals(w.step, unserialized.step)
     self.assertEqual(sorted(dir(w)), sorted(dir(unserialized)))
     self.assertEqual(w, unserialized)
Exemplo n.º 9
0
 def test_traversal(self):
     test_map = numpy.zeros((20, 20))
     line = numpy.array(20)
     line.fill(1.0)
     test_map[10, :] = line
     test_map[10, 18] = 0.0
     path_data = numpy.array([[0, 1], [0, 2], [0, 3], [0, 4], [0,
                                                               5], [0, 6],
                              [0, 7], [0, 8], [0, 9], [1, 9], [2,
                                                               9], [3, 9],
                              [4, 9], [5, 9], [6, 9], [7, 9], [8, 9],
                              [9, 9], [10, 9], [11, 9], [12, 9], [13, 9],
                              [14, 9], [15, 9], [16, 9], [17, 9], [18, 9],
                              [18, 10], [18, 11], [18, 12], [18, 13],
                              [18, 14], [18, 15], [18, 16], [18, 17],
                              [18, 18], [18, 19], [19, 19]])
     shortest_path = astar.PathFinder().find(test_map, [0, 0], [19, 19])
     self.assertTrue(_equal(path_data, numpy.array(shortest_path)))
Exemplo n.º 10
0
 def test_hdf5_serialize_unserialize(self):
     filename = None
     try:
         w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
         f = tempfile.NamedTemporaryFile(delete=False)
         f.close()
         filename = f.name
         serialized = save_world_to_hdf5(w, filename)
         unserialized = load_world_to_hdf5(filename)
         self.assertEqual(set(w.layers.keys()), set(unserialized.layers.keys()))
         self.assertEqual(w.layers['humidity'].quantiles, unserialized.layers['humidity'].quantiles)
         for l in w.layers.keys():
             self.assertEqual(w.layers[l], unserialized.layers[l], "Comparing %s" % l)
         self.assertTrue(_equal(w.ocean_level,       unserialized.ocean_level))
         self.assertEquals(w.seed,                   unserialized.seed)
         self.assertEquals(w.n_plates,               unserialized.n_plates)
         self.assertEquals(w.step,                   unserialized.step)
         self.assertEqual(sorted(dir(w)),            sorted(dir(unserialized)))
         #self.assertEqual(w, unserialized)
     finally:
         if filename:
             os.remove(filename)
Exemplo n.º 11
0
 def __eq__(self, other):
     return _equal(self.__dict__, other.__dict__)
Exemplo n.º 12
0
    def __eq__(self, other):
        if isinstance(other, self.__class__):

            return _equal(self.data, other.data) and _equal(self.quantiles, other.quantiles)
        else:
            return False
Exemplo n.º 13
0
    def __eq__(self, other):
        if isinstance(other, self.__class__):

            return _equal(self.data, other.data) and _equal(self.thresholds, other.thresholds)
        else:
            return False
Exemplo n.º 14
0
 def test_pickle_serialize_unserialize(self):
     w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
     f = tempfile.NamedTemporaryFile(delete=False).name
     w.to_pickle_file(f)
     unserialized = World.from_pickle_file(f)
     os.remove(f)
     self.assertTrue(_equal(w.elevation['data'], unserialized.elevation['data']))
     self.assertEqual(w.elevation['thresholds'], unserialized.elevation['thresholds'])
     self.assertTrue(_equal(w.ocean,             unserialized.ocean))
     self.assertTrue(_equal(w.biome,             unserialized.biome))
     self.assertTrue(_equal(w.humidity,          unserialized.humidity))
     self.assertTrue(_equal(w.irrigation,        unserialized.irrigation))
     self.assertTrue(_equal(w.permeability,      unserialized.permeability))
     self.assertTrue(_equal(w.watermap,          unserialized.watermap))
     self.assertTrue(_equal(w.precipitation,     unserialized.precipitation))
     self.assertTrue(_equal(w.temperature,       unserialized.temperature))
     self.assertTrue(_equal(w.sea_depth,         unserialized.sea_depth))
     self.assertEquals(w.seed,                   unserialized.seed)
     self.assertEquals(w.n_plates,               unserialized.n_plates)
     self.assertTrue(_equal(w.ocean_level,       unserialized.ocean_level))
     self.assertTrue(_equal(w.lake_map,          unserialized.lake_map))
     self.assertTrue(_equal(w.river_map,         unserialized.river_map))
     self.assertEquals(w.step,                   unserialized.step)
     self.assertEqual(sorted(dir(w)),            sorted(dir(unserialized)))
     self.assertEqual(w, unserialized)
Exemplo n.º 15
0
 def test_protobuf_serialize_unserialize(self):
     w = world_gen("Dummy",
                   32,
                   16,
                   1, [.874, .765, .594, .439, .366, .124],
                   [.941, .778, .507, .236, 0.073, .014, .002],
                   step=Step.get_by_name("full"))
     serialized = w.protobuf_serialize()
     unserialized = World.protobuf_unserialize(serialized)
     self.assertTrue(
         _equal(w.elevation['data'], unserialized.elevation['data']))
     self.assertEqual(w.elevation['thresholds'],
                      unserialized.elevation['thresholds'])
     self.assertTrue(_equal(w.ocean, unserialized.ocean))
     self.assertTrue(_equal(w.biome, unserialized.biome))
     self.assertTrue(_equal(w.humidity, unserialized.humidity))
     self.assertTrue(_equal(w.irrigation, unserialized.irrigation))
     self.assertTrue(_equal(w.permeability, unserialized.permeability))
     self.assertTrue(_equal(w.watermap, unserialized.watermap))
     self.assertTrue(_equal(w.precipitation, unserialized.precipitation))
     self.assertTrue(_equal(w.temperature, unserialized.temperature))
     self.assertTrue(_equal(w.sea_depth, unserialized.sea_depth))
     self.assertEquals(w.seed, unserialized.seed)
     self.assertEquals(w.n_plates, unserialized.n_plates)
     self.assertTrue(_equal(w.ocean_level, unserialized.ocean_level))
     self.assertTrue(_equal(w.lake_map, unserialized.lake_map))
     self.assertTrue(_equal(w.river_map, unserialized.river_map))
     self.assertEquals(w.step, unserialized.step)
     self.assertEqual(sorted(dir(w)), sorted(dir(unserialized)))
     self.assertEqual(w, unserialized)
Exemplo n.º 16
0
 def test_hdf5_serialize_unserialize(self):
     filename = None
     try:
         w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
         f = tempfile.NamedTemporaryFile(delete=False)
         f.close()
         filename = f.name
         serialized = save_world_to_hdf5(w, filename)
         unserialized = load_world_to_hdf5(filename)
         self.assertTrue(_equal(w.elevation['data'], unserialized.elevation['data']))
         self.assertEqual(w.elevation['thresholds'], unserialized.elevation['thresholds'])
         self.assertTrue(_equal(w.ocean,             unserialized.ocean))
         self.assertTrue(_equal(w.biome,             unserialized.biome))
         self.assertTrue(_equal(w.humidity['quantiles'], unserialized.humidity['quantiles']))
         self.assertTrue(_equal(w.humidity['data'],  unserialized.humidity['data']))
         self.assertTrue(_equal(w.humidity,          unserialized.humidity))
         self.assertTrue(_equal(w.irrigation,        unserialized.irrigation))
         self.assertTrue(_equal(w.permeability,      unserialized.permeability))
         self.assertTrue(_equal(w.watermap,          unserialized.watermap))
         self.assertTrue(_equal(w.precipitation['thresholds'], unserialized.precipitation['thresholds']))
         self.assertTrue(_equal(w.precipitation['data'], unserialized.precipitation['data']))
         self.assertTrue(_equal(w.precipitation,     unserialized.precipitation))
         self.assertTrue(_equal(w.temperature,       unserialized.temperature))
         self.assertTrue(_equal(w.sea_depth,         unserialized.sea_depth))
         self.assertTrue(_equal(w.ocean_level,       unserialized.ocean_level))
         self.assertTrue(_equal(w.lake_map,          unserialized.lake_map))
         self.assertTrue(_equal(w.river_map,         unserialized.river_map))
         self.assertTrue(_equal(w.icecap,            unserialized.icecap))
         self.assertEquals(w.seed,                   unserialized.seed)
         self.assertEquals(w.n_plates,               unserialized.n_plates)
         self.assertEquals(w.step,                   unserialized.step)
         self.assertEqual(sorted(dir(w)),            sorted(dir(unserialized)))
         #self.assertEqual(w, unserialized)
     finally:
         if filename:
             os.remove(filename)
Exemplo n.º 17
0
 def test_protobuf_serialize_unserialize(self):
     w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
     serialized = w.protobuf_serialize()
     unserialized = World.protobuf_unserialize(serialized)
     self.assertTrue(_equal(w.elevation['data'], unserialized.elevation['data']))
     self.assertEqual(w.elevation['thresholds'], unserialized.elevation['thresholds'])
     self.assertTrue(_equal(w.ocean,             unserialized.ocean))
     self.assertTrue(_equal(w.biome,             unserialized.biome))
     self.assertTrue(_equal(w.humidity,          unserialized.humidity))
     self.assertTrue(_equal(w.irrigation,        unserialized.irrigation))
     self.assertTrue(_equal(w.permeability,      unserialized.permeability))
     self.assertTrue(_equal(w.watermap,          unserialized.watermap))
     self.assertTrue(_equal(w.precipitation,     unserialized.precipitation))
     self.assertTrue(_equal(w.temperature,       unserialized.temperature))
     self.assertTrue(_equal(w.sea_depth,         unserialized.sea_depth))
     self.assertTrue(_equal(w.ocean_level,       unserialized.ocean_level))
     self.assertTrue(_equal(w.lake_map,          unserialized.lake_map))
     self.assertTrue(_equal(w.river_map,         unserialized.river_map))
     self.assertTrue(_equal(w.icecap,            unserialized.icecap))
     self.assertEquals(w.seed,                   unserialized.seed)
     self.assertEquals(w.n_plates,               unserialized.n_plates)
     self.assertEquals(w.step,                   unserialized.step)
     self.assertEqual(sorted(dir(w)),            sorted(dir(unserialized)))
     self.assertEqual(w, unserialized)
Exemplo n.º 18
0
 def test_pickle_serialize_unserialize(self):
     w = world_gen("Dummy", 32, 16, 1, [.874, .765, .594, .439, .366, .124], [.941, .778, .507, .236, 0.073, .014, .002], step=Step.get_by_name("full"))
     f = tempfile.NamedTemporaryFile(delete=False).name
     w.to_pickle_file(f)
     unserialized = World.from_pickle_file(f)
     os.remove(f)
     self.assertTrue(_equal(w.elevation['data'], unserialized.elevation['data']))
     self.assertEqual(w.elevation['thresholds'], unserialized.elevation['thresholds'])
     self.assertTrue(_equal(w.ocean,             unserialized.ocean))
     self.assertTrue(_equal(w.biome,             unserialized.biome))
     self.assertTrue(_equal(w.humidity,          unserialized.humidity))
     self.assertTrue(_equal(w.irrigation,        unserialized.irrigation))
     self.assertTrue(_equal(w.permeability,      unserialized.permeability))
     self.assertTrue(_equal(w.watermap,          unserialized.watermap))
     self.assertTrue(_equal(w.precipitation,     unserialized.precipitation))
     self.assertTrue(_equal(w.temperature,       unserialized.temperature))
     self.assertTrue(_equal(w.sea_depth,         unserialized.sea_depth))
     self.assertEquals(w.seed,                   unserialized.seed)
     self.assertEquals(w.n_plates,               unserialized.n_plates)
     self.assertTrue(_equal(w.ocean_level,       unserialized.ocean_level))
     self.assertTrue(_equal(w.lake_map,          unserialized.lake_map))
     self.assertTrue(_equal(w.river_map,         unserialized.river_map))
     self.assertEquals(w.step,                   unserialized.step)
     self.assertEqual(sorted(dir(w)),            sorted(dir(unserialized)))
     self.assertEqual(w, unserialized)
Exemplo n.º 19
0
 def __eq__(self, other):
     return _equal(self.__dict__, other.__dict__)
Exemplo n.º 20
0
 def test_hdf5_serialize_unserialize(self):
     filename = None
     try:
         w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full"))
         f = tempfile.NamedTemporaryFile(delete=False)
         f.close()
         filename = f.name
         serialized = save_world_to_hdf5(w, filename)
         unserialized = load_world_to_hdf5(filename)
         self.assertTrue(
             _equal(w.elevation['data'], unserialized.elevation['data']))
         self.assertEqual(w.elevation['thresholds'],
                          unserialized.elevation['thresholds'])
         self.assertTrue(_equal(w.plates, unserialized.plates))
         self.assertTrue(_equal(w.ocean, unserialized.ocean))
         self.assertTrue(_equal(w.biome, unserialized.biome))
         self.assertTrue(
             _equal(w.humidity['quantiles'],
                    unserialized.humidity['quantiles']))
         self.assertTrue(
             _equal(w.humidity['data'], unserialized.humidity['data']))
         self.assertTrue(_equal(w.humidity, unserialized.humidity))
         self.assertTrue(_equal(w.irrigation, unserialized.irrigation))
         self.assertTrue(_equal(w.permeability, unserialized.permeability))
         self.assertTrue(_equal(w.watermap, unserialized.watermap))
         self.assertTrue(
             _equal(w.precipitation['thresholds'],
                    unserialized.precipitation['thresholds']))
         self.assertTrue(
             _equal(w.precipitation['data'],
                    unserialized.precipitation['data']))
         self.assertTrue(_equal(w.precipitation,
                                unserialized.precipitation))
         self.assertTrue(_equal(w.temperature, unserialized.temperature))
         self.assertTrue(_equal(w.sea_depth, unserialized.sea_depth))
         self.assertTrue(_equal(w.ocean_level, unserialized.ocean_level))
         self.assertTrue(_equal(w.lake_map, unserialized.lake_map))
         self.assertTrue(_equal(w.river_map, unserialized.river_map))
         self.assertTrue(_equal(w.icecap, unserialized.icecap))
         self.assertEquals(w.seed, unserialized.seed)
         self.assertEquals(w.n_plates, unserialized.n_plates)
         self.assertEquals(w.step, unserialized.step)
         self.assertEqual(sorted(dir(w)), sorted(dir(unserialized)))
         #self.assertEqual(w, unserialized)
     finally:
         if filename:
             os.remove(filename)