Skip to content

Commit

Permalink
Fix some bugs (#103)
Browse files Browse the repository at this point in the history
* fix some bugs

* optimize the code

* optimize code to resolve possible error for para parsing
  • Loading branch information
aressu1985 authored Sep 6, 2022
1 parent 3696027 commit ebb8ee1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
Binary file modified lib/mo-tester-1.0-SNAPSHOT.jar
Binary file not shown.
29 changes: 29 additions & 0 deletions src/main/java/io/mo/Tester.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,31 @@ public static void main(String[] args){
//get path
if (arg.startsWith("path")) {
path = arg.split("=")[1];
File caseFile = new File(path);
String srcPath = null;
if(caseFile.getAbsolutePath().contains(COMMON.CASES_DIR)) {
srcPath = caseFile.getAbsolutePath();
srcPath = srcPath.replace(COMMON.CASES_DIR,COMMON.RESOURCE_DIR);
srcPath = srcPath.substring(0,srcPath.indexOf(COMMON.RESOURCE_DIR)+COMMON.RESOURCE_DIR.length());
}
COMMON.RESOURCE_PATH = srcPath;
}

//get method
if (arg.startsWith("method")) {
if(!arg.contains("=")){
LOG.error("The format of para[method] is not valid,please check......");
System.exit(1);
}
method = arg.split("=")[1];
}

//get sucess rate
if (arg.startsWith("rate")) {
if(!arg.contains("=")){
LOG.error("The format of para[rate] is not valid,please check......");
System.exit(1);
}
rate = Integer.parseInt(arg.split("=")[1]);
}

Expand All @@ -52,16 +68,29 @@ public static void main(String[] args){

//get includes
if (arg.startsWith("include")) {
if(!arg.contains("=")){
LOG.error("The format of para[include] is not valid,please check......");
System.exit(1);
}
includes = arg.split("=")[1].split(",");
}

//get excludes
if (arg.startsWith("exclude")) {
if(!arg.contains("=")){
LOG.error("The format of para[include] is not valid,please check......");
System.exit(1);
}
excludes = arg.split("=")[1].split(",");
}

//get resource path
if (arg.startsWith("resource")) {
if(!arg.contains("=")){
LOG.error("The format of para[resource] is not valid,please check......");
System.exit(1);
}

COMMON.RESOURCE_PATH = arg.split("=")[1];
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/mo/db/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static void run(TestScript script){
"[ACTUAL RESULT]:\n" + command.getTestResult().getExpResult() + "\n");
LOG.error("[" + script.getFileName() + "][row:" + command.getPosition() + "][" + command.getCommand().trim() + "] was executed failed");
LOG.error("[EXPECT RESULT]:\n" + command.getTestResult().getExpResult());
LOG.error("[ACTUAL RESULT]:\n" + command.getTestResult().getExpResult());
LOG.error("[ACTUAL RESULT]:\n" + command.getTestResult().getActResult());
continue;
}

Expand Down Expand Up @@ -138,7 +138,7 @@ public static void run(TestScript script){
"[ACTUAL RESULT]:\n" + command.getTestResult().getExpResult() + "\n");
LOG.error("[" + script.getFileName() + "][row:" + command.getPosition() + "][" + command.getCommand().trim() + "] was executed failed");
LOG.error("[EXPECT RESULT]:\n" + command.getTestResult().getExpResult());
LOG.error("[ACTUAL RESULT]:\n" + command.getTestResult().getExpResult());
LOG.error("[ACTUAL RESULT]:\n" + command.getTestResult().getActResult());
continue;
}

Expand Down
14 changes: 13 additions & 1 deletion src/main/java/io/mo/result/RSCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,32 @@ public boolean equals(RSCell cell){
//precision toleration code
String v1 = (String)this.value;
String v2 = (String)cell.getValue();

//if one is NULL,return false
if(v1.equalsIgnoreCase("null") || v2.equalsIgnoreCase("null"))
return false;


if(cell.type == Types.FLOAT ||
cell.type == Types.REAL ||
cell.type == Types.DOUBLE||
cell.type == Types.DECIMAL||
cell.type == Types.BIGINT ||
(cell.type == Types.VARCHAR && isNumeric(v1) &&isNumeric(v2))) {


BigDecimal bd1 = BigDecimal.valueOf(Double.valueOf(v1)).stripTrailingZeros();
BigDecimal bd2 = BigDecimal.valueOf(Double.valueOf(v2)).stripTrailingZeros();
//System.out.println("bd1 = " + bd1);
//System.out.println("bd2 = " + bd2);


if(bd1.compareTo(bd2) == 0)
return true;
else{
if(bd1.equals(BigDecimal.ZERO) || bd2.equals(BigDecimal.ZERO))
return false;
}

//round to one with samll scale, and compare
int scal1 = bd1.scale();
Expand All @@ -90,7 +102,7 @@ public boolean equals(RSCell cell){
LOG.debug("value[" + v1 +"] and value[" + v2 +"] match the scale tolerable error");
return true;
}

error = error.divide(bd1,BigDecimal.ROUND_HALF_UP);
toleration = BigDecimal.valueOf(COMMON.INT_TOLERABLE_ERROR);
//if error beteen bd1 and bd2 divided bd1 or db2 is less than INT_TOLERABLE_ERROR(0.0.000000000000001),return true;
Expand Down

0 comments on commit ebb8ee1

Please sign in to comment.