mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package cn.hutool.captcha.generator;
|
||||
|
||||
import cn.hutool.core.math.Calculator;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -59,20 +60,8 @@ public class MathGenerator implements CodeGenerator {
|
||||
return false;
|
||||
}
|
||||
|
||||
final int a = Integer.parseInt(StrUtil.sub(code, 0, this.numberLength).trim());
|
||||
final char operator = code.charAt(this.numberLength);
|
||||
final int b = Integer.parseInt(StrUtil.sub(code, this.numberLength + 1, this.numberLength + 1 + this.numberLength).trim());
|
||||
|
||||
switch (operator) {
|
||||
case '+':
|
||||
return (a + b) == result;
|
||||
case '-':
|
||||
return (a - b) == result;
|
||||
case '*':
|
||||
return (a * b) == result;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
final int calculateResult = (int) Calculator.conversion(code);
|
||||
return result == calculateResult;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,14 @@
|
||||
package cn.hutool.captcha;
|
||||
|
||||
import cn.hutool.captcha.generator.MathGenerator;
|
||||
import org.junit.Test;
|
||||
|
||||
public class GeneratorTest {
|
||||
@Test
|
||||
public void mathGeneratorTest(){
|
||||
final MathGenerator mathGenerator = new MathGenerator();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
mathGenerator.verify(mathGenerator.generate(), "0");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user