Skip to content

Commit ba4f8b9

Browse files
committed
修改
1 parent 8aae74b commit ba4f8b9

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

csharp/ToolGood.Algorithm2.Test/AlgorithmEngine/AlgorithmEngineTest_flow.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,43 @@ public void iferror_test()
3636
t = engine.TryEvaluate("iferror(1-'rrr',1,2)", 0);
3737
Assert.AreEqual(1, t);
3838
}
39-
39+
40+
[Test]
41+
public void iserror_test()
42+
{
43+
AlgorithmEngine engine = new AlgorithmEngine();
44+
var t = engine.TryEvaluate("iserror(1/0,1)", 0);
45+
Assert.AreEqual(1, t);
46+
47+
t = engine.TryEvaluate("iserror(1-'rrr',1)", 0);
48+
Assert.AreEqual(1, t);
49+
}
50+
[Test]
51+
public void ifnull_test()
52+
{
53+
AlgorithmEngine engine = new AlgorithmEngine();
54+
var t = engine.TryEvaluate("isnull(null,1)", 0);
55+
Assert.AreEqual(1, t);
56+
57+
t = engine.TryEvaluate("isnull(1,2)", 0);
58+
Assert.AreEqual(1, t);
59+
}
60+
61+
[Test]
62+
public void isnullorerror_test()
63+
{
64+
AlgorithmEngine engine = new AlgorithmEngine();
65+
var t = engine.TryEvaluate("isnullorerror(null,1)", 0);
66+
Assert.AreEqual(1, t);
67+
68+
t = engine.TryEvaluate("isnullorerror(1/0,1)", 0);
69+
Assert.AreEqual(1, t);
70+
71+
t = engine.TryEvaluate("isnullorerror(1,2)", 0);
72+
Assert.AreEqual(1, t);
73+
}
74+
75+
4076

4177
[Test]
4278
public void ISNUMBER_test()
@@ -229,7 +265,7 @@ public void andor_Test()
229265

230266
}
231267

232-
268+
233269

234270

235271
}

csharp/ToolGood.Algorithm2/AlgorithmEngine.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ public string TryEvaluate(string exp, string def)
220220
try
221221
{
222222
var obj = Evaluate();
223+
if (obj.IsNull) {
224+
return null;
225+
}
223226
obj = obj.ToString("");
224227
if (obj.IsError)
225228
{

csharp/ToolGood.Algorithm2/Operand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public static Operand Create(double obj)
4343
}
4444
public static Operand Create(string obj)
4545
{
46+
if (object.Equals(null,obj)) {
47+
return Operand.CreateNull();
48+
}
4649
return new OperandString(obj);
4750
}
4851
public static Operand CreateJson(string txt)
@@ -202,7 +205,7 @@ public Operand ToArray(string errorMessage)
202205
list.Add(Operand.Create(double.Parse(v.ToString(), NumberStyles.Any, cultureInfo)));
203206
else if (v.IsLong)
204207
list.Add(Operand.Create(double.Parse(v.ToString(), NumberStyles.Any, cultureInfo)));
205-
else if (v.IsLong)
208+
else if (v.IsNull)
206209
list.Add(Operand.CreateNull());
207210
else
208211
list.Add(Operand.Create(v));
@@ -213,7 +216,6 @@ public Operand ToArray(string errorMessage)
213216
return Error(errorMessage);
214217
}
215218

216-
217219
public void Dispose() { }
218220
}
219221
public abstract class Operand<T> : Operand

0 commit comments

Comments
 (0)