Esempio n. 1
0
    def test_fold(self):
        def fold_fn(acc, i):
            return acc + (i['bounds'].length() * i['bounds'].width() *
                          i['bounds'].height())

        is1 = IntervalSet([
            Interval(Bounds3D(0, 1, 0, 1, 0, 1), 1),
            Interval(Bounds3D(0, 0.5, 0.5, 1, 0, 0.5), 2),
            Interval(Bounds3D(0, 0.5, 0, 1, 0, 0.5), 3),
        ])
        self.assertAlmostEqual(is1.fold(fold_fn, 0), 1.375)
Esempio n. 2
0
    def test_fold_custom_sortkey(self):
        def sortkey(i):
            return (i['x1'], i['x2'])

        def fold_fn(acc, i):
            acc.append(i['payload'])
            return acc

        is1 = IntervalSet([
            Interval(Bounds3D(0, 1, 0, 0.1, 0, 1), 1),
            Interval(Bounds3D(0, 0.5, 0.5, 1, 0, 0.5), 2),
            Interval(Bounds3D(0.1, 0.4, 0, 1, 0, 0.5), 3),
        ])
        self.assertListEqual(is1.fold(fold_fn, [], sortkey), [1, 3, 2])