[#34] Third step of not using Bio as Attribute
This commit is contained in:
@ -9,11 +9,13 @@ namespace Tests.HelperTests {
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOpts = new() { WriteIndented = true };
|
||||
private static readonly RawVaribute[] Vaributes = [
|
||||
new("GV/"), new("GV/D"), new("GV/K"), new("GV/S"), new("GV/Z"),
|
||||
new("WR/"), new("WR/S"), new("ZW/"), new("ZW/S"), new("ZW/Z")];
|
||||
new("GV/-"), new("GV/D-"), new("GV/K-"), new("GV/S-"), new("GV/Z-"),
|
||||
new("WR/-"), new("WR/S-"), new("ZW/-"), new("ZW/S-"), new("ZW/Z-"),
|
||||
new("GV/-B"), new("WR/-B"), new("ZW/-B"), new("ZW/S-B"), new("GV/S-B"), new("GV/K-B")];
|
||||
|
||||
private static (string, string?) GetSortIdAttrId(string bucket) {
|
||||
return (bucket[..2], bucket.Length > 2 ? bucket[2..] : null);
|
||||
private static (string, string?, string?) GetSortIdAttrId(string bucket) {
|
||||
var v = bucket.Split('-');
|
||||
return (v[0][..2], v[0].Length > 2 ? v[0][2..] : null, v.Length > 1 ? v[1] : null);
|
||||
}
|
||||
|
||||
private static string GetQualId(double kmw) {
|
||||
@ -27,16 +29,16 @@ namespace Tests.HelperTests {
|
||||
}
|
||||
|
||||
private static void TestCalcOe(PaymentBillingData data, string bucket, double oe, decimal expected, string? qualid = null, bool geb = false) {
|
||||
var (sortid, attrid) = GetSortIdAttrId(bucket);
|
||||
var (sortid, attrid, cultid) = GetSortIdAttrId(bucket);
|
||||
var kmw = Utils.OeToKmw(oe);
|
||||
var v = data.CalculatePrice(sortid, attrid, qualid ?? GetQualId(kmw), geb, oe, kmw);
|
||||
var v = data.CalculatePrice(sortid, attrid, cultid, qualid ?? GetQualId(kmw), geb, oe, kmw);
|
||||
Assert.That(Math.Round(v, 6), Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
private static void TestCalcKmw(PaymentBillingData data, string bucket, double kmw, decimal expected, string? qualid = null, bool geb = false) {
|
||||
var (sortid, attrid) = GetSortIdAttrId(bucket);
|
||||
var (sortid, attrid, cultid) = GetSortIdAttrId(bucket);
|
||||
var oe = Utils.KmwToOe(kmw);
|
||||
var v = data.CalculatePrice(sortid, attrid, qualid ?? GetQualId(kmw), geb, oe, kmw);
|
||||
var v = data.CalculatePrice(sortid, attrid, cultid, qualid ?? GetQualId(kmw), geb, oe, kmw);
|
||||
Assert.That(Math.Round(v, 6), Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
@ -161,7 +163,40 @@ namespace Tests.HelperTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRead_05_QualityLevel() {
|
||||
public void TestRead_05_Cultivations() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
"version": 1,
|
||||
"payment": {
|
||||
"default": 0.10,
|
||||
"-B": 0.20,
|
||||
"/S": 0.30
|
||||
},
|
||||
"curves": []
|
||||
}
|
||||
""", Vaributes);
|
||||
Assert.Multiple(() => {
|
||||
TestCalcOe(data, "WR", 73, 0.10m);
|
||||
TestCalcOe(data, "WR-B", 73, 0.20m);
|
||||
TestCalcOe(data, "WRS", 73, 0.30m);
|
||||
TestCalcOe(data, "GV", 73, 0.10m);
|
||||
TestCalcOe(data, "GV-B", 73, 0.20m);
|
||||
TestCalcOe(data, "GVD", 73, 0.10m);
|
||||
TestCalcOe(data, "GVK", 73, 0.10m);
|
||||
TestCalcOe(data, "GVK-B", 73, 0.20m);
|
||||
TestCalcOe(data, "GVS", 73, 0.30m);
|
||||
TestCalcOe(data, "GVS-B", 73, 0.30m);
|
||||
TestCalcOe(data, "GVZ", 73, 0.10m);
|
||||
TestCalcOe(data, "ZW", 73, 0.10m);
|
||||
TestCalcOe(data, "ZW-B", 73, 0.20m);
|
||||
TestCalcOe(data, "ZWS", 73, 0.30m);
|
||||
TestCalcOe(data, "ZWZ", 73, 0.10m);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRead_06_QualityLevel() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -192,7 +227,7 @@ namespace Tests.HelperTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRead_06_ModeOeAndKmw() {
|
||||
public void TestRead_07_ModeOeAndKmw() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -234,7 +269,7 @@ namespace Tests.HelperTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRead_07_MultipleCurves() {
|
||||
public void TestRead_08_MultipleCurves() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -303,7 +338,7 @@ namespace Tests.HelperTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRead_08_WgMaster() {
|
||||
public void TestRead_09_WgMaster() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "wgmaster",
|
||||
@ -346,6 +381,30 @@ namespace Tests.HelperTests {
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRead_10_AttrubteAndCultivation() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
"version": 1,
|
||||
"payment": {
|
||||
"default": 0.10,
|
||||
"/S": 0.20,
|
||||
"-B": 0.30,
|
||||
"GV/S-B": 0.40
|
||||
},
|
||||
"curves": []
|
||||
}
|
||||
""", Vaributes);
|
||||
Assert.Multiple(() => {
|
||||
TestCalcOe(data, "GV", 73, 0.10m);
|
||||
TestCalcOe(data, "GVS", 73, 0.20m);
|
||||
TestCalcOe(data, "GV-B", 73, 0.30m);
|
||||
TestCalcOe(data, "GVS-B", 73, 0.40m);
|
||||
TestCalcOe(data, "ZWS-B", 73, 0.20m);
|
||||
});
|
||||
}
|
||||
|
||||
private static List<Varibute> GetSelection(IEnumerable<string> attVars) {
|
||||
return attVars.Select(s => new Varibute(new RawVaribute(s))).ToList();
|
||||
}
|
||||
@ -373,7 +432,7 @@ namespace Tests.HelperTests {
|
||||
List<GraphEntry> entries = [
|
||||
new GraphEntry(0, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.5m
|
||||
}, null), GetSelection(["GV/"]))
|
||||
}, null), GetSelection(["GV/-"]))
|
||||
];
|
||||
var data = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(data.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
@ -392,7 +451,7 @@ namespace Tests.HelperTests {
|
||||
new GraphEntry(0, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.5m,
|
||||
[83] = 1.0m
|
||||
}, null), GetSelection(["GV/"]))
|
||||
}, null), GetSelection(["GV/-"]))
|
||||
];
|
||||
var data = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(data.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
@ -420,10 +479,10 @@ namespace Tests.HelperTests {
|
||||
new GraphEntry(0, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.5m,
|
||||
[84] = 1.0m
|
||||
}, null), GetSelection(["GV/", "ZW/"])),
|
||||
}, null), GetSelection(["GV/-", "ZW/-"])),
|
||||
new GraphEntry(10, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.75m,
|
||||
}, null), GetSelection(["WR/"]))
|
||||
}, null), GetSelection(["WR/-"]))
|
||||
];
|
||||
var data = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(data.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
@ -454,14 +513,14 @@ namespace Tests.HelperTests {
|
||||
new GraphEntry(0, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.5m,
|
||||
[84] = 1.0m
|
||||
}, null), GetSelection(["GV/B", "ZW/B"])),
|
||||
}, null), GetSelection(["GV/K-", "ZW/K-"])),
|
||||
new GraphEntry(2, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.75m,
|
||||
}, null), GetSelection(["WR/", "BL/", "RR/", "FV/"])),
|
||||
}, null), GetSelection(["WR/-", "BL/-", "RR/-", "FV/-"])),
|
||||
new GraphEntry(4, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.65m,
|
||||
[84] = 1.2m
|
||||
}, null), GetSelection(["BP/", "SA/"]))
|
||||
}, null), GetSelection(["BP/-", "SA/-"]))
|
||||
];
|
||||
var data = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(data.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
@ -472,7 +531,7 @@ namespace Tests.HelperTests {
|
||||
"BP/": "curve:2",
|
||||
"SA/": "curve:2",
|
||||
"default": 0.75,
|
||||
"/B": "curve:1"
|
||||
"/K": "curve:1"
|
||||
},
|
||||
"curves": [
|
||||
{
|
||||
@ -495,5 +554,85 @@ namespace Tests.HelperTests {
|
||||
}
|
||||
"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWrite_06_Cultivation() {
|
||||
List<GraphEntry> entries = [
|
||||
new GraphEntry(0, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.5m,
|
||||
[84] = 1.0m
|
||||
}, null), GetSelection(["GV/-B", "ZW/-B"])),
|
||||
new GraphEntry(2, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.75m,
|
||||
}, null), GetSelection(["WR/-", "BL/-", "RR/-", "FV/-"])),
|
||||
new GraphEntry(4, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.65m,
|
||||
[84] = 1.2m
|
||||
}, null), GetSelection(["BP/-", "SA/-"]))
|
||||
];
|
||||
var data = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(data.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
"version": 1,
|
||||
"payment": {
|
||||
"BP/": "curve:2",
|
||||
"SA/": "curve:2",
|
||||
"default": 0.75,
|
||||
"-B": "curve:1"
|
||||
},
|
||||
"curves": [
|
||||
{
|
||||
"id": 1,
|
||||
"mode": "oe",
|
||||
"data": {
|
||||
"73oe": 0.5,
|
||||
"84oe": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"mode": "oe",
|
||||
"data": {
|
||||
"73oe": 0.65,
|
||||
"84oe": 1.2
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWrite_07_AttributeAndCultivation() {
|
||||
List<GraphEntry> entries = [
|
||||
new GraphEntry(0, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.75m,
|
||||
}, null), GetSelection(["GV/-", "ZW/-", "WR/-", "RR/-", "BL/-", "BP/-", "FV/-"])),
|
||||
new GraphEntry(2, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.3m,
|
||||
}, null), GetSelection(["GV/S-", "ZW/S-"])),
|
||||
new GraphEntry(4, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.2m,
|
||||
}, null), GetSelection(["GV/-B", "ZW/-B"])),
|
||||
new GraphEntry(4, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.4m,
|
||||
}, null), GetSelection(["GV/S-B", "ZW/S-B"]))
|
||||
];
|
||||
var data = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(data.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
"version": 1,
|
||||
"payment": {
|
||||
"default": 0.75,
|
||||
"/S": 0.3,
|
||||
"-B": 0.2,
|
||||
"/S-B": 0.4
|
||||
},
|
||||
"curves": []
|
||||
}
|
||||
"""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user