Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

表达式问题修复以及新增整数类型 #240

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GaiaXAnalyze/GXAnalyzeAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.31@jar"
implementation 'com.alibaba:fastjson:1.2.26@jar'

implementation 'androidx.annotation:annotation:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.3'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class GXAnalyzeTest {
GXAnalyze.createValueBool(true);
} else if (valuePath == "data.false") {
GXAnalyze.createValueBool(false);
}else if(valuePath == "data.long"){
GXAnalyze.createValueLong(8L);
} else {
GXAnalyze.createValueFloat64(8F)
}
Expand Down Expand Up @@ -84,6 +86,8 @@ class GXAnalyzeTest {
} else {
return GXAnalyze.createValueFloat64(0f)
}
}else{
return GXAnalyze.createValueFloat64(8f)
}
return 0L
}
Expand All @@ -96,6 +100,7 @@ class GXAnalyzeTest {
@Test
fun empty_test() {
repeat(100) {
Assert.assertEquals("1.0", 1.000.toString())
Assert.assertEquals("", instance.getResult("\$data.stringEmpty", testData))
Assert.assertEquals("test", instance.getResult("\$data.stringEmpty + 'test'", testData))
Assert.assertEquals("", instance.getResult("''", testData))
Expand All @@ -108,16 +113,16 @@ class GXAnalyzeTest {
@Test
fun num_test() {
repeat(100) {
Assert.assertEquals(10000f, instance.getResult("10000", testData))
Assert.assertEquals(10000L, instance.getResult("10000", testData))
Assert.assertEquals(10f, instance.getResult("10.000", testData))
Assert.assertEquals(100f, instance.getResult("100.00", testData))
Assert.assertEquals(1000f, instance.getResult("1000.0", testData))
Assert.assertEquals(1001f, instance.getResult("1001.0", testData))
Assert.assertEquals(1111f, instance.getResult("1111", testData))
Assert.assertEquals(11110f, instance.getResult("11110", testData))
Assert.assertEquals(20000f, instance.getResult("10000+10000", testData))
Assert.assertEquals(1111L, instance.getResult("1111", testData))
Assert.assertEquals(11110L, instance.getResult("11110", testData))
Assert.assertEquals(20000L, instance.getResult("10000+10000", testData))
Assert.assertEquals(
26f,
26L,
instance.getResult("1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1", testData)
)
}
Expand Down Expand Up @@ -154,6 +159,8 @@ class GXAnalyzeTest {
testData
)
)
Assert.assertEquals(8f, instance.getResult("size()", testData))
Assert.assertEquals(16f, instance.getResult("size()+8", testData))
}
}

Expand All @@ -172,30 +179,31 @@ class GXAnalyzeTest {
@Test
fun mod_calculate() {
repeat(100) {
Assert.assertEquals(0f, instance.getResult("2%2", testData))
Assert.assertEquals(0f, instance.getResult("3%-1", testData))
Assert.assertEquals(1f, instance.getResult("3%2", testData))
Assert.assertEquals(0L, instance.getResult("2%2", testData))
Assert.assertEquals(0L, instance.getResult("3%-1", testData))
Assert.assertEquals(1L, instance.getResult("3%2", testData))
}
}

//
@Test
fun add_calculate() {
repeat(100) {
Assert.assertEquals(10f, instance.getResult("1+2+3+4", testData))
Assert.assertEquals(1f, instance.getResult("0+1", testData))
Assert.assertEquals(10L, instance.getResult("1+2+3+4", testData))
Assert.assertEquals(1L, instance.getResult("0+1", testData))
Assert.assertEquals("abcd", instance.getResult("'ab'+'cd'", testData))
Assert.assertEquals(10f, instance.getResult("\$data+2", testData))
Assert.assertEquals(10L, instance.getResult("\$data.long+2", testData))
Assert.assertEquals(16f, instance.getResult("\$data+\$data", testData))
Assert.assertEquals("1231", instance.getResult("'123' + 1", testData))
Assert.assertEquals("1231", instance.getResult("'1' + 231", testData))
Assert.assertEquals("1231", instance.getResult("'123' + 1.000", testData))
Assert.assertEquals("1231.000", instance.getResult("'123' + 1.000", testData))
Assert.assertEquals("1231.001", instance.getResult("'123' + 1.001", testData))
Assert.assertEquals("1231.001", instance.getResult("'123' + 1.001000", testData))
Assert.assertEquals("123.001.001", instance.getResult("'123.00' + 1.001000", testData))
Assert.assertEquals("1230", instance.getResult("'123' + 0.000", testData))
Assert.assertEquals("1231.001000", instance.getResult("'123' + 1.001000", testData))
Assert.assertEquals("123.001.001000", instance.getResult("'123.00' + 1.001000", testData))
Assert.assertEquals("1230.000", instance.getResult("'123' + 0.000", testData))
Assert.assertEquals("1230.001", instance.getResult("'123' + 0.001", testData))
Assert.assertEquals("1231", instance.getResult("123.000 + '1'", testData))
Assert.assertEquals("123.0001", instance.getResult("123.000 + '1'", testData))
Assert.assertEquals("123.0011", instance.getResult("123.001 + '1'", testData))
Assert.assertEquals("123.0011.0", instance.getResult("123.001 + '1.0'", testData))
}
Expand All @@ -204,9 +212,9 @@ class GXAnalyzeTest {
@Test
fun subtract_calculate() {
repeat(100) {
Assert.assertEquals(3f, instance.getResult("4-1", testData))
Assert.assertEquals(-1f, instance.getResult("1-2", testData))
Assert.assertEquals(-1f, instance.getResult("0-1", testData))
Assert.assertEquals(3L, instance.getResult("4-1", testData))
Assert.assertEquals(-1L, instance.getResult("1-2", testData))
Assert.assertEquals(-1L, instance.getResult("0-1", testData))
Assert.assertEquals(-2f, instance.getResult("\$data-10", testData))
Assert.assertEquals(2f, instance.getResult("10-\$data", testData))
Assert.assertEquals(0f, instance.getResult("8-\$data", testData))
Expand All @@ -219,17 +227,17 @@ class GXAnalyzeTest {
@Test
fun multiply_calculate() {
repeat(100) {
Assert.assertEquals(0f, instance.getResult("0*2", testData))
Assert.assertEquals(-2f, instance.getResult("-1*2", testData))
Assert.assertEquals(-2f, instance.getResult("2*-1", testData))
Assert.assertEquals(-1f, instance.getResult("+1*-1", testData))
Assert.assertEquals(2f, instance.getResult("2*+1", testData))
Assert.assertEquals(0L, instance.getResult("0*2", testData))
Assert.assertEquals(-2L, instance.getResult("-1*2", testData))
Assert.assertEquals(-2L, instance.getResult("2*-1", testData))
Assert.assertEquals(-1L, instance.getResult("+1*-1", testData))
Assert.assertEquals(2L, instance.getResult("2*+1", testData))
Assert.assertEquals(4.4f, instance.getResult("2.2*2", testData))
Assert.assertEquals(-4.4f, instance.getResult("-2.2*2", testData))
Assert.assertEquals(-8f, instance.getResult("\$data*-1", testData))
Assert.assertEquals(64f, instance.getResult("\$data*\$data", testData))
Assert.assertEquals(16f, instance.getResult("\$data*2", testData))
Assert.assertEquals(1f, instance.getResult("1*1", testData))
Assert.assertEquals(1L, instance.getResult("1*1", testData))
Assert.assertEquals(true, instance.getResult("(1+1)>1 ? 1>0 : 2<3", testData))
Assert.assertEquals(
2f,
Expand All @@ -254,10 +262,12 @@ class GXAnalyzeTest {
@Test
fun divide_calculate() {
repeat(100) {
Assert.assertEquals(-0.5f, instance.getResult("-1/2", testData))
Assert.assertEquals(0.5f, instance.getResult("1/2", testData))
Assert.assertEquals(1f, instance.getResult("1/1", testData))
Assert.assertEquals(1f, instance.getResult("-1/-1", testData))
Assert.assertEquals(-0.5f, instance.getResult("-1.0/2.0", testData))
Assert.assertEquals(0L, instance.getResult("-1/2", testData))
Assert.assertEquals(0.5f, instance.getResult("1.0/2", testData))
Assert.assertEquals(0L, instance.getResult("1/2", testData))
Assert.assertEquals(1L, instance.getResult("1/1", testData))
Assert.assertEquals(1L, instance.getResult("-1/-1", testData))
Assert.assertEquals(-8f, instance.getResult("\$data/-1", testData))
Assert.assertEquals(1f, instance.getResult("\$data/\$data", testData))
}
Expand All @@ -267,22 +277,22 @@ class GXAnalyzeTest {
@Test
fun multi_calculate() {
repeat(100) {
Assert.assertEquals(8f, instance.getResult("1+1*2+3+4/2", testData))
Assert.assertEquals(-1f, instance.getResult("(1+1-3)", testData))
Assert.assertEquals(-2f, instance.getResult("(1+1)-2*2", testData))
Assert.assertEquals(-4f, instance.getResult("(1-3)*2", testData))
Assert.assertEquals(4f, instance.getResult("1+1*3", testData))
Assert.assertEquals(4f, instance.getResult("1+2*3/2", testData))
Assert.assertEquals(4f, instance.getResult("(1+1)*2", testData))
Assert.assertEquals(2f, instance.getResult("(1+3)/2", testData))
Assert.assertEquals(8L, instance.getResult("1+1*2+3+4/2", testData))
Assert.assertEquals(-1L, instance.getResult("(1+1-3)", testData))
Assert.assertEquals(-2L, instance.getResult("(1+1)-2*2", testData))
Assert.assertEquals(-4L, instance.getResult("(1-3)*2", testData))
Assert.assertEquals(4L, instance.getResult("1+1*3", testData))
Assert.assertEquals(4L, instance.getResult("1+2*3/2", testData))
Assert.assertEquals(4L, instance.getResult("(1+1)*2", testData))
Assert.assertEquals(2L, instance.getResult("(1+3)/2", testData))
}
}

@Test
fun single_op_expression() {
repeat(100) {
Assert.assertEquals(1f, instance.getResult("+1", testData))
Assert.assertEquals(-1f, instance.getResult("-1", testData))
Assert.assertEquals(1L, instance.getResult("+1", testData))
Assert.assertEquals(-1L, instance.getResult("-1", testData))
Assert.assertEquals(true, instance.getResult("!false", testData))
Assert.assertEquals(false, instance.getResult("!true", testData))
}
Expand Down Expand Up @@ -363,21 +373,21 @@ class GXAnalyzeTest {
fun ternary() {
repeat(100) {
Assert.assertEquals(null, instance.getResult("false ? \$data : null", testData))
Assert.assertEquals(0f, instance.getResult("false ? 1 : 0", testData))
Assert.assertEquals(1f, instance.getResult("\$data ? 1 : 0", testData))
Assert.assertEquals(1f, instance.getResult("true ? 1 : 0", testData))
Assert.assertEquals(1f, instance.getResult("true ? 1 : 0", testData))
Assert.assertEquals(0L, instance.getResult("false ? 1 : 0", testData))
Assert.assertEquals(1L, instance.getResult("\$data ? 1 : 0", testData))
Assert.assertEquals(1L, instance.getResult("true ? 1 : 0", testData))
Assert.assertEquals(1L, instance.getResult("true ? 1 : 0", testData))
Assert.assertEquals(true, instance.getResult("true ?: 1", testData))
Assert.assertEquals(1f, instance.getResult("false ?: 1", testData))
Assert.assertEquals(1L, instance.getResult("false ?: 1", testData))
Assert.assertEquals(true, instance.getResult("true ?: \$data", testData))
Assert.assertEquals("123", instance.getResult("true ? '123' : '456'", testData))
Assert.assertEquals("123", instance.getResult("'true' ? '123' : '456'", testData))
Assert.assertEquals(null, instance.getResult("true ? null : \$data", testData))
Assert.assertEquals(1f, instance.getResult("false ? \$\$ : 1", testData))
Assert.assertEquals(1L, instance.getResult("false ? \$\$ : 1", testData))
Assert.assertEquals(testData, instance.getResult("true ? \$\$ : 1", testData))
Assert.assertEquals(testData, instance.getResult("\$\$ ?: 0", testData))
Assert.assertEquals(1f, instance.getResult("\$data.true?1:2", testData))
Assert.assertEquals(2f, instance.getResult("\$data.false?1:2", testData))
Assert.assertEquals(1L, instance.getResult("\$data.true?1:2", testData))
Assert.assertEquals(2L, instance.getResult("\$data.false?1:2", testData))
// Assert.assertEquals(2f, instance.getResult("($$!=null)?size($$):0", testData))
}
}
Expand Down
3 changes: 2 additions & 1 deletion GaiaXAnalyze/GXAnalyzeAndroid/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
)

#编译包大小优化选项 如表达式需要debug,请把以下三个编译选项注释掉
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Oz -flto -fdata-sections -ffunction-sections")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Oz -flto -fdata-sections -ffunction-sections")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -O3 -flto -Wl,--gc-sections -Wl")
Expand All @@ -25,7 +26,7 @@ add_library( # Sets the name of the library.

# Provides a relative path to your source file(s).
GXJniAnalyze.cpp
JniHelp.cpp)
)

# 链接头文件
target_include_directories(${PROJECT_NAME} PRIVATE
Expand Down
14 changes: 14 additions & 0 deletions GaiaXAnalyze/GXAnalyzeAndroid/src/main/cpp/GXJniAnalyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,18 @@ JNIEXPORT void JNICALL
Java_com_alibaba_gaiax_analyze_GXAnalyze_00024Companion_releaseGXValue(JNIEnv *env, jobject thiz,
jlong value) {
releaseGXValue(value);
}
extern "C"
JNIEXPORT jlong JNICALL
Java_com_alibaba_gaiax_analyze_GXAnalyze_00024Companion_getValueLong(JNIEnv *env, jobject thiz,
jlong value) {
GXValue *val = (GXValue *) value;
return (jlong) GX_VALUE_GET_LONG(*val);
}
extern "C"
JNIEXPORT jlong JNICALL
Java_com_alibaba_gaiax_analyze_GXAnalyze_00024Companion_createValueLong(JNIEnv *env, jobject thiz,
jlong value) {
GXValue *result = new GXValue(GX_TAG_LONG, (int64_t)value);
return (jlong) result;
}
Loading