Skip to content

Commit

Permalink
Merge pull request #260 from newsletter2go/math_ops_enhancement
Browse files Browse the repository at this point in the history
fix semantic error for checking on double type
  • Loading branch information
jmelo-lyncode committed Dec 28, 2014
2 parents b2298d9 + 546bf28 commit 9ccf625
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
9 changes: 6 additions & 3 deletions jtwig-core/src/main/java/org/jtwig/util/MathOperations.java
Expand Up @@ -56,10 +56,13 @@ public static int toInt (Object obj) {
}

public static boolean areDouble(Object... list) {
if (list == null || list.length == 0)
return false;

for (Object obj : list)
if (obj instanceof Double)
return true;
if (!(obj instanceof Double))
return false;

return false;
return true;
}
}
Expand Up @@ -14,10 +14,15 @@

package org.jtwig.unit.util;

import org.junit.Test;

import static org.jtwig.util.MathOperations.*;
import static org.jtwig.util.MathOperations.areDouble;
import static org.jtwig.util.MathOperations.intDiv;
import static org.jtwig.util.MathOperations.mod;
import static org.jtwig.util.MathOperations.sum;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class MathOperationsTest {
@Test
Expand All @@ -32,4 +37,21 @@ public void modTest() throws Exception {
public void intDivDoubleTest() throws Exception {
assertEquals(1, intDiv(2.0, 2.0));
}
@Test
public void areDoubleTest() {
assertTrue(areDouble(1.0,2.0));
}
@Test
public void areDoubleWithStringAndDoubleTest() {
assertFalse(areDouble("1.0",2.0));
}
@Test
public void areDoubleEmptyParameterListTest() {
assertFalse(areDouble());
}
@Test
public void areDoubleNullParameterListTest() {
Object[] parameterList = null;
assertFalse(areDouble(parameterList));
}
}

0 comments on commit 9ccf625

Please sign in to comment.