70 lines
1.3 KiB
Python
Executable File
70 lines
1.3 KiB
Python
Executable File
import json
|
|
from tantri.dipoles.generation import DipoleGenerationConfig, Orientation
|
|
import dataclasses
|
|
|
|
|
|
def test_serialise_generation_config_to_json(snapshot):
|
|
|
|
config = DipoleGenerationConfig(
|
|
x_min=-10,
|
|
x_max=10,
|
|
y_min=-5,
|
|
y_max=5,
|
|
z_min=4,
|
|
z_max=8,
|
|
mag=100,
|
|
w_log_min=-3,
|
|
w_log_max=0,
|
|
orientation=Orientation.XY,
|
|
dipole_count=5,
|
|
generation_seed=1234,
|
|
)
|
|
|
|
config_json = json.dumps(dataclasses.asdict(config), indent="\t")
|
|
assert config_json == snapshot
|
|
|
|
|
|
def test_deserialise_json_to_generation_config(snapshot):
|
|
config_json_string = """
|
|
{
|
|
"x_min": -5,
|
|
"x_max": 5,
|
|
"y_min": -4.2,
|
|
"y_max": 39,
|
|
"z_min": 1.2,
|
|
"z_max": 80,
|
|
"mag": 1000,
|
|
"w_log_min": -5.5,
|
|
"w_log_max": 6.6,
|
|
"orientation": "RANDOM",
|
|
"dipole_count": 15,
|
|
"generation_seed": 1234
|
|
}
|
|
"""
|
|
|
|
data = json.loads(config_json_string)
|
|
config = DipoleGenerationConfig(**data)
|
|
|
|
assert config == snapshot
|
|
|
|
|
|
def test_serialise_deserialise_dipole_generation_config_back_and_forth():
|
|
config = DipoleGenerationConfig(
|
|
x_min=-10,
|
|
x_max=10,
|
|
y_min=-5,
|
|
y_max=5,
|
|
z_min=4,
|
|
z_max=8,
|
|
mag=100,
|
|
w_log_min=-3,
|
|
w_log_max=0,
|
|
orientation=Orientation.XY,
|
|
dipole_count=5,
|
|
generation_seed=1234,
|
|
)
|
|
|
|
config_json = json.dumps(dataclasses.asdict(config), indent="\t")
|
|
data = json.loads(config_json)
|
|
assert config == DipoleGenerationConfig(**data)
|