Skip to content
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

magic number smell: Inappropriate default threshold #27

Open
testmigrator opened this issue Aug 1, 2024 · 1 comment
Open

magic number smell: Inappropriate default threshold #27

testmigrator opened this issue Aug 1, 2024 · 1 comment

Comments

@testmigrator
Copy link

The default threshold is set to 0.
Assuming a refactoring has already eliminated the magic number, re-testing should not detect this smell.
However, because magicCount = 0 >= 0 (default threshold), the following code will still detect a magic number:

  override val magicNumberTest: Int
        get() = 0
 testMethod.setSmell(false); //default value is false (i.e. no smell)
 super.visit(n, arg);
 testMethod.setSmell(magicCount >= thresholds.getMagicNumberTest());
@jose
Copy link

jose commented Nov 21, 2024

I've just found the exact same issue. IMO, the fix is:

diff --git a/src/main/java/testsmell/smell/MagicNumberTest.java b/src/main/java/testsmell/smell/MagicNumberTest.java
index 6b756ed..c29c18f 100644
--- a/src/main/java/testsmell/smell/MagicNumberTest.java
+++ b/src/main/java/testsmell/smell/MagicNumberTest.java
@@ -52,7 +52,7 @@ public class MagicNumberTest extends AbstractSmell {
                 testMethod.setSmell(false); //default value is false (i.e. no smell)
                 super.visit(n, arg);

-                testMethod.setSmell(magicCount >= thresholds.getMagicNumberTest());
+                testMethod.setSmell(magicCount > thresholds.getMagicNumberTest());
                 testMethod.addDataItem("MagicNumberCount", String.valueOf(magicCount));
                 smellyElementsSet.add(testMethod);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants