diff options
author | Arun Isaac | 2025-07-25 15:04:04 +0100 |
---|---|---|
committer | Arun Isaac | 2025-08-01 12:58:45 +0100 |
commit | 0e9e530b15e41929964d86ca7a70e2126d5c9fa4 (patch) | |
tree | 29fdeb6f3df235139bda8ed033323f57afb2c3a4 | |
parent | 3a88aa0918b494affb2e8bdac423aa28a2ad4d60 (diff) | |
download | pyhegp-0e9e530b15e41929964d86ca7a70e2126d5c9fa4.tar.gz pyhegp-0e9e530b15e41929964d86ca7a70e2126d5c9fa4.tar.lz pyhegp-0e9e530b15e41929964d86ca7a70e2126d5c9fa4.zip |
Test that read_genotype and write_genotype are inverses.
* tests/test_serialization.py: Import read_genotype and write_genotype from pyhegp.serialization. (test_read_write_genotype_are_inverses): New test.
-rw-r--r-- | tests/test_serialization.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/tests/test_serialization.py b/tests/test_serialization.py index 984a935..b234f9d 100644 --- a/tests/test_serialization.py +++ b/tests/test_serialization.py @@ -22,7 +22,7 @@ from hypothesis import given, strategies as st from hypothesis.extra.numpy import arrays, array_shapes from pytest import approx -from pyhegp.serialization import Summary, read_summary, write_summary, read_summary_headers +from pyhegp.serialization import Summary, read_summary, write_summary, read_summary_headers, read_genotype, write_genotype @given(st.integers(), arrays("float64", @@ -68,3 +68,12 @@ def test_read_summary_headers_variable_whitespace(properties_and_whitespace): file.write(f"{key} {value}\n".encode("ascii")) file.seek(0) assert properties == read_summary_headers(file) + +@given(arrays("float64", + array_shapes(min_dims=2, max_dims=2), + elements=st.floats(min_value=0, max_value=100))) +def test_read_write_genotype_are_inverses(genotype): + with tempfile.TemporaryFile() as file: + write_genotype(file, genotype) + file.seek(0) + assert genotype == approx(read_genotype(file)) |