diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java | 231 |
1 files changed, 149 insertions, 82 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java index 45833e8556..f87fd31172 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java @@ -2,6 +2,8 @@ package com.mapbox.mapboxsdk.style.expressions; import android.graphics.Color; +import com.mapbox.mapboxsdk.style.layers.PropertyFactory; + import org.junit.Test; import java.util.Arrays; @@ -57,6 +59,7 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.pi; import static com.mapbox.mapboxsdk.style.expressions.Expression.pow; import static com.mapbox.mapboxsdk.style.expressions.Expression.product; import static com.mapbox.mapboxsdk.style.expressions.Expression.properties; +import static com.mapbox.mapboxsdk.style.expressions.Expression.raw; import static com.mapbox.mapboxsdk.style.expressions.Expression.rgb; import static com.mapbox.mapboxsdk.style.expressions.Expression.rgba; import static com.mapbox.mapboxsdk.style.expressions.Expression.round; @@ -88,28 +91,28 @@ public class ExpressionTest { @Test public void testRgb() throws Exception { - Object[] expected = new Object[] {"rgb", 0, 0, 0}; + Object[] expected = new Object[] {"rgb", 0f, 0f, 0f}; Object[] actual = rgb(literal(0), literal(0), literal(0)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testRgbLiteral() throws Exception { - Object[] expected = new Object[] {"rgb", 0, 0, 0}; + Object[] expected = new Object[] {"rgb", 0f, 0f, 0f}; Object[] actual = rgb(0, 0, 0).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testRgba() throws Exception { - Object[] expected = new Object[] {"rgba", 0, 0, 0, 1}; + Object[] expected = new Object[] {"rgba", 0f, 0f, 0f, 1f}; Object[] actual = rgba(literal(0), literal(0), literal(0), literal(1)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testRgbaLiteral() throws Exception { - Object[] expected = new Object[] {"rgba", 0, 0, 0, 1}; + Object[] expected = new Object[] {"rgba", 0f, 0f, 0f, 1f}; Object[] actual = rgba(0, 0, 0, 1).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -117,90 +120,90 @@ public class ExpressionTest { @Test public void testToRgba() throws Exception { Object[] expected = new Object[] {"to-rgba", new Object[] {"to-color", "rgba(255, 0, 0, 255)"}}; - Object[] actual = toRgba(color(Color.RED)).toArray(); + Object[] actual = toRgba(toColor(literal(PropertyFactory.colorToRgbaString(Color.RED)))).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testEq() throws Exception { - Object[] expected = new Object[] {"==", 1, 1}; + Object[] expected = new Object[] {"==", 1f, 1f}; Object[] actual = eq(literal(1), literal(1)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testEqLiteral() throws Exception { - Object[] expected = new Object[] {"==", 1, 1}; + Object[] expected = new Object[] {"==", 1f, 1f}; Object[] actual = eq(literal(1), 1).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testNeq() throws Exception { - Object[] expected = new Object[] {"!=", 0, 1}; + Object[] expected = new Object[] {"!=", 0f, 1f}; Object[] actual = neq(literal(0), literal(1)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testNeqLiteral() throws Exception { - Object[] expected = new Object[] {"!=", 0, 1}; + Object[] expected = new Object[] {"!=", 0f, 1f}; Object[] actual = neq(literal(0), 1).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testGt() throws Exception { - Object[] expected = new Object[] {">", 0, 1}; + Object[] expected = new Object[] {">", 0f, 1f}; Object[] actual = gt(literal(0), literal(1)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testGtLiteral() throws Exception { - Object[] expected = new Object[] {">", 0, 1}; + Object[] expected = new Object[] {">", 0f, 1f}; Object[] actual = gt(literal(0), 1).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testLt() throws Exception { - Object[] expected = new Object[] {"<", 1, 0}; + Object[] expected = new Object[] {"<", 1f, 0f}; Object[] actual = lt(literal(1), literal(0)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testLtLiteral() throws Exception { - Object[] expected = new Object[] {"<", 1, 0}; + Object[] expected = new Object[] {"<", 1f, 0f}; Object[] actual = lt(literal(1), 0).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testGte() throws Exception { - Object[] expected = new Object[] {">=", 1, 1}; + Object[] expected = new Object[] {">=", 1f, 1f}; Object[] actual = gte(literal(1), literal(1)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testGteLiteral() throws Exception { - Object[] expected = new Object[] {">=", 1, 1}; + Object[] expected = new Object[] {">=", 1f, 1f}; Object[] actual = gte(literal(1), 1).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testLte() throws Exception { - Object[] expected = new Object[] {"<=", 1, 1}; + Object[] expected = new Object[] {"<=", 1f, 1f}; Object[] actual = lte(literal(1), literal(1)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testLteLiteral() throws Exception { - Object[] expected = new Object[] {"<=", 1, 1}; + Object[] expected = new Object[] {"<=", 1f, 1f}; Object[] actual = lte(literal(1), 1).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -368,21 +371,21 @@ public class ExpressionTest { @Test public void testAt() throws Exception { - Object[] expected = new Object[] {"at", 3, new Object[] {"literal", new Object[] {"one", "two"}}}; + Object[] expected = new Object[] {"at", 3f, new Object[] {"literal", new Object[] {"one", "two"}}}; Object[] actual = at(literal(3), literal(new Object[] {"one", "two"})).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testAtLiteral() throws Exception { - Object[] expected = new Object[] {"at", 3, new Object[] {"literal", new Object[] {"one", "two"}}}; + Object[] expected = new Object[] {"at", 3f, new Object[] {"literal", new Object[] {"one", "two"}}}; Object[] actual = at(3, literal(new Object[] {"one", "two"})).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testAtExpression() throws Exception { - Object[] expected = new Object[] {"at", 3, new Object[] {"properties"}}; + Object[] expected = new Object[] {"at", 3f, new Object[] {"properties"}}; Object[] actual = at(literal(3), properties()).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -501,56 +504,56 @@ public class ExpressionTest { @Test public void testSum() throws Exception { - Object[] expected = new Object[] {"+", 1, 2}; + Object[] expected = new Object[] {"+", 1f, 2f}; Object[] actual = sum(literal(1), literal(2)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testSumLiteral() throws Exception { - Object[] expected = new Object[] {"+", 1, 2}; + Object[] expected = new Object[] {"+", 1f, 2f}; Object[] actual = sum(1, 2).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testProduct() throws Exception { - Object[] expected = new Object[] {"*", 1, 2}; + Object[] expected = new Object[] {"*", 1f, 2f}; Object[] actual = product(literal(1), literal(2)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testProductLiteral() throws Exception { - Object[] expected = new Object[] {"*", 1, 2}; + Object[] expected = new Object[] {"*", 1f, 2f}; Object[] actual = product(1, 2).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testSubtract() throws Exception { - Object[] expected = new Object[] {"-", 2, 1}; + Object[] expected = new Object[] {"-", 2f, 1f}; Object[] actual = subtract(literal(2), literal(1)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testSubtractLiteral() throws Exception { - Object[] expected = new Object[] {"-", 2, 1}; + Object[] expected = new Object[] {"-", 2f, 1f}; Object[] actual = subtract(2, 1).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testDivision() throws Exception { - Object[] expected = new Object[] {"/", 2, 1}; + Object[] expected = new Object[] {"/", 2f, 1f}; Object[] actual = division(literal(2), literal(1)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testDivisionLiteral() throws Exception { - Object[] expected = new Object[] {"/", 2, 1}; + Object[] expected = new Object[] {"/", 2f, 1f}; Object[] actual = division(2, 1).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -558,203 +561,203 @@ public class ExpressionTest { @Test public void testDivisionWithNestedGet() throws Exception { Object nestedGet = new Object[] {"get", "key"}; - Object[] expected = new Object[] {"/", 2, nestedGet}; + Object[] expected = new Object[] {"/", 2f, nestedGet}; Object[] actual = division(literal(2), get(literal("key"))).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testMod() throws Exception { - Object[] expected = new Object[] {"%", 1, 3}; + Object[] expected = new Object[] {"%", 1f, 3f}; Object[] actual = mod(literal(1), literal(3)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testModLiteral() throws Exception { - Object[] expected = new Object[] {"%", 1, 3}; + Object[] expected = new Object[] {"%", 1f, 3f}; Object[] actual = mod(1, 3).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testPow() throws Exception { - Object[] expected = new Object[] {"^", 2, 3}; + Object[] expected = new Object[] {"^", 2f, 3f}; Object[] actual = pow(literal(2), literal(3)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testPowLiteral() throws Exception { - Object[] expected = new Object[] {"^", 2, 3}; + Object[] expected = new Object[] {"^", 2f, 3f}; Object[] actual = pow(2, 3).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testSqrt() throws Exception { - Object[] expected = new Object[] {"sqrt", 4}; + Object[] expected = new Object[] {"sqrt", 4f}; Object[] actual = sqrt(literal(4)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testSqrtLiteral() throws Exception { - Object[] expected = new Object[] {"sqrt", 4}; + Object[] expected = new Object[] {"sqrt", 4f}; Object[] actual = sqrt(4).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testLog10() throws Exception { - Object[] expected = new Object[] {"log10", 10}; - Object[] actual = log10(literal(10)).toArray(); + Object[] expected = new Object[] {"log10", 10f}; + Object[] actual = log10(literal(10f)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testLog10Literal() throws Exception { - Object[] expected = new Object[] {"log10", 10}; + Object[] expected = new Object[] {"log10", 10f}; Object[] actual = log10(10).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testLn() throws Exception { - Object[] expected = new Object[] {"ln", 2}; + Object[] expected = new Object[] {"ln", 2f}; Object[] actual = ln(literal(2)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testLnLiteral() throws Exception { - Object[] expected = new Object[] {"ln", 2}; + Object[] expected = new Object[] {"ln", 2f}; Object[] actual = ln(2).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testLog2() throws Exception { - Object[] expected = new Object[] {"log2", 16}; + Object[] expected = new Object[] {"log2", 16f}; Object[] actual = log2(literal(16)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testLog2Literal() throws Exception { - Object[] expected = new Object[] {"log2", 16}; + Object[] expected = new Object[] {"log2", 16f}; Object[] actual = log2(16).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testSin() throws Exception { - Object[] expected = new Object[] {"sin", 45}; + Object[] expected = new Object[] {"sin", 45f}; Object[] actual = sin(literal(45)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testSinLiteral() throws Exception { - Object[] expected = new Object[] {"sin", 45}; + Object[] expected = new Object[] {"sin", 45f}; Object[] actual = sin(45).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testCos() throws Exception { - Object[] expected = new Object[] {"cos", 45}; + Object[] expected = new Object[] {"cos", 45f}; Object[] actual = cos(literal(45)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testCosLiteral() throws Exception { - Object[] expected = new Object[] {"cos", 45}; + Object[] expected = new Object[] {"cos", 45f}; Object[] actual = cos(45).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testTan() throws Exception { - Object[] expected = new Object[] {"tan", 45}; + Object[] expected = new Object[] {"tan", 45f}; Object[] actual = tan(literal(45)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testTanLiteral() throws Exception { - Object[] expected = new Object[] {"tan", 45}; + Object[] expected = new Object[] {"tan", 45f}; Object[] actual = tan(45).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testAsin() throws Exception { - Object[] expected = new Object[] {"asin", 45}; + Object[] expected = new Object[] {"asin", 45f}; Object[] actual = asin(literal(45)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testAsinLiteral() throws Exception { - Object[] expected = new Object[] {"asin", 45}; + Object[] expected = new Object[] {"asin", 45f}; Object[] actual = asin(45).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testAcos() throws Exception { - Object[] expected = new Object[] {"acos", 45}; + Object[] expected = new Object[] {"acos", 45f}; Object[] actual = acos(literal(45)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testAcosLiteral() throws Exception { - Object[] expected = new Object[] {"acos", 45}; + Object[] expected = new Object[] {"acos", 45f}; Object[] actual = acos(45).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testAtan() throws Exception { - Object[] expected = new Object[] {"atan", 45}; + Object[] expected = new Object[] {"atan", 45f}; Object[] actual = atan(literal(45)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testAtanLiteral() throws Exception { - Object[] expected = new Object[] {"atan", 45}; + Object[] expected = new Object[] {"atan", 45f}; Object[] actual = atan(45).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testMin() throws Exception { - Object[] expected = new Object[] {"min", 0, 1, 2, 3}; + Object[] expected = new Object[] {"min", 0f, 1f, 2f, 3f}; Object[] actual = min(literal(0), literal(1), literal(2), literal(3)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testMinLiteral() throws Exception { - Object[] expected = new Object[] {"min", 0, 1, 2, 3}; + Object[] expected = new Object[] {"min", 0f, 1f, 2f, 3f}; Object[] actual = min(0, 1, 2, 3).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testMax() throws Exception { - Object[] expected = new Object[] {"max", 0, 1, 2, 3}; + Object[] expected = new Object[] {"max", 0f, 1f, 2f, 3f}; Object[] actual = max(literal(0), literal(1), literal(2), literal(3)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testMaxLiteral() throws Exception { - Object[] expected = new Object[] {"max", 0, 1, 2, 3}; + Object[] expected = new Object[] {"max", 0f, 1f, 2f, 3f}; Object[] actual = max(0, 1, 2, 3).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -833,7 +836,7 @@ public class ExpressionTest { @Test public void testNumber() throws Exception { - Object[] expected = new Object[] {"number", 1}; + Object[] expected = new Object[] {"number", 1f}; Object[] actual = number(literal(1)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -855,7 +858,7 @@ public class ExpressionTest { @Test public void testToString() throws Exception { - Object[] expected = new Object[] {"to-string", 3}; + Object[] expected = new Object[] {"to-string", 3f}; Object[] actual = Expression.toString(literal(3)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -925,14 +928,14 @@ public class ExpressionTest { @Test public void testStepBasic() throws Exception { - Object[] expected = new Object[] {"step", 12, 11, 0, 111, 1, 1111}; + Object[] expected = new Object[] {"step", 12f, 11f, 0f, 111f, 1f, 1111f}; Object[] actual = step(literal(12), literal(11), literal(0), literal(111), literal(1), literal(1111)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testStepBasicLiteral() throws Exception { - Object[] expected = new Object[] {"step", new Object[] {"get", "line-width"}, 11, 0, 111, 1, 1111}; + Object[] expected = new Object[] {"step", new Object[] {"get", "line-width"}, 11f, 0f, 111f, 1f, 1111f}; Object[] actual = step(get("line-width"), literal(11), stop(0, 111), stop(1, 1111)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -941,7 +944,7 @@ public class ExpressionTest { public void testStepExpression() throws Exception { Object[] input = new Object[] {"get", "key"}; Object[] number = new Object[] {"to-number", input}; - Object[] expected = new Object[] {"step", number, 11, 0, 111, 1, 1111}; + Object[] expected = new Object[] {"step", number, 11f, 0f, 111f, 1f, 1111f}; Object[] actual = step(toNumber(get(literal("key"))), literal(11), literal(0), literal(111), literal(1), literal(1111)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); @@ -951,14 +954,14 @@ public class ExpressionTest { public void testStepExpressionLiteral() throws Exception { Object[] input = new Object[] {"get", "key"}; Object[] number = new Object[] {"to-number", input}; - Object[] expected = new Object[] {"step", number, 11, 0, 111, 1, 1111}; + Object[] expected = new Object[] {"step", number, 11f, 0f, 111f, 1f, 1111f}; Object[] actual = step(toNumber(get("key")), literal(11), stop(0, 111), stop(1, 1111)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testLinear() throws Exception { - Object[] expected = new Object[] {"interpolate", new Object[] {"linear"}, 12, 0, 1, 1, 2, 2, 3}; + Object[] expected = new Object[] {"interpolate", new Object[] {"linear"}, 12f, 0f, 1f, 1f, 2f, 2f, 3f}; Object[] actual = interpolate( linear(), literal(12), literal(0), literal(1), @@ -970,16 +973,16 @@ public class ExpressionTest { @Test public void testLinearStops() throws Exception { - Object[] expected = new Object[] {"interpolate", new Object[] {"linear"}, 12, 0, 1, 1, 2, 2, 3}; + Object[] expected = new Object[] {"interpolate", new Object[] {"linear"}, 12f, 0f, 1f, 1f, 2f, 2f, 3f}; Object[] actual = interpolate(linear(), literal(12), stop(0, 1), stop(1, 2), stop(2, 3)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testExponential() throws Exception { - Object[] exponential = new Object[] {"exponential", 12}; + Object[] exponential = new Object[] {"exponential", 12f}; Object[] get = new Object[] {"get", "x"}; - Object[] expected = new Object[] {"interpolate", exponential, get, 0, 100, 200}; + Object[] expected = new Object[] {"interpolate", exponential, get, 0f, 100f, 200f}; Object[] actual = interpolate(exponential(literal(12)), get(literal("x")), literal(0), literal(100), literal(200)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); @@ -987,9 +990,9 @@ public class ExpressionTest { @Test public void testExponentialLiteral() throws Exception { - Object[] exponential = new Object[] {"exponential", 12}; + Object[] exponential = new Object[] {"exponential", 12f}; Object[] get = new Object[] {"get", "x"}; - Object[] expected = new Object[] {"interpolate", exponential, get, 0, 100, 100, 200}; + Object[] expected = new Object[] {"interpolate", exponential, get, 0f, 100f, 100f, 200f}; Object[] actual = interpolate(exponential(12), get("x"), stop(0, 100), stop(100, 200)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -999,16 +1002,16 @@ public class ExpressionTest { Object[] getX = new Object[] {"get", "x"}; Object[] exponential = new Object[] {"exponential", getX}; Object[] getY = new Object[] {"get", "y"}; - Object[] expected = new Object[] {"interpolate", exponential, getY, 0, 100, 100, 200}; + Object[] expected = new Object[] {"interpolate", exponential, getY, 0f, 100f, 100f, 200f}; Object[] actual = interpolate(exponential(get("x")), get("y"), stop(0, 100), stop(100, 200)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @Test public void testCubicBezier() throws Exception { - Object[] cubicBezier = new Object[] {"cubic-bezier", 1, 1, 1, 1}; + Object[] cubicBezier = new Object[] {"cubic-bezier", 1f, 1f, 1f, 1f}; Object[] get = new Object[] {"get", "x"}; - Object[] expected = new Object[] {"interpolate", cubicBezier, get, 0, 100, 100, 200}; + Object[] expected = new Object[] {"interpolate", cubicBezier, get, 0f, 100f, 100f, 200f}; Object[] actual = interpolate(cubicBezier(literal(1), literal(1), literal(1), literal(1)), get(literal("x")), literal(0), literal(100), literal(100), literal(200)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); @@ -1016,9 +1019,9 @@ public class ExpressionTest { @Test public void testCubicBezierLiteral() throws Exception { - Object[] cubicBezier = new Object[] {"cubic-bezier", 1, 1, 1, 1}; + Object[] cubicBezier = new Object[] {"cubic-bezier", 1f, 1f, 1f, 1f}; Object[] get = new Object[] {"get", "x"}; - Object[] expected = new Object[] {"interpolate", cubicBezier, get, 0, 100, 100, 200}; + Object[] expected = new Object[] {"interpolate", cubicBezier, get, 0f, 100f, 100f, 200f}; Object[] actual = interpolate(cubicBezier(1, 1, 1, 1), get("x"), stop(0, 100), stop(100, 200)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -1028,8 +1031,8 @@ public class ExpressionTest { Object[] getX = new Object[] {"get", "x"}; Object[] getY = new Object[] {"get", "y"}; Object[] getZ = new Object[] {"get", "z"}; - Object[] cubicBezier = new Object[] {"cubic-bezier", getZ, 1, getY, 1}; - Object[] expected = new Object[] {"interpolate", cubicBezier, getX, 0, 100, 200}; + Object[] cubicBezier = new Object[] {"cubic-bezier", getZ, 1f, getY, 1f}; + Object[] expected = new Object[] {"interpolate", cubicBezier, getX, 0f, 100f, 200f}; Object[] actual = interpolate(cubicBezier(get(literal("z")), literal(1), get(literal("y")), literal(1)), get(literal("x")), literal(0), literal(100), literal(200)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); @@ -1040,8 +1043,8 @@ public class ExpressionTest { Object[] getX = new Object[] {"get", "x"}; Object[] getY = new Object[] {"get", "y"}; Object[] getZ = new Object[] {"get", "z"}; - Object[] cubicBezier = new Object[] {"cubic-bezier", getZ, 1, getY, 1}; - Object[] expected = new Object[] {"interpolate", cubicBezier, getX, 0, 100, 100, 200}; + Object[] cubicBezier = new Object[] {"cubic-bezier", getZ, 1f, getY, 1f}; + Object[] expected = new Object[] {"interpolate", cubicBezier, getX, 0f, 100f, 100f, 200f}; Object[] actual = interpolate(cubicBezier(get("z"), literal(1), get("y"), literal(1)), get("x"), stop(0, 100), stop(100, 200)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); @@ -1056,14 +1059,15 @@ public class ExpressionTest { @Test public void testExpressionMinToString() throws Exception { - String expected = "[\"min\", 0, 1, 2, 3]"; + String expected = "[\"min\", 0.0, 1.0, 2.0, 3.0]"; String actual = min(0, 1, 2, 3).toString(); assertEquals("toString should match", expected, actual); } @Test public void testExpressionExponentialToString() throws Exception { - String expected = "[\"interpolate\", [\"cubic-bezier\", 1, 1, 1, 1], [\"get\", x], 0, 100, 100, 200]"; + String expected = "[\"interpolate\", [\"cubic-bezier\", 1.0, 1.0, 1.0, 1.0]," + + " [\"get\", x], 0.0, 100.0, 100.0, 200.0]"; String actual = interpolate(cubicBezier(literal(1), literal(1), literal(1), literal(1)), get(literal("x")), literal(0), literal(100), literal(100), literal(200)).toString(); assertEquals("toString should match", expected, actual); @@ -1096,7 +1100,7 @@ public class ExpressionTest { @Test public void testColorConversion() { Expression greenColor = color(0xFF00FF00); - Object[] expected = new Object[] {"to-color", "rgba(0, 255, 0, 255)"}; + Object[] expected = new Object[] {"rgba", 0f, 255f, 0f, 255f}; assertTrue("expression should match", Arrays.deepEquals(expected, greenColor.toArray())); } @@ -1165,4 +1169,67 @@ public class ExpressionTest { Object[] actual = floor(literal(2.2f)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } + + @Test + public void testRawEmpty() { + String raw = "[\"get\", ]"; + Expression expected = get(""); + assertEquals("expressions should match", raw(raw), expected); + + raw = "[\"get\", key]"; + expected = get("key"); + assertEquals("expressions should match", raw(raw), expected); + } + + @Test + public void testRawAndroidColors() { + Expression expected = interpolate(linear(), zoom(), + stop(12, step(get("stroke-width"), + color(Color.BLACK), + stop(1f, color(Color.RED)), + stop(2f, color(Color.WHITE)), + stop(3f, color(Color.BLUE)) + )), + stop(15, step(get("stroke-width"), + color(Color.BLACK), + stop(1f, color(Color.YELLOW)), + stop(2f, color(Color.LTGRAY)), + stop(3f, color(Color.CYAN)) + )), + stop(18, step(get("stroke-width"), + color(Color.BLACK), + stop(1f, color(Color.WHITE)), + stop(2f, color(Color.GRAY)), + stop(3f, color(Color.GREEN)) + )) + ); + assertEquals("expressions should match", expected, raw(expected.toString())); + } + + @Test + public void testRawRgbaColor() { + Expression expected = interpolate( + exponential(2f), zoom(), + literal(5f), literal("rgba(0, 0, 0, 255)"), + literal(10.5f), literal("rgb(255, 0, 0)"), + literal(15), color(Color.GREEN), + literal(20), literal(PropertyFactory.colorToRgbaString(Color.BLUE))); + assertEquals("expressions should match", expected, raw(expected.toString())); + } + + @Test + public void testRawMatchStrings() { + Expression expected = match(get("property"), literal(""), + stop("layer1", "image1"), + stop("layer2", "image2")); + assertEquals("expressions should match", expected, raw(expected.toString())); + } + + @Test + public void testRawMatchNumbers() { + Expression expected = match(get("property"), literal(""), + stop("layer1", 2), + stop("layer2", 2.7)); + assertEquals("expressions should match", expected, raw(expected.toString())); + } }
\ No newline at end of file |