Exemple #1
0
    def test_mxed_elements_diamond(self):
        a = [Foo | Bar, Foo, Bar | Baz | Foo, Baz | Foo]

        r = util.sorted_poset(a)

        self.assertEqual(r[0], Foo)
        self.assertEqual(r[-1], Bar | Baz | Foo)
Exemple #2
0
    def test_already_sorted_incomparable(self):
        a = [Foo, Bar, Baz]

        r = util.sorted_poset(a)

        # Incomparable elements, so as long as they
        # are present, any order is valid.
        self.assertEqual(len(r), 3)
        self.assertIn(Foo, r)
        self.assertIn(Bar, r)
        self.assertIn(Baz, r)
Exemple #3
0
    def test_multiple_minimums(self):
        a = [Foo | Bar, Foo, Bar | Baz | Foo, Bar, Baz]

        r = util.sorted_poset(a)

        idx_foo = r.index(Foo)
        idx_bar = r.index(Bar)
        idx_foobar = r.index(Foo | Bar)

        self.assertLess(idx_foo, idx_foobar)
        self.assertLess(idx_bar, idx_foobar)
        self.assertEqual(r[-1], Bar | Baz | Foo)
Exemple #4
0
    def test_multiple_equivalents(self):
        a = [Baz, Foo | Bar, Foo, Bar | Foo, Bar]

        r = util.sorted_poset(a)

        idx_foo = r.index(Foo)
        idx_bar = r.index(Bar)
        idx_barfoo = r.index(Bar | Foo)
        idx_foobar = r.index(Foo | Bar)

        adjacent = -1 <= idx_barfoo - idx_foobar <= 1
        self.assertTrue(adjacent)
        self.assertLess(idx_foo, idx_barfoo)
        self.assertLess(idx_foo, idx_foobar)
        self.assertLess(idx_bar, idx_barfoo)
        self.assertLess(idx_bar, idx_foobar)
Exemple #5
0
    def _sort_validators(self):
        r"""
        Sorts validators

        Notes
        -----
        A partial order sort of the validators. The runtime for this sort is
        :math:`\theta(n^2)`. This is not a concern, as the number of
        validators present for any particular type is expected to remain
        trivially low. The validators are sorted from general to specific.

        """
        self._validators = sorted_poset(iterable=self._validators,
                                        key=lambda record: record.context,
                                        reverse=True)

        self._is_sorted = True
Exemple #6
0
    def test_mixed_elements(self):
        a = [Foo | Bar, Foo | Baz, Foo]

        r = util.sorted_poset(a)

        self.assertEqual(r[0], Foo)
Exemple #7
0
    def test_already_sorted_all_comparable_reverse(self):
        a = [Foo, Foo | Bar, Foo | Bar | Baz]

        r = util.sorted_poset(a, reverse=True)

        self.assertEqual(list(reversed(a)), r)
Exemple #8
0
    def test_already_sorted_all_comparable(self):
        a = [Foo, Foo | Bar, Foo | Bar | Baz]

        r = util.sorted_poset(a)

        self.assertEqual(a, r)