Skip to content
Snippets Groups Projects
Commit 612b8910 authored by Malte Nyhuis's avatar Malte Nyhuis
Browse files

Merge branch 'codecov' into 'master'

improving code coverage

See merge request !60
parents 5310a825 eb497f0a
No related branches found
No related tags found
1 merge request!60improving code coverage
Pipeline #15783 passed
......@@ -47,8 +47,8 @@ def inplace_change(filename, old_string, new_string):
with open(filename) as f:
s = f.read()
if old_string not in s:
# print('"{old_string}" not found in {filename}.'.format(**locals()))
return
print('"{old_string}" not found in {filename}.'.format(**locals()))
return -1
# Safely write the changed content, if found in the file
with open(filename, 'w') as f:
......
......@@ -77,5 +77,4 @@ def getGCI(N1, N2, N3, fc1, fc2, fc3, D, Fs=1.25):
text += f'{"EERE_3_p1": <16} {EERE_3_p1}\n'
print(text)
return GCI_1, GCI_2, GCI_3
# return [GCI_1, GCI_2, GCI_3], [EERE_1, EERE_2, EERE_3], [GCI_1_p1, GCI_2_p1, GCI_3_p1], \
# [EERE_1_p1, EERE_2_p1, EERE_3_p1]
......@@ -69,6 +69,20 @@ def test_inplace_change(tmpdir):
assert ans == test_newstring, "inplace change not working"
test_oldstring = "old"
test_fakeoldstring = "nold"
test_newstring = "new"
test_file = tmpdir / "file.txt"
with open(test_file, "w") as fobj:
fobj.write(test_oldstring)
inplace_change(test_file, test_fakeoldstring, test_newstring)
with open(test_file, "r") as fobj:
ans = fobj.read()
assert ans == test_oldstring, "inplace change not working"
def test_get_filelist_fromdir(tmpdir):
os.mkdir(f"{tmpdir}/somedir")
......
import numpy as np
import pytest
from ntrfc.math.vectorcalc import compute_minmax_distance_in_pointcloud
from ntrfc.math.vectorcalc import compute_minmax_distance_in_pointcloud, closest_node_index, distant_node_index
def test_absVec():
......@@ -129,3 +130,18 @@ def test_compute_minimal_distance_in_pointcloud():
# Test case 6: Points with negative coordinates in point cloud
pointcloud = [[-1, -2, -3], [4, -5, 6], [-7, 8, -9]]
assert np.isclose(compute_minmax_distance_in_pointcloud(pointcloud, minmax="max"), 22.693611435820433, atol=1e-6)
@pytest.fixture
def sample_nodes():
return np.array([[0, 0], [1, 1], [2, 2], [3, 3]])
def test_closest_node_index(sample_nodes):
node = [2.5, 2.5]
assert closest_node_index(node, sample_nodes) == 2 # Expected closest node is [2, 2] at index 2
def test_distant_node_index(sample_nodes):
node = [0, 0]
assert distant_node_index(node, sample_nodes) == 3 # Expected distant node is [3, 3] at index 3
......@@ -2,6 +2,8 @@ def test_aspect_ratio():
from ntrfc.meshquality.aspect_ratio import compute_cell_aspect_ratios
import pyvista as pv
import numpy as np
# test good mesh
grid = pv.UniformGrid()
values = np.linspace(0, 10, 1000).reshape((20, 5, 10))
values.shape
......@@ -16,3 +18,20 @@ def test_aspect_ratio():
aspect_ratios = compute_cell_aspect_ratios(grid)
assert np.all(aspect_ratios == max(grid.spacing) / min(grid.spacing))
# test bad mesh
grid = pv.UniformGrid()
values = np.linspace(0, 10, 1000).reshape((20, 5, 10))
values.shape
# Set the grid dimensions: shape + 1 because we want to inject our values on
# the CELL data
grid.dimensions = np.array(values.shape) + 1
# Edit the spatial reference
grid.origin = (100, 33, 55.6) # The bottom left corner of the data set
grid.spacing = (1, 5000, 2) # These are the cell sizes along each axis
aspect_ratios = compute_cell_aspect_ratios(grid)
assert np.all(aspect_ratios == max(grid.spacing) / min(grid.spacing))
......@@ -13,8 +13,26 @@ def test_getgci():
Fs = 1.25
D = 2
GCI_1, GCI_2, GCI_3 = getGCI(N1, N2, N3, fc1, fc2, fc3, D, Fs=1.25)
GCI_1, GCI_2, GCI_3 = getGCI(N1, N2, N3, fc1, fc2, fc3, D, Fs=Fs)
assert np.isclose(GCI_1, 0.0001259844787122061), "GCI_1 computation does not seem to be correct"
assert np.isclose(GCI_2, 0.0008813583711057829), "GCI_3 computation does not seem to be correct"
assert np.isclose(GCI_3, 0.0061695085977409286), "GCI_3 computation does not seem to be correct"
# test with bad values
fc3 = 270.263
fc2 = 262.165
fc1 = 10.151
N3 = 18576
N2 = 74304
N1 = 297216
Fs = 1.25
D = 2
getGCI(N1, N2, N3, fc1, fc2, fc3, D, Fs=Fs)
......@@ -81,6 +81,7 @@ def test_cascade_meshing_gmshwindtunnel(tmpdir):
domain2d = CascadeWindTunnelDomain2D()
domain2d.generate_from_cascade_parameters(gwkconfig, blade)
domain2d.plot_domain(tmpdir / "test.png")
meshpath = tmpdir / "test.cgns"
create_mesh(domain2d, gwkconfig, meshconfig, blade, str(meshpath))
mesh = load_mesh(meshpath)
......
......@@ -18,3 +18,4 @@ def test_calcmidpassagestreamline():
blade.compute_all_frompoints(alpha=alpha)
calcmidpassagestreamline(blade.skeletonline_pv.points[::, 0], blade.skeletonline_pv.points[::, 1],
blade.beta_le, blade.beta_te, -1, 2, 1)
blade.plot()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment