mirror of
https://github.com/GTNewHorizons/Hardcore-Ender-Expansion.git
synced 2026-10-26 14:24:03 +00:00
Fixed number object equality in Assert
This commit is contained in:
1 parent
1f6b6fb204
commit
a7cd01eed7
1 file changed
+9
-1
@@ -1,4 +1,5 @@
|
||||
package chylex.hee.system.test;
|
||||
import chylex.hee.system.util.MathUtil;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
public final class Assert{
|
||||
@@ -7,7 +8,14 @@ public final class Assert{
|
||||
}
|
||||
|
||||
public static void equal(Object value1, Object value2, String message){
|
||||
if (!Objects.equal(value1,value2))throw new IllegalStateException(message.replace("$1",value1 == null ? "null" : value1.toString()).replace("$2",value2 == null ? "null" : value2.toString()));
|
||||
if (!Objects.equal(value1,value2) && !areNumbersEqual(value1,value2))throw new IllegalStateException(message.replace("$1",value1 == null ? "null" : value1.toString()).replace("$2",value2 == null ? "null" : value2.toString()));
|
||||
}
|
||||
|
||||
private static boolean areNumbersEqual(Object value1, Object value2){
|
||||
if (!(value1 instanceof Number && value2 instanceof Number))return false;
|
||||
|
||||
if (value1 instanceof Double || value1 instanceof Float)return MathUtil.floatEquals(((Number)value1).floatValue(),((Number)value2).floatValue());
|
||||
else return ((Number)value1).longValue() == ((Number)value2).longValue();
|
||||
}
|
||||
|
||||
private Assert(){}
|
||||
|
||||
Reference in new issue
Block a user