Repository: RemDelaporteMathurin/h-transport-materials

Issue:
Temperature range should be determined by data_T

Discussion:

Patch:
diff --git a/h_transport_materials/property.py b/h_transport_materials/property.py
index 8174d74..4cc3aee 100644
--- a/h_transport_materials/property.py
+++ b/h_transport_materials/property.py
@@ -67,6 +67,16 @@ class ArrheniusProperty(Property):
         self.data_y = data_y
         super().__init__(**kwargs)
 
+    @property
+    def range(self):
+        if self._range is None and self.data_T is not None:
+            self.fit()
+        return self._range
+
+    @range.setter
+    def range(self, value):
+        self._range = value
+
     @property
     def pre_exp(self):
         if self._pre_exp is None and self.data_T is not None:
@@ -121,6 +131,7 @@ class ArrheniusProperty(Property):
 
     def fit(self):
         self.pre_exp, self.act_energy = fit_arhenius(self.data_y, self.data_T)
+        self.range = (self.data_T.min(), self.data_T.max())
 
     def value(self, T, exp=np.exp):
         return self.pre_exp * exp(-self.act_energy / k_B / T)


Test patch:
diff --git a/tests/test_arhenius_property.py b/tests/test_arhenius_property.py
index 995e830..b030537 100644
--- a/tests/test_arhenius_property.py
+++ b/tests/test_arhenius_property.py
@@ -64,3 +64,14 @@ def test_value(T, pre_exp, act_energy):
     computed_value = my_prop.value(T=T)
     expected_value = pre_exp * np.exp(-act_energy / htm.k_B / T)
     assert expected_value == computed_value
+
+
+def test_fit_creates_temp_range():
+    """Checks that when given data_T and data_y,
+    ArrheniusProperty.range is based on data_T"""
+    my_prop = htm.ArrheniusProperty(
+        data_T=[300, 400, 500],
+        data_y=[1, 2, 3],
+    )
+
+    assert my_prop.range == (300, 500)