Beispiel #1
0
    def test_iter_adjacencies(self):
        def onedim_lattice(n, max_size):
            return [
                neighbour for neighbour in [n - 1, n + 1]
                if abs(neighbour) <= max_size
            ]

        # starting at 0, we’ll get all 21 points:
        adjs0 = list(iter_adjacencies([0], lambda n: onedim_lattice(n, 10)))
        self.assertEqual(21, len(adjs0))
        self.assertCountEqual(range(-10, 11), dict(adjs0).keys())

        # starting at 11, we’ll get 22 points
        adjs1 = list(iter_adjacencies([11], lambda n: onedim_lattice(n, 10)))
        self.assertEqual(22, len(adjs1))
        self.assertCountEqual(range(-10, 12), dict(adjs1).keys())

        # starting at 12, we’ll get 1 point
        adjs2 = list(iter_adjacencies([12], lambda n: onedim_lattice(n, 10)))
        self.assertEqual(1, len(adjs2))
        self.assertEqual([(12, [])], list(adjs2))

        # starting at [0, 12], we’ll get adjs0 | adjs2
        adjs3 = list(iter_adjacencies([0, 12],
                                      lambda n: onedim_lattice(n, 10)))
        self.assertEqual(22, len(adjs3))
        self.assertCountEqual(adjs0 + adjs2, adjs3)
Beispiel #2
0
    def test_iter_adjacencies(self):
        def onedim_lattice(n, max_size):
            return [neighbour for neighbour in [n - 1, n + 1] if abs(neighbour) <= max_size]

        # starting at 0, we’ll get all 21 points:
        adjs0 = list(iter_adjacencies([0], lambda n: onedim_lattice(n, 10)))
        assert 21 == len(adjs0)
        unittest.TestCase().assertCountEqual(range(-10, 11), dict(adjs0).keys())

        # starting at 11, we’ll get 22 points
        adjs1 = list(iter_adjacencies([11], lambda n: onedim_lattice(n, 10)))
        assert 22 == len(adjs1)
        unittest.TestCase().assertCountEqual(range(-10, 12), dict(adjs1).keys())

        # starting at 12, we’ll get 1 point
        adjs2 = list(iter_adjacencies([12], lambda n: onedim_lattice(n, 10)))
        assert 1 == len(adjs2)
        assert [(12, [])] == list(adjs2)

        # starting at [0, 12], we’ll get adjs0 | adjs2
        adjs3 = list(iter_adjacencies([0, 12], lambda n: onedim_lattice(n, 10)))
        assert 22 == len(adjs3)
        unittest.TestCase().assertCountEqual(adjs0 + adjs2, adjs3)
Beispiel #3
0
    def test_iter_adjacencies(self):
        def onedim_lattice(n, max_size):
            return [neighbour for neighbour in [n - 1, n + 1] if abs(neighbour) <= max_size]

        # starting at 0, we’ll get all 21 points:
        adjs0 = list(iter_adjacencies([0], lambda n: onedim_lattice(n, 10)))
        self.assertEqual(21, len(adjs0))
        self.assertEqual(set(range(-10, 11)), set(dict(adjs0).keys()))

        # starting at 11, we’ll get 22 points
        adjs1 = list(iter_adjacencies([11], lambda n: onedim_lattice(n, 10)))
        self.assertEqual(22, len(adjs1))
        self.assertEqual(set(range(-10, 12)), set(dict(adjs1).keys()))

        # starting at 12, we’ll get 1 point
        adjs2 = list(iter_adjacencies([12], lambda n: onedim_lattice(n, 10)))
        self.assertEqual(1, len(adjs2))
        self.assertEqual([(12, [])], list(adjs2))

        # starting at [0, 12], we’ll get adjs0 | adjs2
        adjs3 = list(iter_adjacencies([0, 12], lambda n: onedim_lattice(n, 10)))
        self.assertEqual(22, len(adjs3))
        self.assertEqual(sorted(adjs0 + adjs2), sorted(adjs3))