From 9d95e780ecbbb7e4518dac0da833cdc6ed44e043 Mon Sep 17 00:00:00 2001 From: Adam Taranto Date: Sun, 15 Sep 2024 01:00:51 +1000 Subject: [PATCH] Add tests for __iter__ --- src/python/tests/test_dunders.py | 37 ++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/python/tests/test_dunders.py b/src/python/tests/test_dunders.py index 5555d52..89e1fee 100644 --- a/src/python/tests/test_dunders.py +++ b/src/python/tests/test_dunders.py @@ -24,14 +24,39 @@ def test_len_after_multiple_counts(): assert len(kmer_table) == 2, "Length should be 2 after adding two unique k-mers" -def test_iter_dunder_method(): - """KmerCountTable should be iterable, yield hash:count pairs""" - pass +# Test iter methods -def test_next_dunder_method(): - """Select next key in generator""" - pass +def test_iterable(): + kmer_table = create_sample_kmer_table(3, ["AAA", "TTT", "AAC"]) + hash_aaa = kmer_table.hash_kmer("AAA") # 10679328328772601858 + hash_ttt = kmer_table.hash_kmer("TTT") # 10679328328772601858 + hash_aac = kmer_table.hash_kmer("AAC") # 6579496673972597301 + + # Collect items from the iterator + items = list(kmer_table) + + # Check if the items contain the expected tuples + assert 2 in [ + count for _, count in items + ], "Counts should be present in the iterated items" + assert 6579496673972597301 in [ + key for key, _ in items + ], "keys should be present in the iterated items" + assert len(items) == 2, "There should be 2 k-mers in the table" + + +def test_iter_empty(): + kmer_table = oxli.KmerCountTable(ksize=16) + + # Collect items from an empty iterator + items = list(kmer_table) + + # Ensure that no items are returned from an empty table + assert items == [], "Iterator should be empty for an empty KmerCountTable" + + +# Test __set__ and __get__ def test_setitem():