Skip to content

Commit deb227d

Browse files
committed
修改类名
1 parent 7d93e10 commit deb227d

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

csharp/ToolGood.Algorithm2.Test/AlgorithmEngineEx/AlgorithmEngineExTest.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class AlgorithmEngineExTest
1414
[Test]
1515
public void Test()
1616
{
17-
MultiConditionCache multiConditionCache = new MultiConditionCache();
17+
ConditionCache multiConditionCache = new ConditionCache();
1818
multiConditionCache.AddFormula("桌面积", "[圆桌]", "[半径]*[半径]*pi()");
1919
multiConditionCache.AddFormula("桌面积", "[方桌]", "[长]*[宽]");
2020

@@ -64,7 +64,26 @@ public void Test()
6464

6565
var p4 = priceAlgorithm.TryEvaluate("出错了", 0.0);
6666

67-
67+
}
68+
69+
[Test]
70+
public void Test2()
71+
{
72+
ConditionCache multiConditionCache = new ConditionCache();
73+
multiConditionCache.AddCondition("类型", "[方桌]&& [长]<1.3", "1");
74+
multiConditionCache.AddCondition("类型", "[方桌]&& [长]<2", "2");
75+
multiConditionCache.AddCondition("类型", "[方桌]&& [长]<5", "3");
76+
multiConditionCache.AddCondition("类型", "[方桌]&& [长]<7", "4");
77+
78+
Desk desk = new Desk() {
79+
IsRoundTable = false,
80+
Length = 3,
81+
Width = 1.3,
82+
Heigth = 1
83+
};
84+
PriceAlgorithm priceAlgorithm = new PriceAlgorithm(multiConditionCache, desk);
85+
var p1 = priceAlgorithm.QueryRemark("类型");
86+
Assert.AreEqual("3", p1);
6887
}
6988

7089

@@ -83,7 +102,7 @@ public class Desk
83102
public class PriceAlgorithm : ToolGood.Algorithm.AlgorithmEngineEx
84103
{
85104
private Desk _disk;
86-
public PriceAlgorithm(MultiConditionCache multiConditionCache, Desk desk) : base(multiConditionCache)
105+
public PriceAlgorithm(ConditionCache multiConditionCache, Desk desk) : base(multiConditionCache)
87106
{
88107
_disk = desk;
89108
}

csharp/ToolGood.Algorithm2/AlgorithmEngineEx.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public class AlgorithmEngineEx
2929
/// <summary>
3030
/// 多条件缓存
3131
/// </summary>
32-
public MultiConditionCache MultiConditionCache { get; private set; }
32+
public ConditionCache MultiConditionCache { get; private set; }
3333

34-
public AlgorithmEngineEx(MultiConditionCache multiConditionCache)
34+
public AlgorithmEngineEx(ConditionCache multiConditionCache)
3535
{
3636
MultiConditionCache = multiConditionCache;
3737
}
@@ -141,7 +141,7 @@ public string QueryRemark(string categoryName)
141141
}
142142
return conditionCache.Remark;
143143
}
144-
return null;
144+
throw new Exception($"CategoryName [{categoryName}] is missing.");
145145
}
146146

147147

csharp/ToolGood.Algorithm2/MultiConditionalCache.cs renamed to csharp/ToolGood.Algorithm2/ConditionCache.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
namespace ToolGood.Algorithm
88
{
99
/// <summary>
10-
/// 多条件缓存
10+
/// 条件缓存
1111
/// </summary>
12-
public class MultiConditionCache
12+
public class ConditionCache
1313
{
14-
private Dictionary<string, List<ConditionCache>> conditionCaches = new Dictionary<string, List<ConditionCache>>();
14+
private Dictionary<string, List<Internals.ConditionCache>> conditionCaches = new Dictionary<string, List<Internals.ConditionCache>>();
1515
/// <summary>
1616
/// 最后一个错误
1717
/// </summary>
@@ -27,7 +27,7 @@ public class MultiConditionCache
2727
/// <returns></returns>
2828
public bool AddFormula(string categoryName, string condition, string formula, string remark = null)
2929
{
30-
ConditionCache conditionCache = new ConditionCache() {
30+
Internals.ConditionCache conditionCache = new Internals.ConditionCache() {
3131
CategoryName = categoryName,
3232
Remark = remark,
3333
ConditionString = condition,
@@ -46,9 +46,9 @@ public bool AddFormula(string categoryName, string condition, string formula, st
4646
}
4747
conditionCache.Formula = formulaProg;
4848

49-
List<ConditionCache> list;
49+
List<Internals.ConditionCache> list;
5050
if (conditionCaches.TryGetValue(categoryName, out list) == false) {
51-
list = new List<ConditionCache>();
51+
list = new List<Internals.ConditionCache>();
5252
conditionCaches[categoryName] = list;
5353
}
5454

@@ -66,7 +66,7 @@ public bool AddFormula(string categoryName, string condition, string formula, st
6666
/// <returns></returns>
6767
public bool AddCondition(string categoryName, string condition, string remark)
6868
{
69-
ConditionCache conditionCache = new ConditionCache() {
69+
Internals.ConditionCache conditionCache = new Internals.ConditionCache() {
7070
CategoryName = categoryName,
7171
Remark = remark,
7272
ConditionString = condition,
@@ -78,9 +78,9 @@ public bool AddCondition(string categoryName, string condition, string remark)
7878
}
7979
conditionCache.Condition = conditionProg;
8080
}
81-
List<ConditionCache> list;
81+
List<Internals.ConditionCache> list;
8282
if (conditionCaches.TryGetValue(categoryName, out list) == false) {
83-
list = new List<ConditionCache>();
83+
list = new List<Internals.ConditionCache>();
8484
conditionCaches[categoryName] = list;
8585
}
8686

@@ -118,11 +118,11 @@ private ProgContext Parse(string exp)
118118
return null;
119119
}
120120

121-
internal List<ConditionCache> GetConditionCaches(string name)
121+
internal List<Internals.ConditionCache> GetConditionCaches(string name)
122122
{
123-
List<ConditionCache> result;
123+
List<Internals.ConditionCache> result;
124124
if (conditionCaches.TryGetValue(name, out result) == false) {
125-
result = new List<ConditionCache>();
125+
result = new List<Internals.ConditionCache>();
126126
}
127127
return result;
128128
}

0 commit comments

Comments
 (0)