From 0e9e530b15e41929964d86ca7a70e2126d5c9fa4 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Fri, 25 Jul 2025 15:04:04 +0100 Subject: 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. --- tests/test_serialization.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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)) -- cgit 1.4.1