diff options
author | Muriithi Frederick Muriuki | 2021-11-20 18:06:32 +0300 |
---|---|---|
committer | GitHub | 2021-11-20 18:06:32 +0300 |
commit | 92d5766f5514181cd6aa82fc0d0f225666e892cb (patch) | |
tree | 74840e8e2118e24e1f49eb780ca0bbf24704e510 /tests/unit/test_data_helpers.py | |
parent | abc0d36f39c691652fee81bce808d625fc368e72 (diff) | |
parent | 08c81b8892060353bb7fb15555875f03bbdcb46e (diff) | |
download | genenetwork3-92d5766f5514181cd6aa82fc0d0f225666e892cb.tar.gz |
Merge pull request #56 from genenetwork/partial-correlations
Partial correlations
Diffstat (limited to 'tests/unit/test_data_helpers.py')
-rw-r--r-- | tests/unit/test_data_helpers.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/unit/test_data_helpers.py b/tests/unit/test_data_helpers.py index 39aea45..88ea469 100644 --- a/tests/unit/test_data_helpers.py +++ b/tests/unit/test_data_helpers.py @@ -4,7 +4,7 @@ Test functions in gn3.data_helpers from unittest import TestCase -from gn3.data_helpers import partition_all, parse_csv_line +from gn3.data_helpers import partition_by, partition_all, parse_csv_line class TestDataHelpers(TestCase): """ @@ -59,3 +59,31 @@ class TestDataHelpers(TestCase): parse_csv_line( line=line, delimiter=delimiter, quoting=quoting), expected) + + def test_partition_by(self): + """ + Test that `partition_by` groups the data using the given predicate + + Given: + - `part_fn`: a predicate funtion that return boolean True/False + - `items`: a sequence of items + When: + - the partitioning predicate function and the sequence of items are + passed to the `partition_by` function + Then: + - the result is a tuple, with sub-tuples containing the data in the + original sequence. Each sub-tuple is a partition, ending as soon as + the next value in the sequence, when passed to `part_fn`, returns + boolean `True`. + """ + for part_fn, items, expected in ( + (lambda s: s.startswith("----"), + ("------", "a", "b", "-----", "c", "----", "d", "e", "---", + "f"), + (("------", "a", "b"), ("-----", "c"), + ("----", "d", "e", "---", "f"))), + (lambda x: (x % 2) == 0, + (0, 1, 3, 2, 4, 5, 7, 6, 9, 1), + ((0, 1, 3), (2,), (4, 5, 7), (6, 9, 1))),): + with self.subTest(items=items): + self.assertEqual(partition_by(part_fn, items), expected) |