-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompatibilityAndSchemaEditModeTests.cs
More file actions
654 lines (554 loc) · 26 KB
/
CompatibilityAndSchemaEditModeTests.cs
File metadata and controls
654 lines (554 loc) · 26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using CoreAI.Crafting;
using Microsoft.Extensions.AI;
using NUnit.Framework;
namespace CoreAI.Tests.EditMode
{
/// <summary>
/// EditMode coverage for <see cref="CompatibilityChecker"/> and <see cref="JsonSchemaValidator"/>.
/// </summary>
public sealed class CompatibilityAndSchemaEditModeTests
{
// ═══════════════════════════════════════════════════
// CompatibilityChecker Tests
// ═══════════════════════════════════════════════════
[Test]
public void Compatibility_EmptyIngredients_ReturnsIncompatible()
{
CompatibilityChecker checker = new();
CompatibilityResult result = checker.Check(new List<string>());
Assert.IsFalse(result.IsCompatible);
Assert.AreEqual(0f, result.CompatibilityScore);
}
[Test]
public void Compatibility_SingleIngredient_ReturnsCompatible()
{
CompatibilityChecker checker = new();
CompatibilityResult result = checker.Check("IronOre");
Assert.IsTrue(result.IsCompatible);
Assert.AreEqual(1.0f, result.CompatibilityScore);
}
[Test]
public void Compatibility_TwoIngredients_NoRules_ReturnsDefault()
{
CompatibilityChecker checker = new(0.8f);
CompatibilityResult result = checker.Check("IronOre", "Coal");
Assert.IsTrue(result.IsCompatible);
Assert.AreEqual(0.8f, result.CompatibilityScore);
}
[Test]
public void Compatibility_PairRule_BlockingScore_ReturnsIncompatible()
{
CompatibilityChecker checker = new();
checker.AddRule("Fire", "Water", 0f, "Fire and Water cancel each other");
CompatibilityResult result = checker.Check("Fire", "Water");
Assert.IsFalse(result.IsCompatible);
Assert.AreEqual(0f, result.CompatibilityScore);
Assert.IsTrue(result.Warnings.Count > 0);
}
[Test]
public void Compatibility_PairRule_SynergyScore_ReturnsBonuses()
{
CompatibilityChecker checker = new();
checker.AddRule("Fire", "Earth", 1.5f, "Fire and Earth form lava");
CompatibilityResult result = checker.Check("Fire", "Earth");
Assert.IsTrue(result.IsCompatible);
Assert.Greater(result.CompatibilityScore, 1.0f);
Assert.IsTrue(result.Bonuses.Count > 0);
}
[Test]
public void Compatibility_PairRule_OrderIndependent()
{
CompatibilityChecker checker = new();
checker.AddRule("Fire", "Water", 0f, "Incompatible");
// Проверяем что порядок не важен
CompatibilityResult r1 = checker.Check("Fire", "Water");
CompatibilityResult r2 = checker.Check("Water", "Fire");
Assert.IsFalse(r1.IsCompatible);
Assert.IsFalse(r2.IsCompatible);
}
[Test]
public void Compatibility_GroupRule_ThreeElements_Matches()
{
CompatibilityChecker checker = new();
checker.AddGroupRule(1.8f, "Triple synergy: Fire+Earth+Air", "Fire", "Earth", "Air");
CompatibilityResult result = checker.Check("Fire", "Earth", "Air");
Assert.IsTrue(result.IsCompatible);
Assert.Greater(result.CompatibilityScore, 1.0f);
Assert.IsTrue(result.Bonuses.Count > 0);
}
[Test]
public void Compatibility_GroupRule_FourElements_Matches()
{
CompatibilityChecker checker = new();
checker.AddGroupRule(2.0f, "Master recipe: all four elements", "Fire", "Water", "Earth", "Air");
CompatibilityResult result = checker.Check("Fire", "Water", "Earth", "Air");
Assert.IsTrue(result.IsCompatible);
// Score capped at 2.0
Assert.AreEqual(2.0f, result.CompatibilityScore);
}
[Test]
public void Compatibility_GroupRule_DoesNotMatchSubset()
{
CompatibilityChecker checker = new();
checker.AddGroupRule(0f, "Four elements cancel out", "Fire", "Water", "Earth", "Air");
// Только 3 из 4 — правило на 4 не должно матчить
CompatibilityResult result = checker.Check("Fire", "Water", "Earth");
Assert.IsTrue(result.IsCompatible); // default score 1.0
}
[Test]
public void Compatibility_GroupRule_MatchesAsSubsetOfLargerInput()
{
CompatibilityChecker checker = new();
checker.AddGroupRule(1.5f, "Fire+Earth synergy", "Fire", "Earth");
// 3 ингредиента, но парное правило Fire+Earth всё равно матчит
CompatibilityResult result = checker.Check("Fire", "Earth", "Wind");
Assert.IsTrue(result.IsCompatible);
Assert.Greater(result.CompatibilityScore, 1.0f);
}
[Test]
public void Compatibility_GroupRule_LargerRuleHasMoreWeight()
{
CompatibilityChecker checker = new();
// Парное правило: Fire+Earth = 0.5 (плохо)
checker.AddRule("Fire", "Earth", 0.5f, "Pair: weak");
// Тройное правило: Fire+Earth+Air = 1.8 (синергия, перевешивает)
checker.AddGroupRule(1.8f, "Triple: synergy!", "Fire", "Earth", "Air");
CompatibilityResult result = checker.Check("Fire", "Earth", "Air");
Assert.IsTrue(result.IsCompatible);
// Тройное правило весит 3 сравнительно с парным весом 2
// (0.5*2 + 1.8*3) / (2+3) = (1.0 + 5.4) / 5 = 1.28
Assert.Greater(result.CompatibilityScore, 1.0f, "Triple rule should outweigh pair rule");
}
[Test]
public void Compatibility_ElementGroups_MatchesByGroup()
{
CompatibilityChecker checker = new();
checker.RegisterElement("IronOre", "Metal");
checker.RegisterElement("CopperOre", "Metal");
checker.RegisterElement("WaterFlask", "Water");
checker.AddRule("Metal", "Water", 0.3f, "Metal rusts in water");
// IronOre → Metal, WaterFlask → Water → правило Metal+Water матчит
CompatibilityResult result = checker.Check("IronOre", "WaterFlask");
Assert.IsTrue(result.IsCompatible);
Assert.Less(result.CompatibilityScore, 1.0f);
Assert.IsTrue(result.Warnings.Count > 0);
}
[Test]
public void Compatibility_ElementGroups_ThreeIngredients_GroupMatch()
{
CompatibilityChecker checker = new();
checker.RegisterElement("FireStone", "Fire");
checker.RegisterElement("IronOre", "Metal");
checker.RegisterElement("WaterFlask", "Water");
checker.AddGroupRule(0f, "Fire+Metal+Water = explosion!", "Fire", "Metal", "Water");
CompatibilityResult result = checker.Check("FireStone", "IronOre", "WaterFlask");
Assert.IsFalse(result.IsCompatible);
Assert.AreEqual(0f, result.CompatibilityScore);
}
[Test]
public void Compatibility_CustomValidator_Rejects()
{
CompatibilityChecker checker = new();
checker.AddValidator(new RejectAllValidator());
CompatibilityResult result = checker.Check("A", "B");
Assert.IsFalse(result.IsCompatible);
}
[Test]
public void Compatibility_CustomValidator_AddsBonuses()
{
CompatibilityChecker checker = new();
checker.AddValidator(new BonusValidator());
CompatibilityResult result = checker.Check("A", "B");
Assert.IsTrue(result.IsCompatible);
Assert.IsTrue(result.Bonuses.Count > 0);
}
[Test]
public void Compatibility_RuleCount_TracksAddedRules()
{
CompatibilityChecker checker = new();
Assert.AreEqual(0, checker.RuleCount);
checker.AddRule("A", "B", 1.0f);
Assert.AreEqual(1, checker.RuleCount);
checker.AddGroupRule(1.0f, "triple", "A", "B", "C");
Assert.AreEqual(2, checker.RuleCount);
}
[Test]
public void Compatibility_ElementCount_TracksRegistered()
{
CompatibilityChecker checker = new();
Assert.AreEqual(0, checker.ElementCount);
checker.RegisterElement("IronOre", "Metal");
Assert.AreEqual(1, checker.ElementCount);
}
[Test]
public void Compatibility_MixedPairAndGroupRules_BothApply()
{
CompatibilityChecker checker = new();
checker.AddRule("A", "B", 0.8f, "A+B weak");
checker.AddRule("C", "D", 1.2f, "C+D good");
checker.AddGroupRule(1.5f, "A+B+C+D together = great", "A", "B", "C", "D");
CompatibilityResult result = checker.Check("A", "B", "C", "D");
Assert.IsTrue(result.IsCompatible);
// All 3 rules match. Weighted: (0.8*2 + 1.2*2 + 1.5*4) / (2+2+4) = (1.6+2.4+6.0)/8 = 1.25
Assert.Greater(result.CompatibilityScore, 1.0f);
}
[Test]
public void CompatibilityRule_Pair_FactoryMethod()
{
CompatibilityRule rule = CompatibilityRule.Pair("A", "B", 0.5f, "test");
Assert.AreEqual(2, rule.Size);
Assert.AreEqual(0.5f, rule.Score);
Assert.AreEqual("test", rule.Reason);
}
[Test]
public void CompatibilityRule_Group_FactoryMethod()
{
CompatibilityRule rule = CompatibilityRule.Group(1.5f, "synergy", "A", "B", "C");
Assert.AreEqual(3, rule.Size);
Assert.AreEqual(1.5f, rule.Score);
}
[Test]
public void CompatibilityRule_IsBlocking_WhenScoreZero()
{
CompatibilityRule rule = CompatibilityRule.Pair("A", "B", 0f);
Assert.IsTrue(rule.IsBlocking);
}
[Test]
public void CompatibilityRule_IsNotBlocking_WhenScorePositive()
{
CompatibilityRule rule = CompatibilityRule.Pair("A", "B", 0.1f);
Assert.IsFalse(rule.IsBlocking);
}
// ═══════════════════════════════════════════════════
// JsonSchemaValidator Tests
// ═══════════════════════════════════════════════════
[Test]
public void Schema_EmptyJson_ReturnsErrors()
{
JsonSchemaValidator schema = new("Test");
JsonValidationResult result = schema.Validate("");
Assert.IsFalse(result.IsValid);
Assert.IsTrue(result.Errors.Count > 0);
}
[Test]
public void Schema_InvalidJson_ReturnsErrors()
{
JsonSchemaValidator schema = new("Test");
JsonValidationResult result = schema.Validate("not json at all");
Assert.IsFalse(result.IsValid);
Assert.IsTrue(result.ErrorSummary.Contains("Invalid JSON"));
}
[Test]
public void Schema_MissingRequiredField_ReturnsError()
{
JsonSchemaValidator schema = new("CraftResult");
schema.AddField("itemName", "string", true);
JsonValidationResult result = schema.Validate("{}");
Assert.IsFalse(result.IsValid);
Assert.IsTrue(result.ErrorSummary.Contains("Missing required field 'itemName'"));
}
[Test]
public void Schema_AllRequiredFieldsPresent_IsValid()
{
JsonSchemaValidator schema = new("CraftResult");
schema.AddField("itemName", "string", true);
schema.AddField("quality", "number", true);
JsonValidationResult result = schema.Validate("{\"itemName\":\"Sword\",\"quality\":85}");
Assert.IsTrue(result.IsValid);
Assert.IsNotNull(result.ParsedObject);
}
[Test]
public void Schema_WrongType_String_ReturnsError()
{
JsonSchemaValidator schema = new("Test");
schema.AddField("name", "string", true);
JsonValidationResult result = schema.Validate("{\"name\": 42}");
Assert.IsFalse(result.IsValid);
Assert.IsTrue(result.ErrorSummary.Contains("expected string"));
}
[Test]
public void Schema_WrongType_Number_ReturnsError()
{
JsonSchemaValidator schema = new("Test");
schema.AddField("value", "number", true);
JsonValidationResult result = schema.Validate("{\"value\": \"not a number\"}");
Assert.IsFalse(result.IsValid);
Assert.IsTrue(result.ErrorSummary.Contains("expected number"));
}
[Test]
public void Schema_NumberBelowMin_ReturnsError()
{
JsonSchemaValidator schema = new("Test");
schema.AddField("quality", "number", true, 0, 100);
JsonValidationResult result = schema.Validate("{\"quality\": -5}");
Assert.IsFalse(result.IsValid);
Assert.IsTrue(result.ErrorSummary.Contains("below minimum"));
}
[Test]
public void Schema_NumberAboveMax_ReturnsError()
{
JsonSchemaValidator schema = new("Test");
schema.AddField("quality", "number", true, 0, 100);
JsonValidationResult result = schema.Validate("{\"quality\": 150}");
Assert.IsFalse(result.IsValid);
Assert.IsTrue(result.ErrorSummary.Contains("exceeds maximum"));
}
[Test]
public void Schema_NumberInRange_IsValid()
{
JsonSchemaValidator schema = new("Test");
schema.AddField("quality", "number", true, 0, 100);
JsonValidationResult result = schema.Validate("{\"quality\": 85.5}");
Assert.IsTrue(result.IsValid);
}
[Test]
public void Schema_EnumValue_Valid()
{
JsonSchemaValidator schema = new("Test");
schema.AddField("rarity", "string", true,
allowedValues: new[] { "common", "rare", "epic", "legendary" });
JsonValidationResult result = schema.Validate("{\"rarity\": \"epic\"}");
Assert.IsTrue(result.IsValid);
}
[Test]
public void Schema_EnumValue_Invalid()
{
JsonSchemaValidator schema = new("Test");
schema.AddField("rarity", "string", true,
allowedValues: new[] { "common", "rare", "epic", "legendary" });
JsonValidationResult result = schema.Validate("{\"rarity\": \"mythic\"}");
Assert.IsFalse(result.IsValid);
Assert.IsTrue(result.ErrorSummary.Contains("not in allowed values"));
}
[Test]
public void Schema_EnumValue_CaseInsensitive()
{
JsonSchemaValidator schema = new("Test");
schema.AddField("rarity", "string", true,
allowedValues: new[] { "common", "rare" });
JsonValidationResult result = schema.Validate("{\"rarity\": \"Rare\"}");
Assert.IsTrue(result.IsValid);
}
[Test]
public void Schema_OptionalField_MissingIsOk()
{
JsonSchemaValidator schema = new("Test");
schema.AddField("name", "string", true);
schema.AddField("description", "string", false);
JsonValidationResult result = schema.Validate("{\"name\": \"Sword\"}");
Assert.IsTrue(result.IsValid);
}
[Test]
public void Schema_BooleanField_Validates()
{
JsonSchemaValidator schema = new("Test");
schema.AddField("isActive", "boolean", true);
Assert.IsTrue(schema.Validate("{\"isActive\": true}").IsValid);
Assert.IsFalse(schema.Validate("{\"isActive\": \"yes\"}").IsValid);
}
[Test]
public void Schema_ArrayField_Validates()
{
JsonSchemaValidator schema = new("Test");
schema.AddField("ingredients", "array", true);
Assert.IsTrue(schema.Validate("{\"ingredients\": [\"a\",\"b\"]}").IsValid);
Assert.IsFalse(schema.Validate("{\"ingredients\": \"not array\"}").IsValid);
}
[Test]
public void Schema_ObjectField_Validates()
{
JsonSchemaValidator schema = new("Test");
schema.AddField("stats", "object", true);
Assert.IsTrue(schema.Validate("{\"stats\": {\"hp\": 100}}").IsValid);
Assert.IsFalse(schema.Validate("{\"stats\": 42}").IsValid);
}
[Test]
public void Schema_IntegerField_AcceptsWholeFloat()
{
JsonSchemaValidator schema = new("Test");
schema.AddField("count", "integer", true);
Assert.IsTrue(schema.Validate("{\"count\": 5}").IsValid);
Assert.IsTrue(schema.Validate("{\"count\": 5.0}").IsValid);
Assert.IsFalse(schema.Validate("{\"count\": 5.7}").IsValid);
}
[Test]
public void Schema_MarkdownFences_StrippedBeforeParsing()
{
JsonSchemaValidator schema = new("Test");
schema.AddField("name", "string", true);
JsonValidationResult result = schema.Validate("```json\n{\"name\": \"Sword\"}\n```");
Assert.IsTrue(result.IsValid);
}
[Test]
public void Schema_MultipleErrors_AllReported()
{
JsonSchemaValidator schema = new("CraftResult");
schema.AddField("itemName", "string", true);
schema.AddField("quality", "number", true, 0, 100);
schema.AddField("rarity", "string", true,
allowedValues: new[] { "common", "rare" });
// All three fields wrong or missing
JsonValidationResult result = schema.Validate("{\"quality\": -1, \"rarity\": \"mythic\"}");
Assert.IsFalse(result.IsValid);
Assert.AreEqual(3, result.Errors.Count); // missing itemName, quality below min, rarity invalid
}
[Test]
public void Schema_ToPromptDescription_ContainsFieldNames()
{
JsonSchemaValidator schema = new("CraftResult");
schema.AddField("itemName", "string", true, description: "Name of the crafted item");
schema.AddField("quality", "number", true, 0, 100);
string prompt = schema.ToPromptDescription();
Assert.IsTrue(prompt.Contains("itemName"));
Assert.IsTrue(prompt.Contains("quality"));
Assert.IsTrue(prompt.Contains("REQUIRED"));
Assert.IsTrue(prompt.Contains("CraftResult"));
}
[Test]
public void Schema_FieldCount_TracksAddedFields()
{
JsonSchemaValidator schema = new("Test");
Assert.AreEqual(0, schema.FieldCount);
schema.AddField("a", "string");
Assert.AreEqual(1, schema.FieldCount);
schema.AddField("b", "number");
Assert.AreEqual(2, schema.FieldCount);
}
[Test]
public void Schema_SchemaName_Accessible()
{
JsonSchemaValidator schema = new("MyCraft");
Assert.AreEqual("MyCraft", schema.SchemaName);
}
[Test]
public void Schema_FluentApi_Chainable()
{
JsonSchemaValidator schema = new JsonSchemaValidator("Test")
.AddField("a", "string", true)
.AddField("b", "number")
.AddField("c", "boolean");
Assert.AreEqual(3, schema.FieldCount);
}
[Test]
public void Schema_ComplexCraftResult_FullValidation()
{
// Реалистичный сценарий: CoreMechanicAI возвращает результат крафта
JsonSchemaValidator schema = new JsonSchemaValidator("CraftResult")
.AddField("itemName", "string", true, description: "Name of crafted item")
.AddField("quality", "number", true, 0, 100)
.AddField("rarity", "string", true,
allowedValues: new[] { "common", "uncommon", "rare", "epic", "legendary" })
.AddField("durability", "integer", true, 1, 1000)
.AddField("effects", "array", false)
.AddField("isCursed", "boolean", false);
string validJson = @"{
""itemName"": ""Flaming Sword"",
""quality"": 87.5,
""rarity"": ""epic"",
""durability"": 450,
""effects"": [""fire_damage"", ""glow""],
""isCursed"": false
}";
JsonValidationResult result = schema.Validate(validJson);
Assert.IsTrue(result.IsValid, $"Expected valid but got errors: {result.ErrorSummary}");
Assert.AreEqual("Flaming Sword", result.ParsedObject["itemName"].ToString());
}
// ═══════════════════════════════════════════════════
// CompatibilityLlmTool Tests
// ═══════════════════════════════════════════════════
[Test]
public void CompatibilityTool_Properties_AreValid()
{
CompatibilityChecker checker = new();
CompatibilityLlmTool tool = new(checker);
Assert.AreEqual("check_compatibility", tool.Name);
Assert.IsTrue(tool.Description.Contains("compatibility"));
Assert.IsTrue(tool.ParametersSchema.Contains("ingredients"));
}
[Test]
public void CompatibilityTool_NullChecker_Throws()
{
Assert.Throws<System.ArgumentNullException>(() => new CompatibilityLlmTool(null));
}
[Test]
public void CompatibilityTool_EmptyIngredients_ReturnsError()
{
CompatibilityChecker checker = new();
CompatibilityLlmTool tool = new(checker);
string result = tool.ExecuteAsync(new string[0]).Result;
Assert.IsTrue(result.Contains("\"Success\":false") || result.Contains("\"Success\": false"));
}
[Test]
public void CompatibilityTool_SingleIngredient_ReturnsError()
{
CompatibilityChecker checker = new();
CompatibilityLlmTool tool = new(checker);
string result = tool.ExecuteAsync(new[] { "OnlyOne" }).Result;
Assert.IsTrue(result.Contains("at least 2") || result.Contains("At least 2"));
}
[Test]
public void CompatibilityTool_ValidIngredients_ReturnsResult()
{
CompatibilityChecker checker = new();
checker.AddRule("Fire", "Earth", 1.5f, "Lava synergy");
CompatibilityLlmTool tool = new(checker);
string result = tool.ExecuteAsync(new[] { "Fire", "Earth" }).Result;
Assert.IsTrue(result.Contains("\"Success\":true") || result.Contains("\"Success\": true"));
Assert.IsTrue(result.Contains("\"IsCompatible\":true") || result.Contains("\"IsCompatible\": true"));
}
[Test]
public async Task CompatibilityTool_AIFunction_UsesIngredientsArgumentName()
{
CompatibilityChecker checker = new();
checker.AddRule("Fire", "Earth", 1.5f, "Lava synergy");
CompatibilityLlmTool tool = new(checker);
AIFunction function = tool.CreateAIFunction();
object result = await function.InvokeAsync(new AIFunctionArguments(new Dictionary<string, object>
{
{ "ingredients", new[] { "Fire", "Earth" } }
}), CancellationToken.None);
string json = result?.ToString() ?? "";
Assert.IsTrue(json.Contains("\"Success\":true") || json.Contains("\"Success\": true"));
Assert.IsTrue(json.Contains("\"IsCompatible\":true") || json.Contains("\"IsCompatible\": true"));
}
[Test]
public void CompatibilityTool_ThreeIngredients_Works()
{
CompatibilityChecker checker = new();
checker.AddGroupRule(0f, "Explosive combo!", "Fire", "Oil", "Gunpowder");
CompatibilityLlmTool tool = new(checker);
string result = tool.ExecuteAsync(new[] { "Fire", "Oil", "Gunpowder" }).Result;
Assert.IsTrue(result.Contains("\"IsCompatible\":false") || result.Contains("\"IsCompatible\": false"));
}
// ═══════════════════════════════════════════════════
// Test helpers
// ═══════════════════════════════════════════════════
private sealed class RejectAllValidator : ICompatibilityValidator
{
public CompatibilityResult Validate(IReadOnlyList<string> ingredients)
{
return new CompatibilityResult
{
IsCompatible = false,
CompatibilityScore = 0f,
Reason = "Rejected by custom validator"
};
}
}
private sealed class BonusValidator : ICompatibilityValidator
{
public CompatibilityResult Validate(IReadOnlyList<string> ingredients)
{
return new CompatibilityResult
{
IsCompatible = true,
CompatibilityScore = 1.2f,
Bonuses = new List<string> { "Custom bonus applied" }
};
}
}
}
}