Files
YachtDice/Assets/Scripts/Tests/Editor/ModifierEffectTests.cs
horooko ba626acb9b [Add] Universal modifier system, shop, inventory & persistence
Replace hardcoded BonusForOnes/MultiplierForSixes with data-driven
modifier system supporting 2 scopes (SelectedCategory, AnyCategoryClosed),
4 effect types, durability modes (Permanent, LimitedUses), and
configurable targets via ScriptableObject (ModifierData).

- Modifier domain: ModifierEnums, ModifierTarget, ModifierData,
  ModifierRuntime, ModifierEffect (dict-based strategy), ModifierPipeline
  (4-pass: cat-additive → cat-multiplicative → final-additive → final-multiplicative)
- ScoringSystem: replaced old modifier list with ModifierPipeline integration,
  added OnCategoryConfirmed event
- Shop MVC: ShopCatalog (SO), ShopModel, ShopView, ShopItemView, ShopController
- Inventory MVC: InventoryModel (activate/deactivate/sell/durability),
  InventoryView, InventorySlotView, InventoryController
- CurrencyBank: editor-adjustable balance with events
- Persistence: SaveData + SaveSystem (Newtonsoft JSON + PlayerPrefs)
- Editor: ModifierAssetCreator menu item to generate 6 example modifiers + catalog
- Tests: 6 test classes covering effects, pipeline, scoring, shop, inventory, save
- GameController: wired shop/inventory/save lifecycle
- GameInfoView: added currency display, shop/inventory toggle buttons

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 06:40:33 +07:00

90 lines
2.8 KiB
C#

using NUnit.Framework;
using UnityEngine;
public sealed class ModifierEffectTests
{
private static ModifierData CreateData(
ModifierEffectType effectType, float effectValue,
int dieValue = 0, ModifierScope scope = ModifierScope.SelectedCategory)
{
return ModifierData.CreateForTest("test", scope, effectType, effectValue, dieValue);
}
[Test]
public void AddPerDieValue_CountsMatchingDice()
{
var data = CreateData(ModifierEffectType.AddPerDieValue, 10f, dieValue: 1);
var result = ScoreResult.Create(5, new[] { 1, 1, 3, 4, 1 }, YachtCategory.Ones);
ModifierEffect.Apply(data, ref result);
Assert.AreEqual(30, result.FlatBonus);
}
[Test]
public void AddPerDieValue_ZeroTarget_CountsAllDice()
{
var data = CreateData(ModifierEffectType.AddPerDieValue, 2f, dieValue: 0);
var result = ScoreResult.Create(10, new[] { 1, 2, 3, 4, 5 }, YachtCategory.Chance);
ModifierEffect.Apply(data, ref result);
Assert.AreEqual(10, result.FlatBonus);
}
[Test]
public void AddPerDieValue_NoMatches_ZeroBonus()
{
var data = CreateData(ModifierEffectType.AddPerDieValue, 10f, dieValue: 6);
var result = ScoreResult.Create(5, new[] { 1, 2, 3, 4, 5 }, YachtCategory.Chance);
ModifierEffect.Apply(data, ref result);
Assert.AreEqual(0, result.FlatBonus);
}
[Test]
public void AddFlatToFinalScore_AddsFlat()
{
var data = CreateData(ModifierEffectType.AddFlatToFinalScore, 15f);
var result = ScoreResult.Create(25, new[] { 3, 3, 2, 2, 2 }, YachtCategory.FullHouse);
ModifierEffect.Apply(data, ref result);
Assert.AreEqual(15, result.FlatBonus);
}
[Test]
public void MultiplyPerDieValue_MultipliesPerMatch()
{
var data = CreateData(ModifierEffectType.MultiplyPerDieValue, 2f, dieValue: 6);
var result = ScoreResult.Create(18, new[] { 6, 6, 6, 1, 2 }, YachtCategory.Sixes);
ModifierEffect.Apply(data, ref result);
Assert.AreEqual(8f, result.Multiplier); // 1 * 2 * 2 * 2 = 8
}
[Test]
public void MultiplyPerDieValue_NoMatches_MultiplierUnchanged()
{
var data = CreateData(ModifierEffectType.MultiplyPerDieValue, 3f, dieValue: 6);
var result = ScoreResult.Create(10, new[] { 1, 2, 3, 4, 5 }, YachtCategory.Chance);
ModifierEffect.Apply(data, ref result);
Assert.AreEqual(1f, result.Multiplier);
}
[Test]
public void MultiplyFinalScore_MultipliesOnce()
{
var data = CreateData(ModifierEffectType.MultiplyFinalScore, 1.5f);
var result = ScoreResult.Create(50, new[] { 6, 6, 6, 6, 6 }, YachtCategory.Yacht);
ModifierEffect.Apply(data, ref result);
Assert.AreEqual(1.5f, result.Multiplier, 0.001f);
}
}