Пример #1
0
    def test_size(self):
        ''' Get size. '''
        fr = FmapRange((-11, -4, 3, 0), (3, 5, 7, 11))

        self.assertEqual(fr.size('n', 'w'), (5 + 4) * 11, 'size: nw')
        self.assertEqual(fr.size('h'), 7 - 3, 'size: h')
        self.assertEqual(fr.size(), 14 * 9 * 4 * 11, 'size: all')
Пример #2
0
    def test_rget_counter(self):
        ''' Get rget_counter. '''
        fr = FmapRange((1, 3, 9, 11), (3, 5, 13, 15))
        counters = self.frm.rget_counter(fr)
        self.assertEqual(sum(counters.values()), fr.size(), 'rget_counter')

        fr = FmapRange((0, 0, 0, 0), (0, 0, 0, 0))
        counters = self.frm.rget_counter(fr)
        self.assertEqual(sum(counters.values()), 0, 'rget_counter')

        fr = FmapRange((1, 3, 9, 11), (3, 5, 13, 17))
        counters = self.frm.rget_counter(fr)
        self.assertLess(sum(counters.values()), fr.size(), 'rget_counter')
        self.assertEqual(sum(counters.values()),
                         self.frm.complete_fmap_range().overlap(fr).size(),
                         'rget_counter')
Пример #3
0
    def test_range(self):
        ''' Get range. '''
        fr = FmapRange((-11, -4, 3, 0), (3, 5, 7, 11))

        self.assertEqual(len(set(fr.range('n', 'w'))), fr.size('n', 'w'),
                         'range: nw: len')
        self.assertEqual(len(set(fr.range('h'))), fr.size('h'), 'range: h: len')
        self.assertEqual(len(set(fr.range())), fr.size(), 'range: all: len')

        be_b, be_w = fr.beg_end('b', 'w')
        for pnt in fr.range('b', 'w'):
            self.assertGreaterEqual(pnt[0], be_b[0], 'range: b: >=')
            self.assertLess(pnt[0], be_b[1], 'range: b: <')
            self.assertGreaterEqual(pnt[1], be_w[0], 'range: w: >=')
            self.assertLess(pnt[1], be_w[1], 'range: w: <')

        for fp in fr.range():
            self.assertTrue(fp in fr, 'range: all: in')
Пример #4
0
    def test_contains(self):
        ''' Whether contains fmap point. '''
        fr = FmapRange((-11, -4, 3, 0), (3, 5, 7, 11))

        for fp in fr.range():
            self.assertTrue(fp in fr, 'contains')

        num = 0
        for fp in FmapRange((-12, -12, -12, -12), (12, 12, 12, 12)).range():
            num += 1 if fp in fr else 0
        self.assertEqual(num, fr.size())
Пример #5
0
    def test_overlap_size(self):
        ''' Get overlap_size. '''
        fr1 = FmapRange((-11, -4, 3, 0), (3, 5, 7, 11))
        fr2 = FmapRange((0, 3, 3, -5), (3, 10, 4, 3))
        self.assertEqual(fr1.overlap_size(fr2), 3 * 2 * 1 * 3)
        self.assertEqual(fr2.overlap_size(fr1), 3 * 2 * 1 * 3)

        fr3 = FmapRange((0, 7, 3, -5), (3, 10, 4, 3))
        self.assertEqual(fr1.overlap_size(fr3), 0)

        fr4 = FmapRange((-12, -12, -12, -12), (12, 12, 12, 12))
        self.assertEqual(fr1.overlap_size(fr4), fr1.size())
Пример #6
0
 def test_valid_zero_range(self):
     ''' Valid zero range, i.e., fp_beg == fp_end. '''
     fr = FmapRange((0, 1, 2, 3), (2, 4, 2, 5))
     self.assertEqual(fr.size(), 0, 'Zero range')
Пример #7
0
 def test_rget_counter_same_vals(self):
     ''' Get rget_counter when there are same values in FmapRangeMap. '''
     self.frm.add(FmapRange((0, 0, 0, 16), (4, 8, 16, 32)), 2)
     fr = FmapRange((1, 3, 9, 11), (3, 5, 13, 17))
     counters = self.frm.rget_counter(fr)
     self.assertEqual(sum(counters.values()), fr.size())