The original SimpleTest package contains the functions assertWithinMargin() and assertOutsideMargin(). Both of these are very handy when you are working with floating point numbers that cannot be compared for equality (because of numerical errors).

I am attaching a patch that adds these two functions to the DrupalTestCase.

Also, can these be easily merged into Drupal 7?

Comments

ztyx’s picture

Oh, I meant DrupalWebTestCase of course...

boombatower’s picture

Project: SimpleTest » Drupal core
Version: 6.x-2.5 » 7.x-dev
Component: Code » simpletest.module
Status: Active » Needs review

This should be done in D7 and then backported.

Status: Needs review » Needs work

The last submitted patch failed testing.

lilou’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch failed testing.

lilou’s picture

Status: Needs work » Needs review
StatusFileSize
new2.73 KB

Reroll from root directory.

catch’s picture

Are there existing use cases for these in core? Would be nice to use them if possible.

catch’s picture

Status: Needs review » Needs work

I think we should have some basic tests for these in simpletest.test

dave reid’s picture

Issue tags: +Needs tests
boombatower’s picture

Title: assertWithinMargin() and assertOutsideMargin() » SimpleTest:assertWithinMargin() and assertOutsideMargin()
Assigned: Unassigned » boombatower
Status: Needs work » Needs review
StatusFileSize
new5.12 KB
  • More detailed default messages.
  • Changed _assert() to assert().
  • Added test as requested.

In the future I will work on a cleaner/scalable way to test all the DrupalWebTestCase assertions.

catch’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

dries’s picture

I agree that it would be good to have some use cases in core. Can't think of any.

Status: Reviewed & tested by the community » Needs work

The last submitted patch failed testing.

lilou’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new5.38 KB

Reroll from HEAD.

Back to previous status.

Status: Reviewed & tested by the community » Needs work

The last submitted patch failed testing.

boombatower’s picture

Status: Needs work » Needs review

teh bot?

arianek’s picture

StatusFileSize
new5.31 KB

applied patch to D7 HEAD:
Hunk #1 succeeded at 336 (offset 40 lines).

re-rolled for bot.

Status: Needs review » Needs work

The last submitted patch failed testing.

klausi’s picture

Assigned: boombatower » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.91 KB

Reroll.

Status: Needs review » Needs work
Issue tags: -Needs tests

The last submitted patch, 334950-simpletest-margin.patch, failed testing.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.