Skip to content

Commit ce43d67

Browse files
author
rmdocherty
committed
added two more tests
1 parent e83c5b5 commit ce43d67

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/tests.py

+34
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
np.random.seed(0)
44
from skimage.draw import disk, rectangle
5+
from skimage.data import binary_blobs
56
from tifffile import imread
67
import matplotlib.pyplot as plt
78

@@ -123,7 +124,38 @@ def test_cls_squares(self):
123124
# plt.imsave("foo.png", arr)
124125
print(integral_range, np.sqrt(2) * l)
125126

127+
def test_blobs_vf_cls(self):
128+
"""Test the cls of random binary blobs, should be around the set length scale"""
129+
print("## Test case: cls of random blobs")
130+
h, l, vf = 750, 10, 0.4
131+
percent_l = l / h
132+
test_arr = binary_blobs(h, percent_l, 2, vf)
133+
result = model.make_error_prediction(test_arr, model_error=False)
134+
assert np.isclose(result["integral_range"], l, atol=5)
135+
126136
def test_repr_pred(self):
137+
"""Test the percentage error of a random binomial size (500,500) - should be small"""
138+
print("## Test case: representativity of random binomial")
139+
test_arr = np.random.binomial(1, 0.5, (500, 500))
140+
result = model.make_error_prediction(test_arr, model_error=False)
141+
assert result["percent_err"] < 0.05
142+
143+
def test_binary(self):
144+
"""Test that abs_err of repr of phase 1 of binary = abs_err of phase 2 of binary"""
145+
print("## Test case: repr of two phases of binary materials the same")
146+
h, l, vf = 750, 10, 0.4
147+
percent_l = l / h
148+
test_arr = binary_blobs(h, percent_l, 2, vf)
149+
inv_test_arr = ~test_arr
150+
result_1 = model.make_error_prediction(test_arr, model_error=False)
151+
result_2 = model.make_error_prediction(inv_test_arr, model_error=False)
152+
153+
print(
154+
f"abs err phase 1: {result_1['abs_err']}, abs err phase 2: {result_2['abs_err']}"
155+
)
156+
assert np.isclose(result_1["abs_err"], result_2["abs_err"], rtol=0.001)
157+
158+
def test_repr_zoom_pred(self):
127159
"""Measure the representativity of a crop of our default microstructure, finding the image edge length
128160
needed to reach a given $desired_error. Then crop the microstructure to this (larger) edge length,
129161
measuring the representativity and percent error again. If our model is correct (and conservative),
@@ -148,6 +180,8 @@ def test_repr_pred(self):
148180
)
149181
assert refined_result["percent_err"] < result["percent_err"]
150182

183+
# TODO: test that reprs of each phase of binary microstrucutre are the same
184+
151185

152186
if __name__ == "__main__":
153187
unittest.main(argv=["example"])

0 commit comments

Comments
 (0)