diff options
author | Frederick Muriuki Muriithi | 2021-11-09 10:06:01 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2021-11-09 10:06:01 +0300 |
commit | d9ea8744e04d891d1d13c710e24a0a7c85127140 (patch) | |
tree | 9168713bdc58708378e4802fff09af78666729b5 /tests/unit/test_data_helpers.py | |
parent | 9b590d894f1e68ca5d7d00cb6d268f7fb6e6730c (diff) | |
download | genenetwork3-d9ea8744e04d891d1d13c710e24a0a7c85127140.tar.gz |
Add new data processing utility
Issue:
https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi
* gn3/data_helpers.py: New function (`partition_by`)
* tests/unit/test_data_helpers.py: Tests for new function
Add a function that approximates Clojure's `partition-by` function, to help
with processing the data in a more functional way.
Diffstat (limited to 'tests/unit/test_data_helpers.py')
-rw-r--r-- | tests/unit/test_data_helpers.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/unit/test_data_helpers.py b/tests/unit/test_data_helpers.py index 39aea45..3f76344 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,16 @@ class TestDataHelpers(TestCase): parse_csv_line( line=line, delimiter=delimiter, quoting=quoting), expected) + + def test_partition_by(self): + 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) |