Skip to content

Commit

Permalink
Bug fix integer to double
Browse files Browse the repository at this point in the history
  • Loading branch information
Yildirim authored and Yildirim committed Oct 31, 2017
1 parent 28f769c commit 1d91c1e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/main/java/org/jpeek/metrics/cohesion/LCOM2.java
Expand Up @@ -126,7 +126,7 @@ public void visitFieldInsn(final int opcode,
0
);
int sum = 0;
int result = 0;
double result = 0;
for (final String attr : attrs) {
for (final Collection<String> methodattrs : methods) {
if (methodattrs.contains(attr)) {
Expand All @@ -135,7 +135,8 @@ public void visitFieldInsn(final int opcode,
}
}
if (!attrs.isEmpty() && !methods.isEmpty()) {
result = 1 - sum / (attrs.size() * methods.size());
result = 1 - (double) sum / (double) (attrs.size()
* methods.size());
}
return result;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/jpeek/metrics/cohesion/LCOM3.java
Expand Up @@ -122,7 +122,7 @@ public void visitFieldInsn(final int opcode,
0
);
int sum = 0;
int result = 0;
double result = 0;
for (final String attr : attrs) {
for (final Collection<String> methodattrs : methods) {
if (methodattrs.contains(attr)) {
Expand All @@ -132,7 +132,8 @@ public void visitFieldInsn(final int opcode,
}
if (!attrs.isEmpty() && methods.size() != 1) {
final int methodsize = methods.size();
result = (methodsize - (sum / attrs.size())) / (methodsize - 1);
result = ((double) methodsize - (double) sum / (double) attrs
.size()) / (methodsize - 1);
}
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/jpeek/metrics/cohesion/LCOM2Test.java
Expand Up @@ -71,7 +71,7 @@ public void createsXmlReportForFixtureClassA() throws IOException {
),
XhtmlMatchers.hasXPaths(
"/metric/app/package/class[@id='Foo']",
"//class[@id='Foo' and @value='1.0000']",
"//class[@id='Foo' and @value='0.3333']",
"//class[@id='Foo' and @color='yellow']"
)
);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/jpeek/metrics/cohesion/LCOM3Test.java
Expand Up @@ -71,8 +71,8 @@ public void createsXmlReportForFixtureClassA() throws IOException {
),
XhtmlMatchers.hasXPaths(
"/metric/app/package/class[@id='Foo']",
"//class[@id='Foo' and @value='0.0000']",
"//class[@id='Foo' and @color='yellow']"
"//class[@id='Foo' and @value='0.5000']",
"//class[@id='Foo' and @color='red']"
)
);
}
Expand Down

0 comments on commit 1d91c1e

Please sign in to comment.