Beispiel #1
0
 def _test_encloses(self, range_set: RangeSet[int]):
     self.assertTrue(range_set.encloses_all(ImmutableSet.empty()))
     for query_range in TestRangeSet.QUERY_RANGES:
         expected_to_enclose = any(
             x.encloses(query_range) for x in range_set.as_ranges())
         self.assertEqual(expected_to_enclose,
                          range_set.encloses(query_range))
         self.assertEqual(expected_to_enclose,
                          range_set.encloses_all([query_range]))
Beispiel #2
0
    def test_enclosed(self):
        range_map: ImmutableRangeMap[int,
                                     str] = (ImmutableRangeMap.builder().put(
                                         Range.closed(0, 2),
                                         "foo").put(Range.open_closed(6, 8),
                                                    "bar").put(
                                                        Range.open(12, 14),
                                                        "meep").build())

        self.assertEqual(
            ImmutableSet.of(["foo", "bar", "meep"]),
            range_map.get_enclosed_by(Range.closed(-1, 15)),
        )
        self.assertEqual(ImmutableSet.of(["foo"]),
                         range_map.get_enclosed_by(Range.closed(0, 6)))
        self.assertEqual(ImmutableSet.empty(),
                         range_map.get_enclosed_by(Range.closed(5, 5)))
Beispiel #3
0
 def __getitem__(self, k: KT) -> ImmutableSet[VT]:
     return self._dict.get(k, ImmutableSet.empty())
Beispiel #4
0
 def test_ranges_enclosed_by_out_of_bounds(self) -> None:
     self.assertEqual(
         ImmutableSet.empty(),
         RangeSet.create_mutable()  # type: ignore
         .add(Range.closed(0, 10)).ranges_enclosed_by(Range.at_least(20)),
     )