using System; using System.Collections.Generic; using Azimuth; using Glass; using UnitTestSharp; namespace Konis.Testbed.UnitTests { public class TuningGridsTests : TestFixture { private static bool IsNumber(TunableProperty property) { return property.Kind == TunableKind.Whole || property.Kind == TunableKind.Number || property.Kind == TunableKind.Range; } private static bool OnTheGrid(NumberGrid grid, double value) { decimal held = (decimal)value; return held >= grid.Min && held <= grid.Max && grid.Snap(held) == held; } public class ForTests : TestFixture { public void EveryNumberAndRange_HasAGridThatValidates() { foreach (TunableProperty property in Tunables.Of(Effects.All[0].Def)) { if (IsNumber(property)) { TuningGrids.For(property.Name).Validate(); } } } public void APropertyHoldingNoNumber_Throws() { CheckThrow(typeof(ArgumentException)); TuningGrids.For("Up"); } public void EveryValueOfEveryEffect_SitsExactlyOnItsGrid() { var offTheGrid = new List(); foreach (Effect effect in Effects.All) { foreach (TunableProperty property in Tunables.Of(effect.Def)) { if (!IsNumber(property)) { continue; } NumberGrid grid = TuningGrids.For(property.Name); object value = property.Get(effect.Def); string name = effect.Name + " " + property.Name; if (property.Kind == TunableKind.Whole) { if (!OnTheGrid(grid, (int)value)) { offTheGrid.Add(name); } continue; } if (property.Kind == TunableKind.Number) { if (!OnTheGrid(grid, ((Scalar)value).Value)) { offTheGrid.Add(name); } continue; } var range = (Variation)value; if (!OnTheGrid(grid, range.Minimum.Value)) { offTheGrid.Add(name + " minimum"); } if (!OnTheGrid(grid, range.Maximum.Value)) { offTheGrid.Add(name + " maximum"); } } } CheckEqual(new string[0], offTheGrid); } } } }