Ejemplo n.º 1
0
        // 50% overlap between phases
        public Hysteresis(double range, int phaseCount)
        {
            ArgAssert.GreaterThan(range, "range", 0);
            ArgAssert.AtLeast(phaseCount, "phaseCount", 2);

            var downwardsThresholds = new double[phaseCount];
            var upwardsThresholds   = new double[phaseCount];

            var step = range / (phaseCount + 1);

            downwardsThresholds[0] = 0;
            downwardsThresholds[1] = step;

            for (var i = 2; i < phaseCount; i++)
            {
                downwardsThresholds[i]   = i * step;
                upwardsThresholds[i - 2] = downwardsThresholds[i];
            }

            upwardsThresholds[phaseCount - 2] = phaseCount * step;
            upwardsThresholds[phaseCount - 1] = range;

            _downwardsThresholds = downwardsThresholds;
            _upwardsThresholds   = upwardsThresholds;
            _equilibria          = ComputeEquilibria();
        }
Ejemplo n.º 2
0
        private void ValidateThresholds()
        {
            ArgAssert.AtLeast(_downwardsThresholds.Count, "thresholds.Count", 2);
            ArgAssert.Equal(_downwardsThresholds.Count, "downwardsThreholds.Count", _upwardsThresholds.Count, "upwardsTresholds.Count");

            for (var i = 1; i < PhaseCount; i++)
            {
                ArgAssert.GreaterThan
                    (_upwardsThresholds[i - 1], string.Format("_upwardsThresholds[{0}]", i - 1),
                    _downwardsThresholds[i], string.Format("_downwardsThresholds[{0}]", i));

                ArgAssert.GreaterThan
                    (_upwardsThresholds[i], string.Format("_upwardsThresholds[{0}]", i),
                    _upwardsThresholds[i - 1], string.Format("_upwardsThresholds[{0}]", i - 1));

                ArgAssert.GreaterThan
                    (_downwardsThresholds[i], string.Format("_downwardsThresholds[{0}]", i),
                    _downwardsThresholds[i - 1], string.Format("_downwardsThresholds[{0}]", i - 1));
            }
        }
Ejemplo n.º 3
0
        public static string Repeat(this string @this, int times)
        {
            ArgAssert.NotNull(@this, "this");
            ArgAssert.AtLeast(times, "times", 0);

            if (@this == "" || times == 0)
            {
                return("");
            }

            if (times == 1)
            {
                return(@this);
            }

            var result = new StringBuilder(@this.Length * times);

            for (var i = 0; i < times; i++)
            {
                result.Append(@this);
            }

            return(result.ToString());
        }