Skip to content
Snippets Groups Projects
Commit e27c46fb authored by Rahil Doshi's avatar Rahil Doshi
Browse files

Fix bugs, final working implementation for data_handler with test cases

parent 224e5f8b
No related branches found
No related tags found
No related merge requests found
Pipeline #68340 failed
......@@ -58,7 +58,7 @@ class Alloy:
self.temperature_boil = interpolate_temperature_boil(self.elements, self.composition)
def interpolate_property(self, T: VariableTypes, temp_array: ValueTypes, prop_array: ValueTypes, prop_name: str,
temp_array_limit=5, force_lookup=False):
temp_array_limit=6, force_lookup=False):
"""
Perform interpolation based on the type of temperature array (equidistant or not).
......
import os
def create_test_files() -> None:
"""
Creates a folder named 'test_files' and generates test files with predefined contents.
......@@ -24,7 +25,7 @@ def create_test_files() -> None:
3050 54.5
3000 54.0
2900 53.0
2800 52.1
2800 52.0
""",
"test_files/test_data_variable_spacing.txt": """Temp Density
3400 58.0
......
......@@ -81,6 +81,9 @@ def clean_temperature_data(temp: np.ndarray, prop: np.ndarray) -> Tuple[np.ndarr
# common_diff = bin_edges[np.argmax(hist)] # Most frequent temperature difference
unique_diffs, counts = np.unique(diffs, return_counts=True)
common_diff = unique_diffs[np.argmax(counts)]
if np.max(counts) < 2:
print("No repeated temperature differences found. Returning original data.")
return temp, prop
print(f"Most common temperature difference: {common_diff}")
except Exception as e:
print(f"Error calculating most common difference: {e}")
......@@ -249,7 +252,7 @@ def run_tests() -> None:
Runs predefined tests to validate data reading and processing functions.
"""
test_cases = [
# {"name": "Normal Case", "file_path": "test_files/test_data_normal.txt"},
{"name": "Normal Case", "file_path": "test_files/test_data_normal.txt"},
# {"name": "Normal Case 1", "file_path": "test_files/test_data_normal1.txt"},
# {"name": "Case with Variable Spacing", "file_path": "test_files/test_data_variable_spacing.txt"},
# {"name": "Case with Sparse Data", "file_path": "test_files/test_data_sparse.txt"},
......@@ -262,7 +265,7 @@ def run_tests() -> None:
# {"name": "Mismatched Columns", "file_path": "test_files/test_data_mismatched_columns.txt"},
# {"name": "Missing Data Entries", "file_path": "test_files/test_data_missing_data.txt"},
# {"name": "Ascending density_temperature values", "file_path": "test_files/test_data_density_temperature_ascending.txt"},
{"name": "Descending density_temperature values", "file_path": "test_files/test_data_density_temperature_descending.txt"}
# {"name": "Descending density_temperature values", "file_path": "test_files/test_data_density_temperature_descending.txt"}
]
for case in test_cases:
......
......@@ -6,4 +6,4 @@ Temp Density
3050 54.5
3000 54.0
2900 53.0
2800 52.1
2800 52.0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment