Skip to content

r.mapcalc: Add tests for math functions and operators#6975

Open
saurabh12nxf wants to merge 4 commits intoOSGeo:mainfrom
saurabh12nxf:add-tests-r-mapcalc-functions
Open

r.mapcalc: Add tests for math functions and operators#6975
saurabh12nxf wants to merge 4 commits intoOSGeo:mainfrom
saurabh12nxf:add-tests-r-mapcalc-functions

Conversation

@saurabh12nxf
Copy link
Contributor

Expands test coverage for r.mapcalc by adding tests for previously untested functionality.

Tests added:

  • Math functions: sqrt, exp, log, sin, cos, abs
  • Conditional statements: if(), nested if()
  • Logical operators: &&, ||, !
  • Comparison operators: >, <, ==, !=
  • Null handling: isnull(), null()

Tests are fast and focused, avoiding duplication with existing tests in the testsuite folder.

@github-actions github-actions bot added raster Related to raster data processing Python Related code is in Python module tests Related to Test Suite labels Jan 26, 2026
Copy link
Contributor

@petrasovaa petrasovaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Please see my comments.

expression = f"{self.output} = log(2.718281828)"
self.assertModule("r.mapcalc", expression=expression, overwrite=True)
self.assertRasterFitsUnivar(
self.output, {"mean": 1, "range": 0}, precision=0.01
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not more precision?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was being overly cautious because I used an approximation of e (2.718281828).
now i am thinking to use precision=1e-6 i think this will be more better .

self.assertRasterExists(self.output)


class TestLogicalOperators(TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test the &&& and ||| operators, they are more tricky. Create suitable input rasters for that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the r.mapcalc documentation, the test as you have it now is not actually testing the special behavior of the &&& and ||| operators.


def test_null_creation(self):
"""Test null() function"""
expression = f"{self.output} = null()"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the one from setup, no need to generate it again

@saurabh12nxf
Copy link
Contributor Author

Hi @petrasovaa please once verify it, I have made changes if any improvement still need to do tell me I am happy to do it.

self.assertRasterExists(self.output)


class TestLogicalOperators(TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the r.mapcalc documentation, the test as you have it now is not actually testing the special behavior of the &&& and ||| operators.

@saurabh12nxf
Copy link
Contributor Author

Hi @petrasovaa I’ve updated the &&& and ||| tests to explicitly verify the documented NULL-handling semantics (e.g., NULL &&& 0 == 0, NULL ||| 1 == 1), which distinguish them from && and || thanks for guiding me so many times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module Python Related code is in Python raster Related to raster data processing tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants