-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
456 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2017-2019 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.jpeek.skeleton; | ||
|
||
import org.cactoos.text.JoinedText; | ||
import org.cactoos.text.TextEnvelope; | ||
import org.cactoos.text.UncheckedText; | ||
|
||
/** | ||
* A fully qualified name of a field, an unambiguous name | ||
* that specifies field without regard | ||
* to the context of the call. | ||
* @author Ilya Kharlamov (ilya.kharlamov@gmail.com) | ||
* @version $Id$ | ||
* @since 0.29 | ||
*/ | ||
public final class QualifiedName extends TextEnvelope { | ||
/** | ||
* Ctor. | ||
* @param owner The class the attribute belongs to | ||
* @param attr The name of the field | ||
*/ | ||
public QualifiedName(final String owner, final String attr) { | ||
super( | ||
new UncheckedText( | ||
new JoinedText( | ||
".", | ||
owner.replace('/', '.'), | ||
attr | ||
) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2017-2019 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package org.jpeek.metrics; | ||
|
||
import org.cactoos.list.ListOf; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Test case for LCOM4 | ||
* LCOM4 = Logical Relatedness of Methods. | ||
* Basically it's a graph disjoint set. | ||
* I.e. it answers the the following question: | ||
* "Into how many independent classes can you split this class?" | ||
* @author Ilya Kharlamov (ilya.kharlamov@gmail.com) | ||
* @version $Id$ | ||
* @since 0.28 | ||
* @checkstyle JavadocMethodCheck (500 lines) | ||
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines) | ||
* @checkstyle MagicNumberCheck (500 lines) | ||
*/ | ||
public final class Lcom4Test { | ||
|
||
/** | ||
* Variable from the report. | ||
*/ | ||
public static final String PAIRS = "pairs"; | ||
|
||
/** | ||
* Variable from the report. | ||
*/ | ||
public static final String ATTRIBUTES = "attributes"; | ||
|
||
/** | ||
* Variable from the report. | ||
*/ | ||
public static final String METHODS = "methods"; | ||
|
||
/** | ||
* Path to XSL. | ||
*/ | ||
private static final String XSL = "org/jpeek/metrics/LCOM4.xsl"; | ||
|
||
/** | ||
* Tests the deep dependencies methodFour() -> methodTwo() -> methodOne(). | ||
* MethodMethodCalls.java | ||
* - methodOne uses 'num' directly | ||
* - methodTwo uses 'num' indirectly via methodOne | ||
* - methodThree uses 'num' directly | ||
* - methodFour uses 'num' indirectly via methodTwo and methodOne | ||
* - methodFive does not use 'num' (this is an orphan method, ignored) | ||
* Therefore the number of disjoint sets (LCOM4) should be 1 | ||
* since all the methods use the same num field. | ||
* @todo #215:30min LCOM4: Graph algorithm to determine disjoint sets. | ||
* Currently we can only identify the dependencies via only one graph hop | ||
* so we can't trace methodFour that uses 'num' indirectly | ||
* via methodTwo and methodOne. | ||
* Calculating Disjoint sets (also known as Connected Components), | ||
* requires a graph traversal algorithm like depth-first search. | ||
* This one will be tricky to implement in XSLT. | ||
* After implementing, remove the @Ignore. | ||
*/ | ||
@Test | ||
@Ignore | ||
public void methodMethodCalls() throws Exception { | ||
final MetricBase.Report report = new MetricBase( | ||
Lcom4Test.XSL | ||
).transform( | ||
"MethodMethodCalls" | ||
); | ||
report.assertVariable( | ||
Lcom4Test.METHODS, | ||
new ListOf<>( | ||
"methodOne()", | ||
"methodTwo()", | ||
"methodThree()", | ||
"methodFour()", | ||
"methodFive()" | ||
).size() | ||
); | ||
report.assertVariable(Lcom4Test.ATTRIBUTES, 1); | ||
report.assertValue(1.0f, 0.001f); | ||
} | ||
|
||
/** | ||
* In OneCommonAttribute.java. | ||
* - methodOne uses variable 'num' | ||
* - methodTwo uses variable 'num' | ||
* So this class only has a single disjoint set AKA (LCOM4) | ||
* This is an ideal LCOM4 value = 1 | ||
*/ | ||
@Test | ||
public void oneCommonAttribute() throws Exception { | ||
final MetricBase.Report report = new MetricBase( | ||
Lcom4Test.XSL | ||
).transform( | ||
"OneCommonAttribute" | ||
); | ||
report.assertVariable( | ||
Lcom4Test.METHODS, | ||
new ListOf<>( | ||
"methodOne", | ||
"methodTwo" | ||
).size() | ||
); | ||
report.assertVariable(Lcom4Test.ATTRIBUTES, 1); | ||
report.assertVariable(Lcom4Test.PAIRS, 1); | ||
report.assertValue(1.0f, 0.001f); | ||
} | ||
|
||
/** | ||
* In NotCommonAttributes.java | ||
* - methodOne only uses 'num' variable | ||
* - methodTwo only uses 'anotherNum' variable | ||
* So basically there are two separate disjoint sets, | ||
* or two separate classes under the same umbrella. | ||
* So the value is 2.0 | ||
*/ | ||
@Test | ||
public void notCommonAttributes() throws Exception { | ||
final MetricBase.Report report = new MetricBase( | ||
Lcom4Test.XSL | ||
).transform( | ||
"NotCommonAttributes" | ||
); | ||
report.assertVariable(Lcom4Test.ATTRIBUTES, 2); | ||
report.assertVariable(Lcom4Test.PAIRS, 0); | ||
report.assertValue(2.0f, 0.001f); | ||
} | ||
|
||
/** | ||
* Should be the same as NotCommonAttributes. | ||
* since constructors are not methods and should be ignored | ||
*/ | ||
@Test | ||
public void notCommonAttributesWithAllArgsConstructor() throws Exception { | ||
final MetricBase.Report report = new MetricBase( | ||
Lcom4Test.XSL | ||
).transform( | ||
"NotCommonAttributesWithAllArgsConstructor" | ||
); | ||
report.assertVariable(Lcom4Test.ATTRIBUTES, 2); | ||
report.assertVariable(Lcom4Test.PAIRS, 0); | ||
report.assertValue(2.0f, 0.001f); | ||
} | ||
} |
Oops, something went wrong.
f5b7433
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.
Puzzle
8-429ff082
disappeared fromsrc/main/resources/org/jpeek/metrics/LCOM4.xsl
, that's why I closed #215. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.f5b7433
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.
Puzzle
215-e68a3c3f
discovered insrc/test/java/org/jpeek/metrics/Lcom4Test.java
and submitted as #310. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.