📄 testparser.java
字号:
}
public void testMatrix03() {
double[][] dr = {{1.0, 4.0, 3.0},{3.0, 4.0, 5.0}};
ml.executeExpression("a=4");
ml.executeExpression("d=[1 a 3\n3,4,5]");
assertTrue(Compare.ArrayEquals(dr, ml.getArrayValueRe("d")));
}
public void testMatrix04() {
double[][] dr = {{1.0, 2.0, 3.0, 4.0}};
ml.executeExpression("d=[1 2 3 ,4]");
assertTrue(Compare.ArrayEquals(dr, ml.getArrayValueRe("d")));
}
public void testMatrix05() {
double[][] dr = {{1.0, -5.0, 3.0},{3.0, 4.0, 5.0}};
ml.executeExpression("d=[1 2-7 3\n3,4,5]");
assertTrue(Compare.ArrayEquals(dr, ml.getArrayValueRe("d")));
}
public void testMatrix06() {
double[][] dr = {{2.0, -5.0, 11.0},{3.0, 4.0, 11.0}};
ml.executeExpression("a=2;b=3;c=11;");
ml.executeExpression("d=[a 2-7 c\n b,4,c]");
assertTrue(Compare.ArrayEquals(dr, ml.getArrayValueRe("d")));
}
public void testMatrix07() {
double[][] dr = {{1.0, 5.0, 3.0, 4.0}};
ml.executeExpression("d=[1 min(5, 6 ) 3 ,4]");
assertTrue(Compare.ArrayEquals(dr, ml.getArrayValueRe("d")));
}
public void testMatrix08() {
// there has been a bug when parsing " ]" the trailing "]" has not been recognized
double[][] dr = {{5.0, 6.0, 4.0}};
ml.executeExpression("dd=[5,6,4 ]");
assertTrue(Compare.ArrayEquals(dr, ml.getArrayValueRe("dd")));
}
public void testMatrix09() {
// there has been a bug when parsing " ]" the trailing "]" has not been recognized
double[][] dr = {{2.0, 6.0, 8.0}};
ml.executeExpression("[2, 6,8 ]");
assertTrue(Compare.ArrayEquals(dr, ml.getArrayValueRe("ans")));
}
public void testMatrix10() {
// there has been a bug when parsing " ]" the trailing "]" has not been recognized
double[][] dr = {{1.0, 6.0, 8.0}};
ml.executeExpression(" [ 1,6 ,8 ]");
assertTrue(Compare.ArrayEquals(dr, ml.getArrayValueRe("ans")));
}
public void testMatrix11() {
// there has been a bug when parsing " ]" the trailing "]" has not been recognized
double[][] dr = {{5.0, 6.0, 7.0}};
ml.executeExpression("[ 5, 6 , 7 ] ");
assertTrue(Compare.ArrayEquals(dr, ml.getArrayValueRe("ans")));
}
public void testMatrix12() {
// there has been a bug when parsing " ]" the trailing "]" has not been recognized
double[][] dr = {{5.0, 6.0, 9.0}};
ml.executeExpression("[5, 6 9 ]");
assertTrue(Compare.ArrayEquals(dr, ml.getArrayValueRe("ans")));
}
// bugfix for: sin(1-1)' had been throwing an error
public void testUnaryOperator01() {
ml.executeExpression("a=sin(1-1)';");
assertEquals(0.0, ml.getScalarValueRe("a"), 0.001);
}
public void testUnaryOperator02() {
double[][] dr = {{5.0, 6.0, 9.0}};
ml.executeExpression("a=[5;6;9]'");
assertTrue(Compare.ArrayEquals(dr, ml.getArrayValueRe("a")));
}
public void testUnaryOperator03() {
// testcase for bug: a=[m]' threw an error
double[][] dr = {{5.0},{ 3.0}};
ml.executeExpression("m=3");
ml.executeExpression("a=[5,m]'");
assertTrue(Compare.ArrayEquals(dr, ml.getArrayValueRe("a")));
}
/************** funtions ***********/
public void testFunctionParameters01() {
ml.throwErrorsB=true;
try {
ml.executeExpression("m=ceil(45) ");
}
catch (Exception e)
{
assertTrue(false);
return;
}
assertTrue(true);
}
public void testFunctionParameters02() {
// BUG1523328: ceil(4;5] did not throw an error, neither
// did ceil(4;5)
ml.throwErrorsB=true;
try {
ml.executeExpression("m=ceil(4;5) ");
}
catch (Exception e)
{
assertTrue(true);
return;
}
assertTrue(false);
}
public void testFunctionParameters03() {
ml.executeExpression("a=ceil(4.5);");
assertEquals(5.0, ml.getScalarValueRe("a"), 0.001);
}
public void testOperatorParsing01() {
ml.throwErrorsB=true;
try {
ml.executeExpression("m=+-44 ");
}
catch (Exception e)
{
assertTrue(false);
return;
}
assertEquals(-44.0, ml.getScalarValueRe("m"), 0.001);
}
public void testOperatorParsing02() {
ml.throwErrorsB=true;
try {
ml.executeExpression("m=*4 ");
}
catch (Exception e)
{
assertTrue(true);
return;
}
assertTrue(false);
}
public void testOperatorParsing03() {
ml.throwErrorsB=true;
try {
ml.executeExpression("m=3-*4 ");
}
catch (Exception e)
{
assertTrue(true);
return;
}
assertTrue(false);
}
public void testOperatorParsing04() {
ml.throwErrorsB=true;
try {
ml.executeExpression("m=*4 ");
}
catch (Exception e)
{
assertTrue(true);
return;
}
assertTrue(false);
}
public void testOperatorParsing05a() {
ml.throwErrorsB=true;
try {
ml.executeExpression("A=4;B=/4; ");
}
catch (Exception e)
{
assertTrue(true);
return;
}
assertTrue(false);
}
public void testOperatorParsing05b() {
ml.throwErrorsB=true;
try {
ml.executeExpression("+/4; ");
}
catch (Exception e)
{
assertTrue(true);
return;
}
assertTrue(false);
}
public void testOperatorParsing05c() {
ml.throwErrorsB=true;
try {
ml.executeExpression("*/4; ");
}
catch (Exception e)
{
assertTrue(true);
return;
}
assertTrue(false);
}
public void testOperatorParsing06a() {
ml.throwErrorsB=true;
try {
ml.executeExpression("m=-+-++4; ");
}
catch (Exception e)
{
assertTrue(false);
return;
}
assertEquals(4.0, ml.getScalarValueRe("m"), 0.001);
}
public void testOperatorParsing06b() {
ml.throwErrorsB=true;
try {
ml.executeExpression("m=-+++46; ");
}
catch (Exception e)
{
assertTrue(false);
return;
}
assertEquals(-46.0, ml.getScalarValueRe("m"), 0.001);
}
public void testOperatorParsing06c() {
ml.throwErrorsB=true;
try {
ml.executeExpression("b=99;m=---b; ");
}
catch (Exception e)
{
assertTrue(false);
return;
}
assertEquals(-99.0, ml.getScalarValueRe("m"), 0.001);
}
// =^7 +^3 -^6 *^5 ^^5 !^7
public void testOperatorParsing07() {
ml.throwErrorsB=true;
try {
ml.executeExpression("a=^7");
}
catch (Exception e)
{
assertTrue(true);
return;
}
assertTrue(false);
}
public void testOperatorParsing08() {
ml.throwErrorsB=true;
try {
ml.executeExpression("+^8");
}
catch (Exception e)
{
assertTrue(true);
return;
}
assertTrue(false);
}
public void testOperatorParsing09() {
ml.throwErrorsB=true;
try {
ml.executeExpression("-^7");
}
catch (Exception e)
{
assertTrue(true);
return;
}
assertTrue(false);
}
public void testOperatorParsing10() {
ml.throwErrorsB=true;
try {
ml.executeExpression("*^7");
ml.executeExpression("/^7");
}
catch (Exception e)
{
assertTrue(true);
return;
}
assertTrue(false);
}
public void testOperatorParsing11() {
ml.throwErrorsB=true;
try {
ml.executeExpression("^^7");
}
catch (Exception e)
{
assertTrue(true);
return;
}
assertTrue(false);
}
// -(--+++-3-5)
public void testOperatorParsing06d() {
ml.throwErrorsB=true;
try {
ml.executeExpression("-(--+++-+3-5); ");
}
catch (Exception e)
{
assertTrue(false);
return;
}
assertEquals(8.0, ml.getScalarValueRe("ans"), 0.001);
}
/*************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -