-
-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
r.surf.fractal: Added seed option and -s flag to module #3480
base: main
Are you sure you want to change the base?
Changes from 7 commits
71c5f2d
44791a5
19b77d5
e2318bf
fe3258e
860ca1a
fe666a5
8dca62b
f927cf8
ad4d972
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
MODULE: Test of r.surf.fractal | ||
|
||
AUTHOR(S): Shashank Shekhar Singh <shashankshekharsingh1205 gmail com> | ||
|
||
PURPOSE: Test fractal surface generation with r.surf.fractal module | ||
|
||
COPYRIGHT: (C) 2024 by Shashank Shekhar Singh and the GRASS Development Team | ||
|
||
This program is free software under the GNU General Public | ||
License (>=v2). Read the file COPYING that comes with GRASS | ||
for details. | ||
""" | ||
|
||
import os | ||
|
||
import grass.script as gs | ||
Shashankss1205 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
from grass.gunittest.case import TestCase | ||
from grass.gunittest.main import test | ||
|
||
|
||
class FractalTestCase(TestCase): | ||
"""Test case for r.surf.fractal""" | ||
|
||
# Raster map name to be used as output | ||
output = "fractal_result" | ||
marisn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@classmethod | ||
def setUpClass(cls): | ||
"""Set up necessary environment""" | ||
# Set up temporary computational region | ||
cls.use_temp_region() | ||
# Only 100,000,000 seem to reasonably (not 100%) ensure that all values | ||
# are generated, so exceeding of ranges actually shows up. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What kind of ranges you are referring to? I didn't see any range check. Usually a tiny computational region suffices to save on CI execution time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind helping me with the test suite please, because I haven't previously worked with them and therefore I was struggling with how to write them. Thanks @marisn There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See for example test for r.random.cells and test documentation. Run r.surf.fractal first with certain fixed seed and save the raster statistics (computed with r.univar) for reference in the test. You can then use assertRasterFitsUnivar to ensure the test-generated raster with the same fixed seed will always give the same values. This type of test is not necessarily testing the output is correct, but it helps detect any regressions in the tool in the future and also that with a fixed seed you always get the same results. |
||
cls.runModule("g.region", rows=10000, cols=10000) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
"""Clean up temporary environment""" | ||
cls.del_temp_region() | ||
|
||
def tearDown(self): | ||
"""Remove the output created from the module after each test""" | ||
self.runModule("g.remove", flags="f", type="raster", name=[self.output]) | ||
|
||
def test_default_settings(self): | ||
"""Test with default settings""" | ||
self.assertModule("r.surf.fractal", output=self.output) | ||
|
||
def test_fractal_dimension(self): | ||
"""Test with specified fractal dimension""" | ||
fractal_dim = 2.05 # Example fractal dimension value | ||
self.assertModule( | ||
"r.surf.fractal", | ||
dimension=fractal_dim, | ||
output=self.output, | ||
) | ||
|
||
def test_num_images(self): | ||
"""Test with specified number of intermediate images""" | ||
num_images = 5 # Example number of intermediate images | ||
self.assertModule( | ||
"r.surf.fractal", | ||
number=num_images, | ||
output=self.output, | ||
) | ||
|
||
def test_random_seed(self): | ||
"""Test with specified random seed""" | ||
seed_value = 12345 # Example random seed value | ||
self.assertModule( | ||
"r.surf.fractal", | ||
seed=seed_value, | ||
output=self.output, | ||
) | ||
|
||
def test_generate_random_seed(self): | ||
"""Test with flag to generate random seed""" | ||
self.assertModule( | ||
"r.surf.fractal", | ||
flags="s", | ||
output=self.output, | ||
) | ||
|
||
def test_invalid_fractal_dimension(self): | ||
"""Test with invalid fractal dimension""" | ||
invalid_dim = 1.5 # Example invalid fractal dimension value | ||
# Ensure that the module fails with an error message | ||
self.assertModuleFail( | ||
"r.surf.fractal", | ||
dimension=invalid_dim, | ||
output=self.output, | ||
) | ||
|
||
def test_invalid_seed_value(self): | ||
"""Test with invalid random seed value""" | ||
invalid_seed = "abc" # Example invalid random seed value | ||
# Ensure that the module fails with an error message | ||
self.assertModuleFail( | ||
"r.surf.fractal", | ||
seed=invalid_seed, | ||
output=self.output, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
test() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the first sentence and the "-s"