Skip to content

Commit

Permalink
add tests for rgb_scaling=False
Browse files Browse the repository at this point in the history
  • Loading branch information
sgbaird committed Jun 17, 2022
1 parent a06542f commit b33a42f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/xtal2png_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from warnings import warn

import numpy as np
import plotly.express as px
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
from pymatgen.analysis.structure_matcher import ElementComparator, StructureMatcher
Expand Down Expand Up @@ -125,6 +126,21 @@ def test_structures_to_arrays_single():
return data


def test_structures_to_arrays_zero_one():
xc = XtalConverter(relax_on_decode=False)
data, _, _ = xc.structures_to_arrays(example_structures, rgb_scaling=False)

if np.min(data) < 0.0:
raise ValueError(
f"minimum is less than 0 when rgb_output=False: {np.min(data)}"
)
if np.max(data) > 1.0:
raise ValueError(
f"maximum is greater than 1 when rgb_output=False: {np.max(data)}"
)
return data


def test_arrays_to_structures():
xc = XtalConverter(relax_on_decode=False)
data, id_data, id_mapper = xc.structures_to_arrays(example_structures)
Expand All @@ -133,6 +149,16 @@ def test_arrays_to_structures():
return structures


def test_arrays_to_structures_zero_one():
xc = XtalConverter(relax_on_decode=False)
data, id_data, id_mapper = xc.structures_to_arrays(
example_structures, rgb_scaling=False
)
structures = xc.arrays_to_structures(data, id_data, id_mapper, rgb_scaling=False)
assert_structures_approximate_match(example_structures, structures)
return structures


def test_arrays_to_structures_single():
xc = XtalConverter(relax_on_decode=False)
data, id_data, id_mapper = xc.structures_to_arrays([example_structures[0]])
Expand Down Expand Up @@ -295,6 +321,8 @@ def test_plot_and_save():


if __name__ == "__main__":
test_structures_to_arrays_zero_one()
test_arrays_to_structures_zero_one()
test_relax_on_decode()
test_primitive_decoding()
test_primitive_encoding()
Expand Down

0 comments on commit b33a42f

Please sign in to comment.