Ejemplo n.º 1
0
    def construct_regions(self, experiment: Experiment, nregions: int,
                          sizepc: float, dimension: int) -> RegionSet:
        """
    Construct a random collection of Regions for the given Experiment.

    Args:
      experiment:   The experiment for this set of Regions.
      nregions:     The number of Regions in this set.
      sizepc:       The maximum size of Regions as a percent
                    of the bounding Region.
      dimension:    The dimensionality of Regions.

    Returns:
      The newly constructed, randomly generated
      collection of Regions.
    """
        bounds = Region([0] * dimension,
                        [experiment.data['maxbound']] * dimension)
        sizepr = Region([0] * dimension, [sizepc] * dimension)
        regions = RegionSet.from_random(nregions, bounds=bounds, sizepc=sizepr)

        self.output_log(experiment, {
            'nregions': nregions,
            'sizepc': sizepc,
            'dimension': dimension
        })

        return regions
Ejemplo n.º 2
0
    def test_create_region(self):
        test_regions = []
        test_regions.append(Region([0], [5]))
        test_regions.append(Region([0, 0], [5, 5]))
        test_regions.append(Region([0, 5, 0], [5, 0, 5]))

        for i, region in enumerate(test_regions):
            #print(region)
            self.assertEqual(region.dimension, i + 1)
            self.assertEqual(region.dimension, len(region.dimensions))
            self.assertEqual(region.dimension, len(region.lower))
            self.assertEqual(region.dimension, len(region.upper))
            self.assertTrue(
                all([d == Interval(0, 5) for d in region.dimensions]))
            self.assertTrue(all([d == 0 for d in region.lower]))
            self.assertTrue(all([d == 5 for d in region.upper]))
            self.assertTrue(
                all([
                    region.lower[i] <= region.upper[i]
                    for i in range(region.dimension)
                ]))
            self.assertTrue(
                all([
                    region.lower[i] == region[i].lower
                    for i in range(region.dimension)
                ]))
            self.assertTrue(
                all([
                    region.upper[i] == region[i].upper
                    for i in range(region.dimension)
                ]))
Ejemplo n.º 3
0
    def test_regionsweep_random(self):
        regionset = RegionSet.from_random(30,
                                          Region([0] * 3, [100] * 3),
                                          sizepc=Region([0] * 3, [0.5] * 3),
                                          precision=0)
        actuals = []
        #for region in regionset: print(f'{region}')
        for i in range(regionset.dimension):
            #print(f'Dimension: {i}')
            expect = regionset.overlaps(i)
            actual = self._evaluate_regionsweep(regionset, i)
            #for pair in expect: print(f'Expect {i}: {pair[0].id} {pair[1].id}')
            #for pair in actual: print(f'Actual {i}: {pair[0].id} {pair[1].id}')
            for pair in expect:
                #passed = "Passed" if pair in actual else "Failed"
                #print(f'{passed} {i}: {pair[0].id} {pair[1].id}')
                self.assertTrue(pair in actual)
            self.assertEqual(len(expect), len(actual))
            actuals.append(actual)

        self.assertTrue(all([len(actual) for actual in actuals]))
        for pair in actuals[0]:
            for d in range(1, regionset.dimension):
                self.assertTrue(pair in actuals[d]
                                or (pair[1], pair[0]) in actuals[d])
Ejemplo n.º 4
0
  def test_regiontimeln_ordering(self):
    regions = RegionSet(dimension=2)
    regions.add(Region([0, 0], [3, 5], 'A'))
    regions.add(Region([3, 1], [5, 5], 'B'))
    regions.add(Region([2, 5], [6, 5], 'C'))
    bbox = regions.bbox
    oracle = [
      [("Init" , 0, bbox),
       ("Begin", 0, regions[0]), ("Begin", 2, regions[2]),
       ("End"  , 3, regions[0]), ("Begin", 3, regions[1]),
       ("End"  , 5, regions[1]), ("End"  , 6, regions[2]),
       ("Done" , 6, bbox)],
      [("Init" , 0, bbox),
       ("Begin", 0, regions[0]), ("Begin", 1, regions[1]),
       ("End"  , 5, regions[0]), ("End"  , 5, regions[1]),
       ("Begin", 5, regions[2]), ("End"  , 5, regions[2]),
       ("Done" , 5, bbox)]
    ]

    for d in range(regions.dimension):
      for i, event in enumerate(regions.timeline.events(d)):
        #print(f'{d},{i}: {event}')
        self.assertEqual(event.kind, RegionEvtKind[oracle[d][i][0]])
        self.assertEqual(event.when, float(oracle[d][i][1]))
        if event.kind == RegionEvtKind.Begin or event.kind == RegionEvtKind.End:
          self.assertIs(event.context, oracle[d][i][2])
          self.assertTrue(-1 <= event.order <= 1)
        elif event.kind == RegionEvtKind.Init:
          self.assertEqual(i, 0)
          self.assertEqual(event.order, -2)
        else:
          self.assertEqual(event.order, 2)
Ejemplo n.º 5
0
    def test_regionset_subset(self):
        nregions = 50
        bounds = Region([0] * 2, [10] * 2)
        sizepc = Region([0] * 2, [0.5] * 2)
        regionset = RegionSet.from_random(nregions,
                                          bounds,
                                          sizepc=sizepc,
                                          precision=1)
        subset = ['A', 'C', 'E', 'G', 'I', 'K'
                  ] + [regionset[r] for r in ['AA', 'P', 'Q', 'R']]
        subsetted = regionset.subset(subset)

        self.assertEqual(regionset.bounds, subsetted.bounds)
        self.assertGreaterEqual(len(regionset), len(subsetted))
        self.assertEqual(len(subset), len(subsetted))
        for r in subset:
            if isinstance(r, str):
                #print(f'{r}: {r in subsetted} {subsetted[r]}')
                self.assertIn(r, subsetted)
                self.assertIs(regionset[r], subsetted[r])
            else:
                #print(f'{r.id}: {r in subsetted} {r}')
                self.assertIsInstance(r, Region)
                self.assertIn(r, subsetted)
                self.assertIs(regionset[r.id], subsetted[r.id])
Ejemplo n.º 6
0
 def setUp(self):
     self.test_regions = []
     self.test_regions.append(Region([0, 0], [5, 5]))
     self.test_regions.append(Region([2, 2], [5, 10]))
     self.test_regions.append(Region([1, 5], [3, 7]))
     self.test_regions.append(Region([-5, 5], [1, 7]))
     self.test_regions.append(Region([-5, 5], [2, 7]))
Ejemplo n.º 7
0
    def test_regionset_tofrom_output(self):
        nregions = 10
        bounds = Region([0] * 2, [100] * 2)
        sizepc = Region([0] * 2, [0.5] * 2)
        regionset = RegionSet.from_random(nregions,
                                          bounds,
                                          sizepc=sizepc,
                                          precision=1)

        with StringIO() as output:
            RegionSet.to_output(regionset, output, options={'compact': True})
            before = output.getvalue()
            #print(before)
            output.seek(0)
            newregionset = RegionSet.from_source(output, 'json')
            self._test_regionset(newregionset, nregions, bounds, regionset)

            output.truncate(0)
            output.seek(0)
            RegionSet.to_output(newregionset,
                                output,
                                options={'compact': True})
            after = output.getvalue()
            #print(after)
            self.assertEqual(before, after)
Ejemplo n.º 8
0
 def test_regionset_from_random(self):
     nregions = 50
     bounds = Region([0] * 2, [10] * 2)
     sizepc = Region([0] * 2, [0.5] * 2)
     regionset = RegionSet.from_random(nregions,
                                       bounds,
                                       sizepc=sizepc,
                                       precision=1)
     self._test_regionset(regionset, nregions, bounds, regionset)
Ejemplo n.º 9
0
 def test_region_random_regions(self):
     region = Region([-5, 0], [15, 10])
     randoms = region.random_regions(5, Region([0.25, 0.25], [0.75, 0.75]))
     randoms += region.random_regions(5,
                                      Region([0.25, 0.25], [0.75, 0.75]),
                                      precision=0)
     #print(f'{region}:')
     for subregion in randoms:
         #print(f'- {subregion}')
         self.assertTrue(subregion in region)
Ejemplo n.º 10
0
 def test_region_random_points(self):
     region2d = Region([-5, 0], [15, 10])
     region3d = Region([-5, 0, 0], [15, 10, 50])
     points2d = region2d.random_points(5)
     points3d = region3d.random_points(5)
     #print(f'{region2d}: random={points2d}')
     #print(f'{region3d}: random={points3d}')
     for point in points2d:
         self.assertTrue(region2d.contains(list(point), inc_upper=False))
     for point in points3d:
         self.assertTrue(region3d.contains(list(point), inc_upper=False))
Ejemplo n.º 11
0
 def setUp(self):
     self.test_regions = []
     self.test_regions.append(Region([0, 0], [5, 5]))
     self.test_regions.append(Region([2, 2], [5, 10]))
     self.test_regions.append(Region([1, 5], [3, 7]))
     self.test_regions.append(Region([-5, 5], [1, 7]))
     self.test_regions.append(Region([-5, 5], [2, 7]))
     self.overlaps = [
         [True, True, False, False, False],  #  [0, 0], [5, 5]
         [True, True, True, False, False],  #  [2, 2], [5, 10]
         [False, True, True, False, True],  #  [1, 5], [3, 7]
         [False, False, False, True, True],  # [-5, 5], [1, 7]
         [False, False, True, True, True]  # [-5, 5], [2, 7]
     ]
Ejemplo n.º 12
0
 def test_region_from_union(self):
     region = Region([0] * 2, [100] * 2)
     regions = region.random_regions(5,
                                     Region([0.1] * 2, [0.25] * 2),
                                     precision=0)
     expected_union = reduce(lambda a, b: a.union(b, 'aggregate'), regions)
     union = Region.from_union(regions, True)
     #print(f'Expected: {expected_union}')
     #print(f'Actual: {union}')
     #print(f'Expected["union"]: {expected_union["union"]}')
     #print(f'Actual["union"]: {union["union"]}')
     self.assertEqual(expected_union, union)
     self.assertListEqual(expected_union['union'], union['union'])
     self.assertTrue(all([union.encloses(r) for r in regions]))
     self.assertTrue(region.encloses(union))
Ejemplo n.º 13
0
    def test_regionsweep_simple(self):
        regionset = RegionSet(dimension=2)
        regionset.add(Region([0, 0], [3, 5]))
        regionset.add(Region([3, 1], [5, 5]))
        regionset.add(Region([2, 4], [6, 6]))

        for i in range(regionset.dimension):
            expect = regionset.overlaps(i)
            actual = self._evaluate_regionsweep(regionset, i)
            #for pair in expect: print(f'Expect {i}:\t{pair[0]}\n\t{pair[1]}')
            #for pair in actual: print(f'Actual {i}:\t{pair[0]}\n\t{pair[1]}')
            for pair in expect:
                #passed = "Passed" if pair in actual else "Failed"
                #print(f'{passed} {i}: {pair[0]} {pair[1]}')
                self.assertTrue(pair in actual)
            self.assertEqual(len(expect), len(actual))
Ejemplo n.º 14
0
 def test_create_regionset(self):
     bounds = Region([0, 0], [100, 100])
     regionset = RegionSet(bounds=bounds)
     regions = bounds.random_regions(10)
     for region in regions:
         regionset.add(region)
     self._test_regionset(regionset, len(regions), bounds, regions)
Ejemplo n.º 15
0
    def test_region_from_text(self):
        test_region = Region([10] * 3, [50] * 3)
        texts = []
        texts.append(('{"lower": [10,10,10], "upper": [50,50,50]}', 'json'))
        texts.append(('{"dimension": 3, "lower": 10, "upper": 50}', 'literal'))
        texts.append(('{"dimension": 3, "lower": 10, "upper": 50}', 'json'))
        texts.append(('{"dimension": 3, "interval": [10, 50]}', 'json'))
        texts.append(('{"dimension": 3, "interval": [10, 50]}', 'literal'))
        texts.append(('{"dimension": 3, "interval": (10, 50)}', 'literal'))
        texts.append(('[[10, 50],[10, 50],[10, 50]]', 'json'))
        texts.append(('[[10, 50],[10, 50],[10, 50]]', 'literal'))
        texts.append(('[(10, 50),(10, 50),(10, 50)]', 'literal'))
        texts.append((
            '[{"lower": 10, "upper": 50},{"lower": 10, "upper": 50},{"lower": 10, "upper": 50}]',
            'json'))
        texts.append((
            '[{"lower": 10, "upper": 50},{"lower": 10, "upper": 50},{"lower": 10, "upper": 50}]',
            'literal'))
        texts.append(('(3, [10, 50])', 'literal'))
        texts.append(('(3, (10, 50))', 'literal'))

        for text in texts:
            #print(f'text="{text[0]}"' if "'" in text else f"text='{text[0]}'")
            #print(f'format={text[1]}')
            self.assertEqual(test_region, Region.from_text(*text))
Ejemplo n.º 16
0
    def test_region_from_object(self):
        test_region = Region([10] * 3, [50] * 3)
        objects = []
        objects.append({"lower": [10] * 3, "upper": [50] * 3})
        objects.append({"dimension": 3, "lower": 10, "upper": [50] * 3})
        objects.append({"dimension": 3, "lower": 10, "upper": 50})
        objects.append({"dimension": 3, "lower": [10] * 3, "upper": 50})
        objects.append({"dimension": 3, "interval": [10, 50]})
        objects.append({"dimension": 3, "interval": (10, 50)})
        objects.append({
            "dimension": 3,
            "interval": {
                "lower": 10,
                "upper": 50
            }
        })
        objects.append({"dimensions": [[10, 50]] * 3})
        objects.append({"dimensions": [(10, 50)] * 3})
        objects.append({"dimensions": [{"lower": 10, "upper": 50}] * 3})
        objects.append([[10, 50]] * 3)
        objects.append([(10, 50)] * 3)
        objects.append([{"lower": 10, "upper": 50}] * 3)
        objects.append((3, [10, 50]))
        objects.append((3, (10, 50)))
        objects.append((3, {"lower": 10, "upper": 50}))

        for object in objects:
            #print(f'{object}')
            self.assertEqual(test_region, Region.from_object(object))
Ejemplo n.º 17
0
    def test_region_linked_intersect(self):
        base_region = Region([0] * 2, [10] * 2)
        regions = [Region([0] * 2, [i] * 2) for i in range(5, 1, -1)]
        ref_region = base_region
        agg_region = base_region
        agg_regions = [base_region]

        for region in regions:
            old_region = ref_region
            agg_regions.append(region)
            ref_region = ref_region.intersect(region, 'reference')
            agg_region = agg_region.intersect(region, 'aggregate')
            #print(f'{asdict(ref_region)}')
            #print(f'{asdict(agg_region)}')
            self.assertListEqual([old_region, region], ref_region['intersect'])
            self.assertListEqual(agg_regions, agg_region['intersect'])
Ejemplo n.º 18
0
    def test_region_linked_union(self):
        base_region = Region([0] * 2, [1] * 2)
        regions = [Region([0, i], [1, i + 1]) for i in range(1, 5)]
        ref_region = base_region
        agg_region = base_region
        agg_regions = [base_region]

        for region in regions:
            old_region = ref_region
            agg_regions.append(region)
            ref_region = ref_region.union(region, 'reference')
            agg_region = agg_region.union(region, 'aggregate')
            #print(f'{asdict(ref_region)}')
            #print(f'{asdict(agg_region)}')
            self.assertListEqual([old_region, region], ref_region['union'])
            self.assertListEqual(agg_regions, agg_region['union'])
Ejemplo n.º 19
0
    def test_regionset_filter(self):
        nregions = 50
        bounds = Region([0] * 2, [10] * 2)
        sizepc = Region([0] * 2, [0.5] * 2)
        regionset = RegionSet.from_random(nregions,
                                          bounds,
                                          sizepc=sizepc,
                                          precision=1)
        filter_bound = Region([5] * 2, [10] * 2)
        filtered = regionset.filter(filter_bound)

        self.assertEqual(filter_bound, filtered.bounds)
        for region in regionset:
            #print(f'{region}: {region in filtered}')
            self.assertEqual(filter_bound.encloses(region), region in filtered)
        for region in filtered:
            #print(f'{region}')
            self.assertTrue(filter_bound.encloses(region))
Ejemplo n.º 20
0
    def test_regionset_iteration(self):
        regionset = RegionSet.from_random(100,
                                          Region([0] * 2, [10] * 2),
                                          sizepc=Region([0] * 2, [0.5] * 2))

        for region in regionset:
            self.assertIsInstance(region, Region)
            self.assertIn(region, regionset)

        for region in regionset.keys():
            self.assertIsInstance(region, str)
            self.assertIn(region, regionset)

        for rid, region in regionset.items():
            self.assertIsInstance(rid, str)
            self.assertIsInstance(region, Region)
            self.assertIn(rid, regionset)
            self.assertIn(region, regionset)
            self.assertEqual(rid, region.id)
Ejemplo n.º 21
0
 def test_region_project(self):
     dimlimit = 7
     test_interval = Interval(1, 5)
     region = Region([-5, 5, 0], [15, 10, 50])
     for d in range(1, dimlimit):
         new_region = region.project(d, test_interval)
         #print(f'{new_region}')
         self.assertEqual(new_region.dimension, d)
         for i in range(0, d):
             interval = region[i] if i < region.dimension else test_interval
             self.assertEqual(new_region[i], interval)
Ejemplo n.º 22
0
    def test_regionset_merge(self):
        nregions = 50
        sizepc = Region([0] * 2, [0.5] * 2)
        first = RegionSet.from_random(nregions,
                                      Region([0] * 2, [10] * 2),
                                      sizepc=sizepc,
                                      precision=1)
        second = RegionSet.from_random(nregions,
                                       Region([0] * 2, [100] * 2),
                                       sizepc=sizepc,
                                       precision=1)
        third = RegionSet(dimension=2)
        third.streamadd([
            Region([-1] * 2, [10] * 2),
            Region([-10, 0], [0, 100]),
            Region([-100, -10], [10, 10])
        ])

        merged = RegionSet.from_merge([first, second, third])
        regionkeys = []

        for region in merged:
            regionkeys.append(region.id)
        for regions in [first, second, third]:
            self.assertTrue(merged.bounds.encloses(regions.bbox))

        self.assertEqual(len(first) + len(second) + len(third), len(merged))
        self.assertEqual(len(regionkeys), len(set(regionkeys)))
Ejemplo n.º 23
0
  def test_regiontimeln_event_create(self):
    self.assertEqual(RegionEvtKind.Begin, RegionEvtKind['Begin'])
    self.assertEqual(RegionEvtKind.End,   RegionEvtKind['End'])
    
    region = Region([0]*2, [1]*2)
    lower = [RegionEvent(RegionEvtKind.Begin, region, i) for i in range(region.dimension)]
    upper = [RegionEvent(RegionEvtKind.End,   region, i) for i in range(region.dimension)]

    self.assertTrue(all([RegionEvtKind.Begin == e.kind for e in lower]))
    self.assertTrue(all([RegionEvtKind.End   == e.kind for e in upper]))
    self.assertTrue(all([e.when == region[i].lower for i, e in enumerate(lower)]))
    self.assertTrue(all([e.when == region[i].upper for i, e in enumerate(upper)]))
    self.assertTrue(all([e.context is region for e in upper + lower]))
Ejemplo n.º 24
0
    def test_regionset_tofrom_output_backlinks(self):
        nregions = 10
        bounds = Region([0] * 2, [100] * 2)
        sizepc = Region([0] * 2, [0.5] * 2)
        regionset = RegionSet.from_random(nregions,
                                          bounds,
                                          sizepc=sizepc,
                                          precision=1)
        regions = []

        for first in regionset:
            for second in regionset:
                if first is not second:
                    regions.append(first.union(second, 'reference'))
                    if first.overlaps(second):
                        regions.append(first.intersect(second, 'reference'))

        for region in regions:
            #print(f'{region}')
            regionset.add(region)

        with StringIO() as output:
            RegionSet.to_output(regionset, output, options={'compact': True})
            #print(output.getvalue())
            output.seek(0)
            newregionset = RegionSet.from_source(output, 'json')

            for region in regions:
                for field in ['intersect', 'union']:
                    if field in region:
                        self.assertTrue(field in newregionset[region.id])
                        self.assertTrue(
                            all([
                                isinstance(r, Region)
                                for r in newregionset[region.id][field]
                            ]))
                        self.assertListEqual(region[field],
                                             newregionset[region.id][field])
Ejemplo n.º 25
0
    def setUp(self):
        definedset = RegionSet(dimension=2)
        definedset.streamadd([
            Region([0, 0], [5, 5], 'A'),
            Region([2, 2], [5, 10], 'B'),
            Region([1, 5], [3, 7], 'C'),
            Region([3, 3], [4, 7], 'D'),
            Region([-5, 5], [1, 7], 'E'),
            Region([-5, 5], [2, 7], 'F'),
            Region([3, 4], [5, 6], 'G')
        ])

        bounds = Region([0] * 2, [1000] * 2)

        self.regions = {'definedset': definedset}
        self.subsets = {
            'definedset': {
                'G1': ['A', 'C', 'E', 'G'],
                'G2': ['B', 'D', 'F'],
                'G3': ['A', 'B', 'C', 'D']
            }
        }

        for nregions in [pow(10, n) for n in range(1, 4)]:
            for sizepc in [0.01, 0.05, 0.1]:
                name = f'{nregions},{sizepc:.2f}'
                sizepcr = Region([0] * 2, [sizepc] * 2)
                regions = RegionSet.from_random(nregions,
                                                bounds,
                                                sizepc=sizepcr,
                                                precision=1)

                self.regions[name] = regions
                self.subsets[name] = {}

                for subsetpc in [0.01, 0.05, 0.1, 0.15, 0.2]:
                    size = round(subsetpc * len(regions))
                    if 0 < size < len(regions):
                        subname = f'{subsetpc:.2f}'
                        shuffled = regions.shuffle()
                        self.subsets[name][subname] = [
                            r.id for i, r in enumerate(shuffled) if i < size
                        ]
Ejemplo n.º 26
0
 def test_region_from_intersect(self):
     regions = [Region([-i] * 2, [i] * 2) for i in range(5, 1, -1)]
     for i in range(1, len(regions)):
         expected_intersect = reduce(
             lambda a, b: a.intersect(b, 'aggregate'), regions[0:i + 1])
         intersect = Region.from_intersect(regions[0:i + 1], True)
         #print(f'Expected: {expected_intersect}')
         #print(f'Expected["intersect"]: {expected_intersect["intersect"]}')
         #print(f'Actual: {intersect}')
         #print(f'Actual["intersect"]: {intersect["intersect"]}')
         self.assertEqual(regions[i], intersect)
         self.assertListEqual(regions[0:i + 1], intersect['intersect'])
         self.assertEqual(expected_intersect, intersect)
         self.assertListEqual(expected_intersect['intersect'],
                              intersect['intersect'])
Ejemplo n.º 27
0
    def setUp(self):
        definedset = RegionSet(dimension=2)
        definedset.streamadd([
            Region([0, 0], [5, 5], 'A'),
            Region([2, 2], [5, 10], 'B'),
            Region([1, 5], [3, 7], 'C'),
            Region([3, 3], [4, 7], 'D'),
            Region([-5, 5], [1, 7], 'E'),
            Region([-5, 5], [2, 7], 'F'),
            Region([3, 4], [5, 6], 'G')
        ])

        bounds = Region([0] * 2, [1000] * 2)

        self.regions = {'definedset': definedset}

        for nregions in [pow(10, n) for n in range(1, 4)]:
            for sizepc in [0.01, 0.05, *([] if nregions > 100 else [0.1])]:
                sizerng = Region([0] * 2, [sizepc] * 2)
                regions = RegionSet.from_random(nregions,
                                                bounds,
                                                sizepc=sizerng,
                                                precision=1)
                self.regions[f'{nregions},{sizepc:.2f}'] = regions
Ejemplo n.º 28
0
 def test_region_contains(self):
     region = Region([-5, 0], [15, 10])
     self.assertTrue(region.lower in region)
     self.assertTrue(region.upper in region)
     self.assertTrue(region.midpoint in region)
     self.assertTrue([v + 0.1 for v in region.lower] in region)
     self.assertTrue([v - 0.1 for v in region.upper] in region)
     self.assertTrue([region.lower[0] + 0.1, region.lower[1]] in region)
     self.assertTrue([region.lower[0], region.lower[1] + 0.1] in region)
     self.assertTrue([region.upper[0] - 0.1, region.upper[1]] in region)
     self.assertTrue([region.upper[0], region.upper[1] - 0.1] in region)
     self.assertFalse(region.contains(region.lower, inc_lower=False))
     self.assertFalse(region.contains(region.upper, inc_upper=False))
     self.assertFalse([v - 0.1 for v in region.lower] in region)
     self.assertFalse([v + 0.1 for v in region.upper] in region)
     self.assertFalse([region.lower[0] - 0.1, region.lower[1]] in region)
     self.assertFalse([region.lower[0], region.lower[1] - 0.1] in region)
     self.assertFalse([region.upper[0] + 0.1, region.upper[1]] in region)
     self.assertFalse([region.upper[0], region.upper[1] + 0.1] in region)
Ejemplo n.º 29
0
    def test_region_encloses(self):
        region = Region([-5, 5], [0, 10])
        test_regions = []
        test_regions.append(Region([-5, 5], [0, 10]))
        test_regions.append(Region([-6, 4], [1, 11]))
        test_regions.append(Region([-4, 6], [-1, 9]))
        test_regions.append(Region([-4, 6], [1, 9]))
        test_regions.append(Region([-6, 5], [0, 10]))
        test_regions.append(Region([-2, 7], [-2, 7]))

        for subregion in test_regions:
            comparsion = all([
                region.lower[i] <= subregion.lower[i] <= subregion.upper[i] <=
                region.upper[i] for i in range(region.dimension)
            ])
            #print(f'{subregion} in\n{region}:')
            #print(f'  expect={comparsion}')
            #print(f'  actual={subregion in region}')
            self.assertEqual(subregion in region, comparsion)
Ejemplo n.º 30
0
    def test_region_equality(self):
        test_regions = []
        test_regions.append(Region([-5, 0], [15, 10]))
        test_regions.append(Region([-5, 1], [15, 10]))
        test_regions.append(Region([-6, 0], [15, 10]))
        test_regions.append(Region([-5, 0], [14, 10]))
        test_regions.append(Region([-5, 0], [15, 11]))
        match_region = Region([-5, 0], [15, 10])

        for region in test_regions:
            self.assertNotEqual(region.id, match_region.id)
            if all([region.lower[i] == match_region.lower[i] and \
                    region.upper[i] == match_region.upper[i] for i in range(match_region.dimension)]):
                self.assertListEqual(region.lower, match_region.lower)
                self.assertListEqual(region.upper, match_region.upper)
                self.assertEqual(region, match_region)