Пример #1
0
 def test_any_intersection(self, nums1, nums2):
     nb1 = nums_to_numbits(nums1)
     good_numbits(nb1)
     nb2 = nums_to_numbits(nums2)
     good_numbits(nb2)
     inter = numbits_any_intersection(nb1, nb2)
     expect = bool(nums1 & nums2)
     assert expect == bool(inter)
Пример #2
0
 def test_intersection(self, nums1, nums2):
     nb1 = nums_to_numbits(nums1)
     good_numbits(nb1)
     nb2 = nums_to_numbits(nums2)
     good_numbits(nb2)
     nbi = numbits_intersection(nb1, nb2)
     good_numbits(nbi)
     intersection = numbits_to_nums(nbi)
     assert nums1 & nums2 == set(intersection)
Пример #3
0
 def test_union(self, nums1, nums2):
     nb1 = nums_to_numbits(nums1)
     good_numbits(nb1)
     nb2 = nums_to_numbits(nums2)
     good_numbits(nb2)
     nbu = numbits_union(nb1, nb2)
     good_numbits(nbu)
     union = numbits_to_nums(nbu)
     self.assertEqual(nums1 | nums2, set(union))
Пример #4
0
 def test_union(self, nums1, nums2):
     nb1 = nums_to_numbits(nums1)
     good_numbits(nb1)
     nb2 = nums_to_numbits(nums2)
     good_numbits(nb2)
     nbu = numbits_union(nb1, nb2)
     good_numbits(nbu)
     union = numbits_to_nums(nbu)
     assert nums1 | nums2 == set(union)
Пример #5
0
    def test_numbits_any_intersection(self):
        res = self.cursor.execute(
            "select numbits_any_intersection(?, ?)",
            (nums_to_numbits([1, 2, 3]), nums_to_numbits([3, 4, 5])))
        answer = [any_inter for (any_inter, ) in res]
        assert [1] == answer

        res = self.cursor.execute(
            "select numbits_any_intersection(?, ?)",
            (nums_to_numbits([1, 2, 3]), nums_to_numbits([7, 8, 9])))
        answer = [any_inter for (any_inter, ) in res]
        assert [0] == answer
Пример #6
0
    def add_lines(self, line_data):
        """Add measured line data.

        `line_data` is a dictionary mapping file names to iterables of ints::

            { filename: { line1, line2, ... }, ...}

        """
        if self._debug.should('dataop'):
            self._debug.write("Adding lines: %d files, %d lines total" %
                              (len(line_data),
                               sum(len(lines)
                                   for lines in line_data.values())))
        self._start_using()
        self._choose_lines_or_arcs(lines=True)
        if not line_data:
            return
        with self._connect() as con:
            self._set_context_id()
            for filename, linenos in line_data.items():
                linemap = nums_to_numbits(linenos)
                file_id = self._file_id(filename, add=True)
                query = "select numbits from line_bits where file_id = ? and context_id = ?"
                existing = list(
                    con.execute(query, (file_id, self._current_context_id)))
                if existing:
                    linemap = numbits_union(linemap, existing[0][0])

                con.execute(
                    "insert or replace into line_bits "
                    " (file_id, context_id, numbits) values (?, ?, ?)",
                    (file_id, self._current_context_id, linemap),
                )
Пример #7
0
 def setup_test(self):
     super().setup_test()
     conn = sqlite3.connect(":memory:")
     register_sqlite_functions(conn)
     self.cursor = conn.cursor()
     self.cursor.execute("create table data (id int, numbits blob)")
     self.cursor.executemany("insert into data (id, numbits) values (?, ?)",
                             [(i, nums_to_numbits(range(i, 100, i)))
                              for i in range(1, 11)])
     self.addCleanup(self.cursor.close)
Пример #8
0
 def test_num_in_numbits(self, num, nums):
     numbits = nums_to_numbits(nums)
     good_numbits(numbits)
     is_in = num_in_numbits(num, numbits)
     assert (num in nums) == is_in
Пример #9
0
 def test_conversion(self, nums):
     numbits = nums_to_numbits(nums)
     good_numbits(numbits)
     nums2 = numbits_to_nums(numbits)
     assert nums == set(nums2)
Пример #10
0
 def test_numbits_to_nums(self):
     res = self.cursor.execute("select numbits_to_nums(?)",
                               [nums_to_numbits([1, 2, 3])])
     assert [1, 2, 3] == json.loads(res.fetchone()[0])
Пример #11
0
 def test_num_in_numbits(self, num, nums):
     numbits = nums_to_numbits(nums)
     good_numbits(numbits)
     is_in = num_in_numbits(num, numbits)
     self.assertEqual(num in nums, is_in)
Пример #12
0
 def test_conversion(self, nums):
     numbits = nums_to_numbits(nums)
     good_numbits(numbits)
     nums2 = numbits_to_nums(numbits)
     self.assertEqual(nums, set(nums2))
Пример #13
0
 def test_any_intersection(self, nums1, nums2):
     inter = numbits_any_intersection(nums_to_numbits(nums1),
                                      nums_to_numbits(nums2))
     expect = bool(nums1 & nums2)
     self.assertEqual(expect, bool(inter))
Пример #14
0
 def test_merging(self, nums1, nums2):
     merged = numbits_to_nums(
         merge_numbits(nums_to_numbits(nums1), nums_to_numbits(nums2)))
     self.assertEqual(nums1 | nums2, set(merged))