def test_offset(self):
     r = [2.0, 2.0, 3.0, 4.0]
     self.assertEqual(1,
                      len(list(sm.AbsoluteOffsetIterator(r, 0, [3, 3], 2))))
     self.assertEqual(
         441, len(list(sm.AbsoluteOffsetIterator(r, 0.1, [3, 3], 2))))
     r2 = [2000.0, 20000.0, 3.0, 4.0]
     self.assertEqual(
         3, len(list(sm.AbsoluteOffsetIterator(r2, 10, [3, 3], 2))))
     r = [200.0, 200.0, 3.0, 4.0]
     it = sm.RelativeOffsetIterator(r,
                                    0.1,
                                    rounding_vec=[3, 3],
                                    record_id_length=2)
     self.assertEqual([(200.0, 200.0, 3.0, 4.0)], [i for i in it])
 def test_abs_offset_iterator(self):
     r = [1.0, 2.0, 3.0, 4.0]
     it = sm.AbsoluteOffsetIterator(r,
                                    0.1,
                                    rounding_vec=[3, 3],
                                    record_id_length=2)
     self.assertEqual(len(it), len([i for i in it]))
 def test_split(self):
     r = [200.0, 2.0, 3.0, 4.0]
     it = sm.RelativeOffsetIterator(r,
                                    2,
                                    rounding_vec=[3, 3],
                                    record_id_length=2)
     l1 = [str(i) for i in it]
     l = [str(i) for i in it]
     with self.assertRaises(RuntimeError):
         it.split(5)
     it = sm.RelativeOffsetIterator(r,
                                    2,
                                    rounding_vec=[3, 3],
                                    record_id_length=2)
     its = it.split(5)
     self.assertGreaterEqual(len(its), 5)
     l2 = []
     for it in its:
         l2.extend([str(i) for i in it])
     self.assertEqual(sorted(l1), sorted(l2))
     it = sm.RelativeOffsetIterator(r,
                                    2,
                                    rounding_vec=[3, 3],
                                    record_id_length=2)
     its = it.split(5)
     for i in its:
         length = len(list(i))
         self.assertIn(length, [9, 18])
     # split on second
     it = sm.AbsoluteOffsetIterator(r,
                                    0.5,
                                    rounding_vec=[2, 2],
                                    record_id_length=2)
     it2 = copy.deepcopy(it)
     l1 = [i for i in it2]
     its = it.split(5)
     self.assertEqual(4, len(its))
     l2 = []
     for it in its:
         l2.extend([i for i in it])
     self.assertEqual(l1, l2)
 def test_comp_offset_num(self):
     # Relative
     r = [2.0, 2.0, 3.0, 4.0]
     it = sm.RelativeOffsetIterator(r,
                                    5,
                                    rounding_vec=[3, 3],
                                    record_id_length=2)
     self.assertEqual(441, sm.comp_offset_num(it))
     r = [20.0, 20.0, 3.0, 4.0]
     it = sm.RelativeOffsetIterator(r,
                                    0.5,
                                    rounding_vec=[3, 3],
                                    record_id_length=2)
     self.assertEqual(9, sm.comp_offset_num(it))
     # Absolute
     r = [2.0, 2.0, 3.0, 4.0]
     it = sm.AbsoluteOffsetIterator(r,
                                    0.1,
                                    rounding_vec=[3, 3],
                                    record_id_length=2)
     self.assertEqual(441, sm.comp_offset_num(it))
 def test_repr(self):
     r = [100.0, 1.0, 3.0, 4.0]
     t = sm.AbsoluteOffsetIterator(r, 1)
     self.assertEqual(
         "<OffsetIterator from [99.0, 0.0, 2.0, 3.0] to [101.0, 2.0, 4.0, "
         "5.0]>", str(t))