コード例 #1
0
        public void DecimalRange_LengthDivisibleByStep_IterationCountMatchesCalculated()
        {
            Random rand = new Random();

            Tuple <decimal, decimal> rangeParams = RestrictedRandomRange();
            decimal start  = rangeParams.Item1;
            decimal length = rangeParams.Item2;
            decimal end    = start + length;
            // pick a power of ten for the number of steps as decimal uses base 10 for the floating point
            decimal step = length / (decimal)Math.Pow(10, rand.Next(2, 5));

            //ensure that step size is a factor of the length of the range
            start  += length % step;
            length += length % step;

            // Test that the attempt to create the correct scenario actually worked, as with floating point values this cannot be certain
            Assert.AreEqual(
                0,
                length % step,
                "This test should be using a range length which is an exact multiple of the step size");

            DecimalRange decimalRange = new DecimalRange(start, end, step);

            // Range endpoint is inclusive, so must take into account this extra iteration
            Assert.AreEqual(
                length / step + 1,
                decimalRange.Count(),
                "Iteration count should be (end-start)/step + 1 where endpoint is included");
        }
コード例 #2
0
        public void Search_CanSerializeRanges()
        {
            var intRange = new IntRange {
                Min = 3, Max = 9
            };

            Assert.Equal("3-9", intRange.ToString());
            intRange = new IntRange {
                Min = 2
            };
            Assert.Equal("2-", intRange.ToString());
            intRange = new IntRange {
                Max = 4
            };
            Assert.Equal("-4", intRange.ToString());

            var doubleRange = new DoubleRange {
                Min = 1.23, Max = 4.56
            };

            Assert.Equal("1.23-4.56", doubleRange.ToString());

            var decimalRange = new DecimalRange {
                Min = 1.23m, Max = 4.56m
            };

            Assert.Equal("1.23-4.56", decimalRange.ToString());
        }
コード例 #3
0
        public void DecimalRange_LengthNotDivisibleByStep_IterationCountMatchesCalculated()
        {
            Random rand = new Random();

            Tuple <decimal, decimal> rangeParams = RestrictedRandomRange();
            decimal start  = rangeParams.Item1;
            decimal length = rangeParams.Item2;
            decimal end    = start + length;
            // note that the number of steps is limited to 1000 or fewer
            decimal step = length / (decimal)(rand.Next(4, 1000) + (rand.NextDouble() * 0.8 + 0.1));

            //ensure that step size is not a factor of the length of the range
            if (length % step == 0)
            {
                decimal offset = (decimal)(rand.NextDouble() * 0.8 + 0.1) * step;
                start  += offset;
                length += offset;
            }

            DecimalRange decimalRange = new DecimalRange(start, end, step);

            Assert.AreEqual(
                Math.Ceiling(length / step),
                decimalRange.Count(),
                "Iteration count should be Ceil((start-end)/step)");
        }
コード例 #4
0
        public void DecimalRange_Iterating_DifferenceBetweenIterationsMatchesStepSize()
        {
            Random rand = new Random();

            Tuple <decimal, decimal> rangeParams = RestrictedRandomRange();
            decimal start  = rangeParams.Item1;
            decimal length = rangeParams.Item2;
            decimal end    = start + length;
            // note that the number of steps is limited to 100 or fewer
            decimal step = length / rand.Next(4, 100);

            // In case range length is under 4, ensure the step is at least 1
            if (step < 1)
            {
                step = 1;
            }

            DecimalRange decimalRange = new DecimalRange(start, end, step);

            decimal?previous = null;

            foreach (decimal i in decimalRange)
            {
                if (previous.HasValue)
                {
                    Assert.AreEqual(
                        (double)(i - previous.Value),
                        (double)step,
                        (double)step * 1e-6,
                        "Difference between iteration values should match the step value supplied to within one millionth");
                }
                previous = i;
            }
        }
コード例 #5
0
        public void DecimalRange_EndBeforeStart_ThrowsArgumentOutOfRangeException()
        {
            decimal start = RandomDecimal(decimal.MinValue / 2, decimal.MaxValue);
            decimal end   = RandomDecimal(decimal.MinValue, start);

            DecimalRange decimalRange = new DecimalRange(start, end);
        }
コード例 #6
0
        /// <summary>
        /// Uloží danou hodnotu do this._ValueTotal.
        /// Provede požadované akce (ValueAlign, ScrollDataValidate, InnerBoundsReset, OnValueChanged).
        /// </summary>
        /// <param name="valueTotal"></param>
        /// <param name="actions"></param>
        /// <param name="eventSource"></param>
        protected void SetValueTotal(DecimalRange valueTotal, ProcessAction actions, EventSourceType eventSource)
        {
            if (valueTotal == null)
            {
                return;
            }
            DecimalRange oldValueTotal = this._ValueTotal;
            DecimalRange newValueTotal = valueTotal;

            if (oldValueTotal != null && newValueTotal == oldValueTotal)
            {
                return;                                                             // No change = no reactions.
            }
            this._ValueTotal = newValueTotal;

            if (IsAction(actions, ProcessAction.RecalcValue))
            {
                this.SetValue(this._Value, LeaveOnlyActions(actions, ProcessAction.RecalcValue, ProcessAction.PrepareInnerItems, ProcessAction.CallChangedEvents), eventSource);
            }
            if (IsAction(actions, ProcessAction.PrepareInnerItems))
            {
                this.ChildItemsReset();
            }
            if (IsAction(actions, ProcessAction.CallChangedEvents))
            {
                this.CallValueTotalChanged(oldValueTotal, newValueTotal, eventSource);
            }
            if (IsAction(actions, ProcessAction.CallDraw))
            {
                this.CallDrawRequest(eventSource);
            }
        }
コード例 #7
0
        /// <summary>
        /// Vrací hodnotou pro daný bod a danou TrackLine
        /// </summary>
        /// <param name="point"></param>
        /// <param name="trackLine"></param>
        /// <returns></returns>
        protected virtual Decimal GetValueForPoint(Point point, Rectangle trackLine)
        {
            Decimal?ratio = ((this.Orientation == System.Windows.Forms.Orientation.Horizontal) ?
                             DecimalRange.CreateFromBeginSize(trackLine.X, trackLine.Width).GetRelativePositionAtValue(point.X) :
                             DecimalRange.CreateFromBeginSize(0, trackLine.Height).GetRelativePositionAtValue(trackLine.Bottom - point.Y));
            decimal r = (ratio.HasValue ? (ratio.Value < 0m ? 0m : (ratio.Value > 1m ? 1m : ratio.Value)) : 0m);

            return(this._ValueTotal.GetValueAtRelativePosition(r));
        }
コード例 #8
0
 /// <summary>
 /// Deeps the copy.
 /// </summary>
 /// <param name="x">The x.</param>
 /// <returns></returns>
 public Object DeepCopy(Object x)
 {
     if (x == null) return null;
     DecimalRange m = (DecimalRange)x;
     DecimalRange result = new DecimalRange(0m, 1m);
     result.Start = m.Start;
     result.End = m.End;
     return result;
 }
コード例 #9
0
        /// <summary>
        /// Vyvolá metodu OnValueTotalChanged() a event ValueTotalChanged
        /// </summary>
        protected void CallValueTotalChanged(DecimalRange oldValue, DecimalRange newValue, EventSourceType eventSource)
        {
            GPropertyChangeArgs <DecimalRange> args = new GPropertyChangeArgs <DecimalRange>(oldValue, newValue, eventSource);

            this.OnValueTotalChanged(args);
            if (!this.IsSuppressedEvent && this.ValueTotalChanged != null)
            {
                this.ValueTotalChanged(this, args);
            }
        }
コード例 #10
0
        /// <summary>
        ///		Extension method that allows for <see cref="NonIntegralRangeBase{TIntegralType}.Constrain"/>
        ///		to be called on a <see cref="Decimal"/> subject with the range and exclusivity passed as a
        ///		parameter, rather than on the <see cref="NonIntegralRangeBase{TIntegralType}"/> object
        ///		with a <see cref="Decimal"/> parameter.
        /// </summary>
        /// <param name="this">
        ///		The subject <see cref="Decimal"/> value in which to check against the <paramref name="range"/>
        ///		parameter to constrain a value within a range with an implicit inclusive comparison mode.
        /// </param>
        /// <param name="range">
        ///		An instance of the type <see cref="DecimalRange"/>, describing a range of numeric values in
        ///		which the <paramref name="this"/> subject is to be compared against.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///		Thrown when the specified <paramref name="range"/> is <see langword="null"/>.
        ///	</exception>
        /// <returns>
        ///		A <see cref="Decimal"/> value that is the <paramref name="this"/> subject value adjusted to
        ///		force the range of possible values to be within the provided <paramref cref="range"/>
        ///		parameter, using <see cref="EndpointExclusivity.Inclusive"/> as the comparison mode.
        /// </returns>
        public static Decimal Constrain(
            this Decimal @this,
            [NotNull] DecimalRange range)
        {
            range.IsNotNull(nameof(range));

            return(range
                   .Constrain(
                       @this));
        }
コード例 #11
0
        public void DecimalRange_ConstructorWithoutStepParam_StepDefaultsToOne()
        {
            decimal length = RandomDecimal(1, decimal.MaxValue);
            decimal start  = RandomDecimal(decimal.MinValue, decimal.MaxValue - length);
            decimal end    = start + length;

            DecimalRange decimalRange = new DecimalRange(start, end);

            Assert.AreEqual(start, decimalRange.Start, "Starting point field must match the value supplied");
            Assert.AreEqual(end, decimalRange.End, "End point field must match the value supplied");
            Assert.AreEqual(1, decimalRange.Step, "Step amount must default to one");
        }
コード例 #12
0
        /// <summary>
        ///		Extension method that allows for <see cref="T:Ccr.Core.Numerics.NonIntegralRangeBase{TIntegralType}.IsNotWithin"/>
        ///		to be called on a <see cref="Decimal"/> subject with the range and exclusivity passed as a
        ///		parameter, rather than on the <see cref="NonIntegralRangeBase{TIntegralType}"/> object
        ///		with a <see cref="Decimal"/> parameter.
        /// </summary>
        /// <param name="this">
        ///		The subject <see cref="Decimal"/> value in which to check against the <paramref name="range"/>
        ///		parameter to determine whether it is within the range, taking into account the exclusivity.
        /// </param>
        /// <param name="range">
        ///		An instance of the type <see cref="DecimalRange"/>, describing a range of numeric values in
        ///		which the <paramref name="this"/> subject is to be compared against.
        /// </param>
        /// <param name="exclusivity">
        ///		A value indicating whether to perform the upper and lower bounds comparisons including
        ///		the range's Minimum and Maximum bounds, or to exclude them. This parameter is optional,
        ///		and the default value is <see cref="EndpointExclusivity.Inclusive"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///		Thrown when the specified <paramref name="range"/> is <see langword="null"/>.
        ///	</exception>
        /// <returns>
        ///		A <see cref="Decimal"/> value indicating whether or not the <paramref name="this"/> subject
        ///		is within the provided <paramref cref="range"/> parameter, taking into account the
        ///		<see cref="EndpointExclusivity"/> mode via the <paramref name="exclusivity"/> parameter.
        ///		This comparison is the logical inverse of the <see cref="IsNotWithin"/> extension method.
        /// </returns>
        public static bool IsNotWithin(
            this Decimal @this,
            [NotNull] DecimalRange range,
            EndpointExclusivity exclusivity = EndpointExclusivity.Inclusive)
        {
            range.IsNotNull(nameof(range));

            return(range
                   .IsNotWithin(
                       @this,
                       exclusivity));
        }
コード例 #13
0
        public void DecimalRange_StepSmallerThanDecimalRange_ParametersMatchThoseGiven()
        {
            decimal length = RandomDecimal(1, decimal.MaxValue);
            decimal start  = RandomDecimal(decimal.MinValue, decimal.MaxValue - length);
            decimal end    = start + length;
            decimal step   = RandomDecimal(1, length / 2);

            DecimalRange decimalRange = new DecimalRange(start, end, step);

            Assert.AreEqual(start, decimalRange.Start, "Starting point field must match the value supplied");
            Assert.AreEqual(end, decimalRange.End, "End point field must match the value supplied");
            Assert.AreEqual(step, decimalRange.Step, "Step amount field must match the value supplied");
        }
コード例 #14
0
        public void DecimalRange_ConvertingToString_IsNotBlank()
        {
            decimal length = RandomDecimal(1, decimal.MaxValue);
            decimal start = RandomDecimal(decimal.MinValue, decimal.MaxValue - length);
            decimal end = start + length;
            decimal step = RandomDecimal(1, length / 2);

            DecimalRange decimalRange = new DecimalRange(start, end, step);

            Assert.AreNotEqual(
                "",
                decimalRange.ToString(),
                "String representation of range must not be an empty string");
        }
コード例 #15
0
        public void DecimalRange_UsingLargestPossibleParameters_IteratesSuccessfully()
        {
            // Step chosen to avoid an unfeasible number of iterations
            DecimalRange decimalRange = new DecimalRange(decimal.MinValue, decimal.MaxValue, decimal.MaxValue / 10);

            bool iterated = false;

            foreach (decimal x in decimalRange)
            {
                iterated = true;
            }

            Assert.AreEqual(true, iterated, "When iterating across full range, at least one value should be returned");
        }
コード例 #16
0
        public void DecimalRange_ConvertingToString_IsNotBlank()
        {
            decimal length = RandomDecimal(1, decimal.MaxValue);
            decimal start  = RandomDecimal(decimal.MinValue, decimal.MaxValue - length);
            decimal end    = start + length;
            decimal step   = RandomDecimal(1, length / 2);

            DecimalRange decimalRange = new DecimalRange(start, end, step);

            Assert.AreNotEqual(
                "",
                decimalRange.ToString(),
                "String representation of range must not be an empty string");
        }
コード例 #17
0
        /// <summary>
        ///		Extension method that performs a transformation on the <see cref="Decimal"/> subject using
        ///		linear mapping to re-map from the provided initial range <paramref name="startRange"/>
        ///		to the target range <paramref name="endRange"/>.
        /// </summary>
        /// <param name="this">
        ///		The subject <see cref="Decimal"/> to perform the linear map range re-mapping upon.
        /// </param>
        /// <param name="startRange">
        ///		An instance of the type <see cref="DecimalRange"/>, describing a range of numeric values in
        ///		which the linear re-mapping uses as the initial range of the subject.
        /// </param>
        /// <param name="endRange">
        ///		An instance of the type <see cref="DecimalRange"/>, describing a range of numeric values in
        ///		which the linear re-mapping uses as the target range of the return value.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///		Thrown when either the <paramref name="startRange"/> or the <paramref name="endRange"/>
        ///		parameters are equal to <see langword="null"/>.
        ///	</exception>
        /// <returns>
        ///		A <see cref="Decimal"/> value that has been linearly mapped to the <paramref name="startRange"/>
        ///		parameter and re-mapped to the <paramref name="endRange"/> parameter.
        /// </returns>
        public static Decimal LinearMap(
            this Decimal @this,
            [NotNull] DecimalRange startRange,
            [NotNull] DecimalRange endRange)
        {
            startRange.IsNotNull(nameof(startRange));
            endRange.IsNotNull(nameof(endRange));

            return((
                       (@this - startRange.Minimum) *
                       (endRange.Maximum - endRange.Minimum) /
                       (startRange.Maximum - startRange.Minimum) +
                       endRange.Minimum)
                   .To <Decimal>());
        }
コード例 #18
0
        protected SalesForecastViewModel()
        {
            RequestData("YTDSalesVolume", x => x.GetTotalSalesByRange(DateTimeUtils.GetYtdRange()).TotalCost, x => {
                var YTDSalesVolume = x;
                YTDSalesForecast   = SalesForecastMaker.GetYtdForecast(YTDSalesVolume);
            });

            DecimalRange badSalesRange    = SalesRangeProvider.GetBadSalesRange();
            DecimalRange normalSalesRange = SalesRangeProvider.GetNormalSalesRange();
            DecimalRange goodSalesRange   = SalesRangeProvider.GetGoodSalesRange();

            AnnualSalesFirstRangeEnd  = badSalesRange.End;
            AnnualSalesSecondRangeEnd = normalSalesRange.End;
            AnnualSalesThirdRangeEnd  = goodSalesRange.End;
        }
コード例 #19
0
        public void DecimalRange_StepGreaterThanLength_IterationCountMatchesCalculated()
        {
            Random rand = new Random();

            Tuple <decimal, decimal> rangeParams = RestrictedRandomRange();
            decimal start  = rangeParams.Item1;
            decimal length = rangeParams.Item2;
            decimal end    = start + length;
            decimal step   = length * (decimal)(2 - rand.NextDouble());

            DecimalRange decimalRange = new DecimalRange(start, end, step);

            Assert.AreEqual(
                1,
                decimalRange.Count(),
                "Iteration count should be one if the step is larger than the range");
        }
コード例 #20
0
        public void DecimalRange_Iterating_ValuesStayWithinRange()
        {
            Random rand = new Random();

            Tuple <decimal, decimal> rangeParams = RestrictedRandomRange();
            decimal start  = rangeParams.Item1;
            decimal length = rangeParams.Item2;
            decimal end    = start + length;
            // note that the number of steps is limited to 100 or fewer
            decimal step = length / rand.Next(4, 100);

            DecimalRange decimalRange = new DecimalRange(start, end, step);

            foreach (decimal i in decimalRange)
            {
                Assert.IsTrue(i >= start, "Value from iterator must by equal or above start parameter");
                Assert.IsTrue(i <= end, "Value from iterator must be equal or below end parameter");
            }
        }
コード例 #21
0
        public void Apply(Schema schema, SchemaFilterContext context)
        {
            if (schema.Properties == null)
            {
                return;
            }

            foreach (PropertyInfo propertyInfo in context.SystemType.GetProperties())
            {
                DecimalRange decimalAttribute = propertyInfo
                                                .GetCustomAttribute <DecimalRange>();

                if (decimalAttribute != null)
                {
                    string camelName = Helpers.ToCamelCase(propertyInfo.Name);
                    Schema property  = schema.Properties[camelName];
                    property.Format = $"numeric({decimalAttribute.Precision}, {decimalAttribute.Scale})";
                }
            }
        }
コード例 #22
0
        public static void ThrowIfNotWithin(
            [AssertionCondition(IS_NOT_NULL)] this Decimal @this,
            [NotNull] DecimalRange range,
            [InvokerParameterName] string elementName,
            EndpointExclusivity exclusivity            = Inclusive,
            [CallerMemberName] string callerMemberName = "")
        {
            range.IsNotNull(nameof(range));

            if (range
                .IsNotWithin(
                    @this,
                    exclusivity))
            {
                throw new ArgumentOutOfRangeException(
                          elementName,
                          $"Parameter {elementName.SQuote()} passed to the method {callerMemberName.SQuote()} " +
                          $"must be within [{range.Minimum} and {range.Maximum}], {exclusivity}ly.");
            }
        }
        protected AnnualSalesPerformanceViewModel(DateTime date)
        {
            DecimalRange badSalesRange    = SalesRangeProvider.GetBadSalesRange();
            DecimalRange normalSalesRange = SalesRangeProvider.GetNormalSalesRange();
            DecimalRange goodSalesRange   = SalesRangeProvider.GetGoodSalesRange();

            AnnualSalesFirstRangeEnd  = badSalesRange.End;
            AnnualSalesSecondRangeEnd = normalSalesRange.End;
            AnnualSalesThirdRangeEnd  = goodSalesRange.End;
            if (DateTimeUtils.IsCurrentYear(date))
            {
                VolumeHeader = "YEAR TO DATE";
                RequestData("Volume", x => x.GetTotalSalesByRange(DateTimeUtils.GetYtdRange()).TotalCost, x => Volume = x);
            }
            else
            {
                VolumeHeader = "YEAR " + date.Year;
                RequestData("Volume", x => x.GetTotalSalesByRange(DateTimeUtils.GetYearRange(date)).TotalCost, x => Volume = x);
            }
        }
コード例 #24
0
        public void DecimalRange_LengthNotDivisibleByStep_IterationCountMatchesCalculated()
        {
            Random rand = new Random();

            Tuple<decimal, decimal> rangeParams = RestrictedRandomRange();
            decimal start = rangeParams.Item1;
            decimal length = rangeParams.Item2;
            decimal end = start + length;
            // note that the number of steps is limited to 1000 or fewer
            decimal step = length / (decimal)(rand.Next(4, 1000) + (rand.NextDouble() * 0.8 + 0.1));

            //ensure that step size is not a factor of the length of the range
            if (length % step == 0)
            {
                decimal offset = (decimal)(rand.NextDouble() * 0.8 + 0.1) * step;
                start += offset;
                length += offset;
            }

            DecimalRange decimalRange = new DecimalRange(start, end, step);

            Assert.AreEqual(
                Math.Ceiling(length / step),
                decimalRange.Count(),
                "Iteration count should be Ceil((start-end)/step)");
        }
コード例 #25
0
        public void DecimalRange_StepGreaterThanLength_IterationCountMatchesCalculated()
        {
            Random rand = new Random();

            Tuple<decimal, decimal> rangeParams = RestrictedRandomRange();
            decimal start = rangeParams.Item1;
            decimal length = rangeParams.Item2;
            decimal end = start + length;
            decimal step = length * (decimal)(2 - rand.NextDouble());

            DecimalRange decimalRange = new DecimalRange(start, end, step);

            Assert.AreEqual(
                1,
                decimalRange.Count(),
                "Iteration count should be one if the step is larger than the range");
        }
コード例 #26
0
        public void Load(NodeBase node = null)
        {
            //Set current base
            Base = node != null ? node : Base;

            //Set position
            transform.localPosition = new Vector3(Base.NodePosition.x, Base.NodePosition.y);

            //Set label
            Label.text = Base.Label;

            #region Set Input ports
            for (int i = 0; i < Base.InputPorts.Count; i++)
            {
                CachePool.I().GetObject("Prefabs/InputPort", (obj) =>
                {
                    obj.transform.SetParent(InputParent, false);
                    RuntimePort rp = obj.GetComponent <RuntimePort>();
                    rp.Load(Base.InputPorts[i]);
                    InputPorts.Add(rp);
                    RuntimeGraph.I().Ports.Add(rp.Base.UID, rp);
                });
            }
            #endregion

            #region Set Output ports
            for (int i = 0; i < Base.OutputPorts.Count; i++)
            {
                CachePool.I().GetObject("Prefabs/OutputPort", (obj) =>
                {
                    obj.transform.SetParent(OutputParent, false);
                    RuntimePort rp = obj.GetComponent <RuntimePort>();
                    rp.Load(Base.OutputPorts[i]);
                    OutputPorts.Add(rp);
                    RuntimeGraph.I().Ports.Add(rp.Base.UID, rp);
                });
            }
            #endregion

            #region Set Content
            System.Type t    = Base.GetType();
            FieldInfo[] info = t.GetFields();

            int ContentCounter = 0;
            int FieldsCount    = 0;

            for (int i = 0; i < info.Length; i++)
            {
                HideFieldAttribute hideAtt = (HideFieldAttribute)info[i].GetCustomAttribute(typeof(HideFieldAttribute), false);
                if (hideAtt != null)
                {
                    continue;
                }

                FieldsCount++;

                if (!Base.ShowedPropertiesList.Contains(info[i].Name))
                {
                    continue;
                }

                ContentCounter++;

                System.Type CurType           = info[i].FieldType;
                string      HumanReadableName = info[i].Name.Replace("_", " ");

                if (CurType == RuntimeGraph.I().stringType)
                {
                    TextAreaAttribute att = (TextAreaAttribute)info[i].GetCustomAttribute(typeof(TextAreaAttribute), false);
                    if (att == null)
                    {
                        GetInputer("String", HumanReadableName, info[i].GetValue(Base));
                    }
                    else
                    {
                        GetInputer("StringMultiline", HumanReadableName, info[i].GetValue(Base));
                    }
                }
                else if (CurType == RuntimeGraph.I().intType)
                {
                    RangeAttribute att = (RangeAttribute)info[i].GetCustomAttribute(typeof(RangeAttribute), false);
                    if (att == null)
                    {
                        GetInputer("Int", HumanReadableName, info[i].GetValue(Base));
                    }
                    else
                    {
                        CachePool.I().GetObject("Prefabs/Content/Int_Range", (obj) =>
                        {
                            obj.transform.SetParent(ContentParent, false);
                            IntRange inputer = obj.GetComponent <IntRange>();
                            inputer.SetLabel(HumanReadableName);
                            inputer.SetValue(info[i].GetValue(Base));
                            inputer.SetRange(att.min, att.max);
                            BaseInputer.Add(HumanReadableName, inputer);
                        });
                    }
                }
                else if (CurType == RuntimeGraph.I().floatType)
                {
                    RangeAttribute att = (RangeAttribute)info[i].GetCustomAttribute(typeof(RangeAttribute), false);
                    if (att == null)
                    {
                        GetInputer("Decimal", HumanReadableName, info[i].GetValue(Base));
                    }
                    else
                    {
                        CachePool.I().GetObject("Prefabs/Content/Decimal_Range", (obj) =>
                        {
                            obj.transform.SetParent(ContentParent, false);
                            DecimalRange inputer = obj.GetComponent <DecimalRange>();
                            inputer.SetLabel(HumanReadableName);
                            inputer.SetValue(info[i].GetValue(Base));
                            inputer.SetRange(att.min, att.max);
                            BaseInputer.Add(HumanReadableName, inputer);
                        });
                    }
                }
                else if (CurType == RuntimeGraph.I().Vector2Type)
                {
                    GetInputer("Vector2", HumanReadableName, info[i].GetValue(Base));
                }
                else if (CurType == RuntimeGraph.I().Vector3Type)
                {
                    GetInputer("Vector3", HumanReadableName, info[i].GetValue(Base));
                }
                else if (CurType == RuntimeGraph.I().Vector4Type)
                {
                    GetInputer("Vector4", HumanReadableName, info[i].GetValue(Base));
                }
                else if (CurType == RuntimeGraph.I().QuaternionType)
                {
                    GetInputer("Vector4", HumanReadableName, info[i].GetValue(Base));
                }
                else if (CurType == RuntimeGraph.I().boolType)
                {
                    GetInputer("Toggle", HumanReadableName, info[i].GetValue(Base));
                }
                else if (CurType == RuntimeGraph.I().enumType)
                {
                    GetInputer("Dropdown", HumanReadableName, info[i].GetValue(Base));
                    CachePool.I().GetObject("Prefabs/Content/Dropdown", (obj) =>
                    {
                        obj.transform.SetParent(ContentParent, false);
                        DropdownMenu inputer = obj.GetComponent <DropdownMenu>();
                        object temp          = info[i].GetValue(Base);
                        inputer.SetEnum(info[i].FieldType);
                        inputer.SetLabel(HumanReadableName);
                        inputer.SetValue(temp);
                        BaseInputer.Add(HumanReadableName, inputer);
                    });
                }
            }
            #endregion

            #region Set Add Button
            if (ContentCounter < FieldsCount)
            {
                CachePool.I().GetObject("Prefabs/Content/AddButton", (obj) =>
                {
                    obj.transform.SetParent(ContentParent, false);
                });
            }
            #endregion
        }
コード例 #27
0
        public void DecimalRange_StepSmallerThanDecimalRange_ParametersMatchThoseGiven()
        {
            decimal length = RandomDecimal(1, decimal.MaxValue);
            decimal start = RandomDecimal(decimal.MinValue, decimal.MaxValue - length);
            decimal end = start + length;
            decimal step = RandomDecimal(1, length / 2);

            DecimalRange decimalRange = new DecimalRange(start, end, step);

            Assert.AreEqual(start, decimalRange.Start, "Starting point field must match the value supplied");
            Assert.AreEqual(end, decimalRange.End, "End point field must match the value supplied");
            Assert.AreEqual(step, decimalRange.Step, "Step amount field must match the value supplied");
        }
コード例 #28
0
        public void DecimalRange_ConstructorWithoutStepParam_StepDefaultsToOne()
        {
            decimal length = RandomDecimal(1, decimal.MaxValue);
            decimal start = RandomDecimal(decimal.MinValue, decimal.MaxValue - length);
            decimal end = start + length;

            DecimalRange decimalRange = new DecimalRange(start, end);

            Assert.AreEqual(start, decimalRange.Start, "Starting point field must match the value supplied");
            Assert.AreEqual(end, decimalRange.End, "End point field must match the value supplied");
            Assert.AreEqual(1, decimalRange.Step, "Step amount must default to one");
        }
コード例 #29
0
        public void DecimalRange_Iterating_DifferenceBetweenIterationsMatchesStepSize()
        {
            Random rand = new Random();

            Tuple<decimal, decimal> rangeParams = RestrictedRandomRange();
            decimal start = rangeParams.Item1;
            decimal length = rangeParams.Item2;
            decimal end = start + length;
            // note that the number of steps is limited to 100 or fewer
            decimal step = length / rand.Next(4, 100);

            // In case range length is under 4, ensure the step is at least 1
            if (step < 1) step = 1;

            DecimalRange decimalRange = new DecimalRange(start, end, step);

            decimal? previous = null;
            foreach (decimal i in decimalRange)
            {
                if (previous.HasValue)
                    Assert.AreEqual(
                        (double)(i - previous.Value),
                        (double)step,
                        (double)step * 1e-6,
                        "Difference between iteration values should match the step value supplied to within one millionth");
                previous = i;
            }
        }
コード例 #30
0
        public void DecimalRange_Iterating_ValuesStayWithinRange()
        {
            Random rand = new Random();

            Tuple<decimal, decimal> rangeParams = RestrictedRandomRange();
            decimal start = rangeParams.Item1;
            decimal length = rangeParams.Item2;
            decimal end = start + length;
            // note that the number of steps is limited to 100 or fewer
            decimal step = length / rand.Next(4, 100);

            DecimalRange decimalRange = new DecimalRange(start, end, step);

            foreach (decimal i in decimalRange)
            {
                Assert.IsTrue(i >= start, "Value from iterator must by equal or above start parameter");
                Assert.IsTrue(i <= end, "Value from iterator must be equal or below end parameter");
            }
        }
コード例 #31
0
        public void DecimalRange_UsingLargestPossibleParameters_IteratesSuccessfully()
        {
            // Step chosen to avoid an unfeasible number of iterations
            DecimalRange decimalRange = new DecimalRange(decimal.MinValue, decimal.MaxValue, decimal.MaxValue / 10);

            bool iterated = false;
            foreach (decimal x in decimalRange)
                iterated = true;

            Assert.AreEqual(true, iterated, "When iterating across full range, at least one value should be returned");
        }
コード例 #32
0
ファイル: UnitTest1.cs プロジェクト: AscarGb/MVCExtensions
        public void DecimalRangeNotPassPrecisionTest()
        {
            DecimalRange attr = new DecimalRange(10, 3);

            Assert.False(attr.IsValid(12345678.899m));
        }
コード例 #33
0
        public void DecimalRange_LengthDivisibleByStep_IterationCountMatchesCalculated()
        {
            Random rand = new Random();

            Tuple<decimal, decimal> rangeParams = RestrictedRandomRange();
            decimal start = rangeParams.Item1;
            decimal length = rangeParams.Item2;
            decimal end = start + length;
            // pick a power of ten for the number of steps as decimal uses base 10 for the floating point
            decimal step = length / (decimal)Math.Pow(10, rand.Next(2, 5));

            //ensure that step size is a factor of the length of the range
            start += length % step;
            length += length % step;

            // Test that the attempt to create the correct scenario actually worked, as with floating point values this cannot be certain
            Assert.AreEqual(
                0,
                length % step,
                "This test should be using a range length which is an exact multiple of the step size");

            DecimalRange decimalRange = new DecimalRange(start, end, step);

            // Range endpoint is inclusive, so must take into account this extra iteration
            Assert.AreEqual(
                length / step + 1,
                decimalRange.Count(),
                "Iteration count should be (end-start)/step + 1 where endpoint is included");
        }
コード例 #34
0
ファイル: UnitTest1.cs プロジェクト: AscarGb/MVCExtensions
        public void DecimalRangeNotPassScaleTest()
        {
            DecimalRange attr = new DecimalRange(10, 3);

            Assert.False(attr.IsValid(1234567.8999m));
        }
コード例 #35
0
        /// <summary>
        /// Nulls the safe get.
        /// </summary>
        /// <param name="rs">The rs.</param>
        /// <param name="names">The names.</param>
        /// <param name="session">The session.</param>
        /// <param name="owner">The owner.</param>
        /// <returns></returns>
        public Object NullSafeGet(IDataReader rs, string[] names, ISessionImplementor session, Object owner)
        {
            decimal? first = NHibernateUtil.Decimal.NullSafeGet(rs, names[0], session, owner) as decimal?;
            decimal? second = NHibernateUtil.Decimal.NullSafeGet(rs, names[1], session, owner) as decimal?;

            if (first == null && second == null)
                return null;

            DecimalRange result = new DecimalRange(0m, 1m);
            result.Start = first;
            result.End = second;

            return result;
        }
コード例 #36
0
ファイル: UnitTest1.cs プロジェクト: AscarGb/MVCExtensions
        public void DecimalRangePassTest()
        {
            DecimalRange attr = new DecimalRange(10, 3);

            Assert.True(attr.IsValid(1234567.899m));
        }
コード例 #37
0
        public void DecimalRange_EndBeforeStart_ThrowsArgumentOutOfRangeException()
        {
            decimal start = RandomDecimal(decimal.MinValue / 2, decimal.MaxValue);
            decimal end = RandomDecimal(decimal.MinValue, start);

            DecimalRange decimalRange = new DecimalRange(start, end);
        }