Skip to content
Snippets Groups Projects
Commit 63519fdb authored by Kipp Cannon's avatar Kipp Cannon
Browse files

gstlal-inspiral: expand test suite

- expand tests of trigger_rate module to cover .coalesce() method
parent ac379959
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,18 @@ def random_coalesced_list(n):
x = l[i][1] + r()
return l
def random_uncoalesced_list(n):
def r():
return float(random.randint(1, 999)) / 1000
if n < 1:
raise ValueError(n)
x = r()
l = trigger_rate.ratebinlist([trigger_rate.ratebin(x, x + r() / 100.0, count = r())])
for i in range(n - 1):
x = r()
l.append(trigger_rate.ratebin(x, x + r() / 100.0, count = r()))
return l
class test_segmentlist(unittest.TestCase):
algebra_repeats = 8000
algebra_listlength = 200
......@@ -38,6 +50,16 @@ class test_segmentlist(unittest.TestCase):
except AssertionError as e:
raise AssertionError(str(e) + "\na = " + str(a) + "\nb = " + str(b))
def test_coalesce(self):
for i in range(self.algebra_repeats):
a = random_uncoalesced_list(random.randint(1, self.algebra_listlength))
b = a.segmentlist()
count_before = sum(seg.count for seg in a)
a.coalesce()
b.coalesce()
self.assertEqual(a.segmentlist(), b)
self.assertAlmostEqual(sum(seg.count for seg in a), count_before, places = 12)
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(test_segmentlist))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment