Exemplo n.º 1
0
 def test_eq_should_return_false_if_is_border_property_is_not_equal(self):
     point_a = EarthPoint(x=1,
                          y=5,
                          altitude=102,
                          stratum=5,
                          is_border=False)
     point_b = EarthPoint(x=1, y=5, altitude=102, stratum=5, is_border=True)
     self.assertNotEqual(point_a, point_b)
Exemplo n.º 2
0
 def test_str_should_return_altitude_space_par_stratum_star_if_border(self):
     point_a = EarthPoint(x=1,
                          y=5,
                          altitude=102,
                          stratum=5,
                          is_border=False)
     point_b = EarthPoint(x=1, y=5, altitude=2, stratum=10, is_border=True)
     self.assertEqual("102 ( 5) ", str(point_a))
     self.assertEqual(" 2 (10)*", str(point_b))
Exemplo n.º 3
0
 def test_is_minimum_should_return_false_if_altitude_is_greaterthan_any_neighbors(
         self):
     with mock.patch('earthmatrix.EarthMatrix._get_neighbors',
                     side_effect=([
                         EarthPoint(0, 0, 1),
                         EarthPoint(0, 1, 0),
                         EarthPoint(0, 2, 1)
                     ], )):
         pmap = EarthMatrix([[]])
         self.assertFalse(pmap._is_minimum(EarthPoint(0, 0, 1)))
Exemplo n.º 4
0
 def test_is_minimum_should_return_true_if_altitude_is_lessequal_to_neighborss(
         self):
     with mock.patch('earthmatrix.EarthMatrix._get_neighbors',
                     side_effect=([
                         EarthPoint(0, 0, 1),
                         EarthPoint(0, 1, 2),
                         EarthPoint(0, 2, 3)
                     ], )):
         pmap = EarthMatrix([[]])
         self.assertTrue(pmap._is_minimum(EarthPoint(0, 0, 1)))
Exemplo n.º 5
0
 def test_eq_should_return_true_if_all_properties_are_equal(self):
     point_a = EarthPoint(x=1,
                          y=5,
                          altitude=102,
                          stratum=5,
                          is_border=False)
     point_b = EarthPoint(x=1,
                          y=5,
                          altitude=102,
                          stratum=5,
                          is_border=False)
     self.assertEqual(point_a, point_b)
Exemplo n.º 6
0
 def test_getitem_should_return_points(self):
     pmap = EarthMatrix([[5, 4, 3], [1, 2, 6], [7, 9, 0]])
     self.assertEqual(EarthPoint(0, 0, 5), pmap[0, 0])
     self.assertEqual(EarthPoint(0, 1, 4), pmap[0, 1])
     self.assertEqual(EarthPoint(0, 2, 3), pmap[0, 2])
     self.assertEqual(EarthPoint(1, 0, 1), pmap[1, 0])
     self.assertEqual(EarthPoint(1, 1, 2), pmap[1, 1])
     self.assertEqual(EarthPoint(1, 2, 6), pmap[1, 2])
     self.assertEqual(EarthPoint(2, 0, 7), pmap[2, 0])
     self.assertEqual(EarthPoint(2, 1, 9), pmap[2, 1])
     self.assertEqual(EarthPoint(2, 2, 0), pmap[2, 2])
Exemplo n.º 7
0
 def test_transmit_stratum_to_neighbors_should_only_transmit_if_no_stratum(
         self):
     neighbor_1 = EarthPoint(0, 0, 5)
     neighbor_2 = EarthPoint(0, 2, 6, stratum=5)
     neighbor_3 = EarthPoint(1, 1, 7)
     with mock.patch('earthmatrix.EarthMatrix._get_neighbors',
                     side_effect=([neighbor_1, neighbor_2,
                                   neighbor_3], [], [], [])):
         pmap = EarthMatrix([[]])
         pmap._strata.extend([[], [], []])
         pmap._transmit_stratum_to_neighbors(EarthPoint(0, 1, 6, stratum=2))
     self.assertEqual(neighbor_1.stratum, None)
     self.assertEqual(neighbor_2.stratum, 5)
     self.assertEqual(neighbor_3.stratum, None)
     self.assertEqual([], pmap._strata[2])
Exemplo n.º 8
0
 def test_parse_points_should_codify_altitudes_using_points(self):
     points = EarthMatrix._parse_points([
         [5, 4, 3],
         [1, 2, 6],
         [7, 9, 0],
     ])
     self.assertEqual(3, len(points))
     self.assertEqual(3, len(points[0]))
     self.assertEqual(3, len(points[1]))
     self.assertEqual(3, len(points[2]))
     self.assertEqual(EarthPoint(0, 0, 5), points[0][0])
     self.assertEqual(EarthPoint(0, 1, 4), points[0][1])
     self.assertEqual(EarthPoint(0, 2, 3), points[0][2])
     self.assertEqual(EarthPoint(1, 0, 1), points[1][0])
     self.assertEqual(EarthPoint(1, 1, 2), points[1][1])
     self.assertEqual(EarthPoint(1, 2, 6), points[1][2])
     self.assertEqual(EarthPoint(2, 0, 7), points[2][0])
     self.assertEqual(EarthPoint(2, 1, 9), points[2][1])
     self.assertEqual(EarthPoint(2, 2, 0), points[2][2])
Exemplo n.º 9
0
 def test_delta_should_return_2_element_tuple(self):
     point = EarthPoint(x=1, y=2, altitude=5)
     self.assertEqual(tuple, type(point.delta(0, 0)))
     self.assertEqual(2, len(point.delta(0, 0)))
Exemplo n.º 10
0
 def test_delta_should_apply_nil_increase_to_y(self):
     point = EarthPoint(x=1, y=2, altitude=5)
     delta = point.delta(0, 0)
     self.assertEqual(2, delta[1])
Exemplo n.º 11
0
 def test_delta_should_apply_negative_increase_to_y(self):
     point = EarthPoint(x=1, y=2, altitude=5)
     delta = point.delta(5, -3)
     self.assertEqual(2 - 3, delta[1])
Exemplo n.º 12
0
 def test_delta_should_apply_negative_increase_to_x(self):
     point = EarthPoint(x=1, y=2, altitude=5)
     delta = point.delta(-5, 2)
     self.assertEqual(1 - 5, delta[0])
Exemplo n.º 13
0
 def test_get_neighbors_should_return_only_points_with_valid_coordinates(
         self):
     pmap = EarthMatrix([[5, 4, 3], [1, 2, 6], [7, 9, 0]])
     self.assertEqual(
         [EarthPoint(0, 1, 4), EarthPoint(1, 0, 1)],
         pmap._get_neighbors(pmap[0, 0]))
     self.assertEqual(
         [EarthPoint(0, 0, 5),
          EarthPoint(0, 2, 3),
          EarthPoint(1, 1, 2)], pmap._get_neighbors(pmap[0, 1]))
     self.assertEqual(
         [EarthPoint(0, 1, 4), EarthPoint(1, 2, 6)],
         pmap._get_neighbors(pmap[0, 2]))
     self.assertEqual(
         [EarthPoint(0, 0, 5),
          EarthPoint(1, 1, 2),
          EarthPoint(2, 0, 7)], pmap._get_neighbors(pmap[1, 0]))
     self.assertEqual([
         EarthPoint(1, 0, 1),
         EarthPoint(0, 1, 4),
         EarthPoint(1, 2, 6),
         EarthPoint(2, 1, 9)
     ], pmap._get_neighbors(pmap[1, 1]))
     self.assertEqual(
         [EarthPoint(1, 1, 2),
          EarthPoint(0, 2, 3),
          EarthPoint(2, 2, 0)], pmap._get_neighbors(pmap[1, 2]))
     self.assertEqual(
         [EarthPoint(1, 0, 1), EarthPoint(2, 1, 9)],
         pmap._get_neighbors(pmap[2, 0]))
     self.assertEqual(
         [EarthPoint(2, 0, 7),
          EarthPoint(1, 1, 2),
          EarthPoint(2, 2, 0)], pmap._get_neighbors(pmap[2, 1]))
     self.assertEqual(
         [EarthPoint(2, 1, 9), EarthPoint(1, 2, 6)],
         pmap._get_neighbors(pmap[2, 2]))
Exemplo n.º 14
0
 def test_init_stratum_should_append_point_to_strata_group(self):
     pmap = EarthMatrix([[]])
     pmap._strata = [['strata_group_0'], ['strata_group_1']]
     point = EarthPoint(1, 5, 15)
     pmap._init_stratum(point)
     self.assertEqual([point], pmap._strata[2])
Exemplo n.º 15
0
 def test_init_stratum_should_assign_next_free_strata_group(self):
     pmap = EarthMatrix([[]])
     pmap._strata = [['strata_group_0'], ['strata_group_1']]
     point = EarthPoint(1, 5, 15)
     pmap._init_stratum(point)
     self.assertEqual(2, point.stratum)