예제 #1
0
    def test_interval_covers_interval(self, ivl_side, oth_side):

        # class Interval:
        #     def covers(self, other: Interval) -> bool

        assert Interval(1, 3).covers(Interval(1.5, 2.5))
        assert Interval(1, 3).covers(Interval(1, 2))
        assert Interval(1, 3).covers(Interval(2, 3))
        assert not Interval(1, 3).covers(Interval(0.5, 2.5))
        assert not Interval(1, 3).covers(Interval(1.5, 3.5))

        ivl = Interval(1, 3, closed=ivl_side)
        other = Interval(1, 3, closed=oth_side)

        should_cover = {
            'right': {
                'right': True,
                'left': False,
                'both': False,
                'neither': True
            },
            'left': {
                'right': False,
                'left': True,
                'both': False,
                'neither': True
            },
            'both': {
                'right': True,
                'left': True,
                'both': True,
                'neither': True
            },
            'neither': {
                'right': False,
                'left': False,
                'both': False,
                'neither': True
            }
        }

        result = ivl.covers(other)
        expected = should_cover[ivl_side][oth_side]
        assert result == expected
예제 #2
0
    def test_interval_covers_intervalIndex(self, idx_side, ivl_side,
                                           ivl_range):

        # class Interval:
        #     def covers(self, other: IntervalIndex) -> IntegerArray1D

        # class IntervalIndex:
        #     def covers(self, other: Interval) -> IntegerArray1D

        idx = IntervalIndex.from_tuples([(0, 1), (2, 3), (1, 3)],
                                        closed=idx_side)
        ivl = Interval(*ivl_range, closed=ivl_side)

        should_cover = {
            # idx_side:
            #   ivl_side: {ivl_range: expected_result}
            'right': {
                'right': {
                    (1, 3): [1, 2],
                    (0, 3): [0, 1, 2],
                    (0, 2): [0],
                    (2, 4): [1]
                },
                'left': {
                    (1, 3): [],
                    (0, 3): [0],
                    (0, 2): [0],
                    (2, 4): [1]
                },
                'both': {
                    (1, 3): [1, 2],
                    (0, 3): [0, 1, 2],
                    (0, 2): [0],
                    (2, 4): [1]
                },
                'neither': {
                    (1, 3): [],
                    (0, 3): [0],
                    (0, 2): [0],
                    (2, 4): [1]
                }
            },
            'left': {
                'right': {
                    (1, 3): [1],
                    (0, 3): [1, 2],
                    (0, 2): [],
                    (2, 4): []
                },
                'left': {
                    (1, 3): [1, 2],
                    (0, 3): [0, 1, 2],
                    (0, 2): [0],
                    (2, 4): [1]
                },
                'both': {
                    (1, 3): [1, 2],
                    (0, 3): [0, 1, 2],
                    (0, 2): [0],
                    (2, 4): [1]
                },
                'neither': {
                    (1, 3): [1],
                    (0, 3): [1, 2],
                    (0, 2): [],
                    (2, 4): []
                }
            },
            'both': {
                'right': {
                    (1, 3): [1],
                    (0, 3): [1, 2],
                    (0, 2): [],
                    (2, 4): []
                },
                'left': {
                    (1, 3): [],
                    (0, 3): [0],
                    (0, 2): [0],
                    (2, 4): [1]
                },
                'both': {
                    (1, 3): [1, 2],
                    (0, 3): [0, 1, 2],
                    (0, 2): [0],
                    (2, 4): [1]
                },
                'neither': {
                    (1, 3): [],
                    (0, 3): [],
                    (0, 2): [],
                    (2, 4): []
                }
            },
            'neither': {
                'right': {
                    (1, 3): [1, 2],
                    (0, 3): [0, 1, 2],
                    (0, 2): [0],
                    (2, 4): [1]
                },
                'left': {
                    (1, 3): [1, 2],
                    (0, 3): [0, 1, 2],
                    (0, 2): [0],
                    (2, 4): [1]
                },
                'both': {
                    (1, 3): [1, 2],
                    (0, 3): [0, 1, 2],
                    (0, 2): [0],
                    (2, 4): [1]
                },
                'neither': {
                    (1, 3): [1, 2],
                    (0, 3): [0, 1, 2],
                    (0, 2): [0],
                    (2, 4): [1]
                }
            }
        }

        result = ivl.covers(idx)
        expected = np.array(should_cover[idx_side][ivl_side][ivl_range])
        other_result = idx.covers(ivl)

        tm.assert_numpy_array_equal(result, expected)
        tm.assert_numpy_array_equal(other_result, expected)