Skip to content

Commit

Permalink
Update UnitTests for new functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahshi committed Feb 27, 2024
1 parent 98bfdfb commit a2aadc4
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1,034 deletions.
4 changes: 2 additions & 2 deletions UnitTests/test_density_epsilon.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def setUp(self):
def test_density_calculation(self):

_, density_ls = pig.calculate_density(self.MI_Composition, self.T_room, self.P_room, model='LS')
result_ls = float(density_ls.values)
result_ls = float(density_ls.values[0])
expected_ls = 2702.703558
self.assertAlmostEqual(
result_ls,
Expand All @@ -60,7 +60,7 @@ def test_density_calculation(self):
"calculate_density function with LS do not agree")

_, density_it = pig.calculate_density(self.MI_Composition, self.T_room, self.P_room, model='IT')
result_it = float(density_it.values)
result_it = float(density_it.values[0])
expected_it = 2750.959065
self.assertAlmostEqual(
result_it,
Expand Down
40 changes: 22 additions & 18 deletions UnitTests/test_fittingfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,18 @@ def test_Linear(self):
def test_NIR(self):

for _, data in self.dfs_dict.items():
_, _, PH_5200_krige_1, _ = pig.NIR_process(
data, 4875, 5400, 'H2Om')
_, _, PH_5200_krige_2, _ = pig.NIR_process(
data, 4850, 5375, 'H2Om')
_, _, PH_5200_krige_3, _ = pig.NIR_process(
data, 4900, 5425, 'H2Om')

# Kriged peak heights
PH_5200_krige_M = np.mean([PH_5200_krige_1,
PH_5200_krige_2,
PH_5200_krige_3])
# Three repeat baselines for the H2Om_{5200}
H2Om_5200_peak_ranges = [(4875, 5400), (4850, 5375), (4900, 5425)]
H2Om_5200_results = list(map(lambda peak_range: {
'peak_fit': (result := pig.NIR_process(data, peak_range[0], peak_range[1], 'H2Om'))[0],
'peak_krige': result[1],
'PH_krige': result[2],
'STN': result[3]
}, H2Om_5200_peak_ranges))

PH_5200_krige = [result["PH_krige"] for result in
H2Om_5200_results]
PH_5200_krige_M = np.mean(PH_5200_krige)

result = PH_5200_krige_M
expected = 0.008959072
Expand All @@ -88,13 +89,16 @@ def test_NIR_invalid_peak_type(self):
def test_MIR(self):

for _, data in self.dfs_dict.items():
_, _, PH_3550_1, _ = pig.MIR_process(
data, 1900, 4400)
_, _, PH_3550_2, _ = pig.MIR_process(
data, 2100, 4200)
_, _, PH_3550_3, _ = pig.MIR_process(
data, 2300, 4000)
PH_3550_M = np.mean([PH_3550_1, PH_3550_2, PH_3550_3])

H2Ot_3550_peak_ranges = [(1900, 4400), (2100, 4200), (2300, 4000)]
H2Ot_3550_results = list(map(lambda peak_range: {
'peak_fit': (result := pig.MIR_process(data, peak_range[0], peak_range[1]))[0],
'plot_output': result[1],
'PH': result[2],
}, H2Ot_3550_peak_ranges))

PH_3550 = [result["PH"] for result in H2Ot_3550_results]
PH_3550_M = np.mean(PH_3550)

result = PH_3550_M
expected = 1.523342931
Expand Down
10 changes: 0 additions & 10 deletions UnitTests/test_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,5 @@ def test_chemistry_thickness_path_none(self):
loader = pig.SampleDataLoader(chemistry_thickness_path=None)
loader.load_chemistry_thickness()

def test_invalid_csv_format(self):
# Assuming you have an invalid CSV file for this test
invalid_csv_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'path/to/your/invalid_csv_file.csv'
)
with self.assertRaises(ValueError):
loader = pig.SampleDataLoader(spectrum_path=invalid_csv_path)
loader.load_spectrum_directory()

if __name__ == '__main__':
unittest.main()
7 changes: 3 additions & 4 deletions UnitTests/test_plotting.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion UnitTests/test_thickness.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_reflectance_index(self):
def test_calc_thickness(self):

thickness = float(pig.calculate_thickness(
1.7097733333333334, np.array([0, 50])))
1.7097733333333334, np.array([0, 50]))[0])
expected_thickness = 0.00584873
self.assertAlmostEqual(
thickness,
Expand Down
Loading

0 comments on commit a2aadc4

Please sign in to comment.