Beispiel #1
0
def test_round():
    assert Interval(1.2, 3.4).round() == (1, 3)
    assert Interval(1.2, 3.4).round(method=math.floor) == (1, 3)
    assert Interval(1.2, 3.4).round(method=math.ceil) == (2, 4)
    assert Interval.open_closed(1.2, 3.4).round() == Interval.open_closed(1, 3)
    assert Interval.closed_open(1.2, 3.4).round() == Interval.closed_open(1, 3)
    assert Interval.empty().round() == Interval.empty()
Beispiel #2
0
def test_subset():
    d = Interval(1, 3)
    assert d.is_subset_of((0, 4))
    assert d.is_subset_of((1, 3))
    assert not d.is_subset_of(Interval.closed_open(1, 3))

    assert d.is_superset_of((2, 2))
    assert d.is_superset_of((1, 3))
    assert d.is_superset_of(Interval.closed_open(1, 3))
Beispiel #3
0
def test_equals():
    d = Interval(1, 3)
    assert d.equals((1, 3))
    assert not d.equals(None)
    assert not d.equals(Interval.closed_open(1, 3))
    assert Interval.empty().equals(Interval.empty())
    # Empty intervals are always equal
    assert Interval.open(1, 1).equals(Interval.open(2, 2)) 
    assert Interval.infinite().equals(Interval.infinite())
Beispiel #4
0
    def update_interval(self):
        len_trend_points = len(self.trend_points)
        if self._line is None:
            if len_trend_points == 1:
                self.search_interval = Interval.point(self.trend_points[0][0])
            else:
                self.search_interval = Interval.empty()
            return

        p0, p1 = self._line
        if p0[0] == p1[0]:
            # vertical line
            self.search_interval = Interval.point(p0[0])
            return

        if self.search_length_rel <= 0:
            self.search_interval = Interval.closed(p0[0], p1[0])
            return

        x_min = p0[0]
        x_max = p1[0]

        intersection = self.intersections[0] if len(
            self.intersections) != 0 else None
        if intersection is not None and intersection[0] <= x_min:
            intersection = None

        if intersection is None or len_trend_points >= self.min_points:
            # search ahead
            x_length = (x_max - x_min) * self.search_length_rel
        else:
            # not enought points to go through intersection
            x_length = intersection[0] - x_min

        # if intersection is None:
        #     # search ahead
        #     x_length = (x_max - x_min) * self.search_length_rel
        # elif len_trend_points >= self.min_points:
        #     # search ahead of intersection
        #     x_length = (intersection[0] - x_min) * self.search_length_int_rel
        # else:
        #     # not enought points to go through intersection
        #     x_length = intersection[0] - x_min

        x_max = x_min + x_length

        self.search_interval = Interval.closed_open(x_min, x_max)
Beispiel #5
0
    def _accumulator_map_scan(self, x, y, _):
        points = [[x, y]]
        if self.degree is not None:
            if self.degree != 1:
                points += self.curve.sample_points_from_x(
                    x,
                    self.degree - 1,
                    backward=True,
                    open=True,
                    min_step=self.min_step)
        elif self.period is not None:
            points += reversed(
                self.curve.sample_points(domain=Interval.closed_open(
                    x - self.period, x),
                                         min_step=self.min_step))
        else:
            raise Exception('Bad config')

        ys = [p[1] for p in points]
        return self._accumulator_map(x, ys)
Beispiel #6
0
def test_arithmetic():
    assert Interval(1, 3) + (2, 4) == (1, 4)
    assert (1, 3) + Interval(2, 4) == (1, 4)

    assert Interval.open(1, 3) + (2, 4) == Interval.open_closed(1, 4)
    assert (1, 3) + Interval.open(2, 4) == Interval.closed_open(1, 4)