예제 #1
0
        internal void EnsureConvertToStringAndBack(object seedValue)
        {
            if (_property.PropertyType.IsPrimitive || _property.PropertyType.IsEnum)
            {
                return;
            }

            GenerateValue(seedValue);
            var deserializedValue = ConvertFromString();

            var actualEnumerable       = ActualValue as IEnumerable;
            var deserializedEnumerable = deserializedValue as IEnumerable;

            if (actualEnumerable != null && deserializedEnumerable != null && SequenceEqual(actualEnumerable, deserializedEnumerable))
            {
                return;
            }

            if (!ActualValue.Equals(deserializedValue))             // TODO check if ActualValue is IEquatable<T>
            {
                throw new NotSupportedException(
                          string.Format(
                              "{0} TypeConverter could not perform a successful roundtrip conversion of {1} {2} for {3}. " +
                              "The failure to validate a successful roundtrip conversion could also be due to the fact that {1} does not implement IEquatable<T>.",
                              _converter.GetType().Name,
                              _property.PropertyType.Name,
                              _property.Name,
                              ActualValue));
            }
        }
예제 #2
0
        private void CalculateCoefficentValues()
        {
            DiceCoefficentValue = OriginalValue.DiceCoefficient(ActualValue);

            var LevenshteinDistanceValue = OriginalValue.LevenshteinDistance(ActualValue);

            LevenshteinDistanceCoefficentValue = 1.0 / (1.0 * (LevenshteinDistanceValue + 0.2));
            LevenshteinDistanceCoefficentValue = LevenshteinDistanceCoefficentValue > .99 ? .99 : LevenshteinDistanceCoefficentValue;

            LongestCommonSubsequenceCoefficentValue = OriginalValue.LongestCommonSubsequence(ActualValue).Item2;
            LongestCommonSubsequenceCoefficentValue = LongestCommonSubsequenceCoefficentValue > .99 ? .99 : LongestCommonSubsequenceCoefficentValue;

            string originalValueDoubleMetaphone = OriginalValue.ToDoubleMetaphone();
            string ActualValueDoubleMetaphone   = ActualValue.ToDoubleMetaphone();

            int matchCount = 0;

            if (originalValueDoubleMetaphone.Length == 4 && ActualValueDoubleMetaphone.Length == 4)
            {
                for (int i = 0; i < originalValueDoubleMetaphone.Length; i++)
                {
                    if (originalValueDoubleMetaphone[i] == ActualValueDoubleMetaphone[i])
                    {
                        matchCount++;
                    }
                }
            }
            DoubleMetaphoneCoefficentValue = matchCount == 0 ? 0.0 : matchCount / 4.0;
            DoubleMetaphoneCoefficentValue = DoubleMetaphoneCoefficentValue == 1.0 ? .90 : DoubleMetaphoneCoefficentValue;

            AverageCoefficentValue = (DiceCoefficentValue + LongestCommonSubsequenceCoefficentValue + LevenshteinDistanceCoefficentValue + DoubleMetaphoneCoefficentValue) / 4.0;
        }
예제 #3
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)
                if (Id != null)
                {
                    hashCode = hashCode * 59 + Id.GetHashCode();
                }

                hashCode = hashCode * 59 + Severity.GetHashCode();

                hashCode = hashCode * 59 + Passed.GetHashCode();

                hashCode = hashCode * 59 + Override.GetHashCode();
                if (ActualValue != null)
                {
                    hashCode = hashCode * 59 + ActualValue.GetHashCode();
                }
                if (ExpectedValue != null)
                {
                    hashCode = hashCode * 59 + ExpectedValue.GetHashCode();
                }

                hashCode = hashCode * 59 + Comparator.GetHashCode();
                if (Kpi != null)
                {
                    hashCode = hashCode * 59 + Kpi.GetHashCode();
                }
                return(hashCode);
            }
        }
예제 #4
0
            public async Task IsUnset()
            {
                await prepare();

                currentTimeEntrySubject.OnNext(null);

                ActualValue.Should().Be(ExpectedEmptyValue);
            }
예제 #5
0
 public static void IsLower(this ActualValue <string> actual, string message)
 {
     if (actual == null)
     {
         throw new ArgumentNullException(nameof(actual));
     }
     actual.IsLower(message, null);
 }
예제 #6
0
            public async ThreadingTask IsUnset()
            {
                await prepare();

                currentTimeEntrySubject.OnNext(null);
                Scheduler.AdvanceBy(TimeSpan.FromMilliseconds(50).Ticks);

                ActualValue.Should().Be(ExpectedEmptyValue);
            }
예제 #7
0
        /// <summary>
        /// Returns true if Metric instances are equal
        /// </summary>
        /// <param name="other">Instance of Metric to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Metric other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id != null &&
                     Id.Equals(other.Id)
                     ) &&
                 (
                     Severity == other.Severity ||

                     Severity.Equals(other.Severity)
                 ) &&
                 (
                     Passed == other.Passed ||

                     Passed.Equals(other.Passed)
                 ) &&
                 (
                     Override == other.Override ||

                     Override.Equals(other.Override)
                 ) &&
                 (
                     ActualValue == other.ActualValue ||
                     ActualValue != null &&
                     ActualValue.Equals(other.ActualValue)
                 ) &&
                 (
                     ExpectedValue == other.ExpectedValue ||
                     ExpectedValue != null &&
                     ExpectedValue.Equals(other.ExpectedValue)
                 ) &&
                 (
                     Comparator == other.Comparator ||

                     Comparator.Equals(other.Comparator)
                 ) &&
                 (
                     Kpi == other.Kpi ||
                     Kpi != null &&
                     Kpi.Equals(other.Kpi)
                 ));
        }
예제 #8
0
 public static void IsLower(
     this ActualValue <string> actual,
     string message,
     params object[] args)
 {
     if (!actual.Value.All(c => !char.IsLetter(c) || char.IsLower(c)))
     {
         Throw(
             nameof(IsLower),
             $"{actual.Value} is not all lowercase.",
             message,
             args);
     }
 }
예제 #9
0
 public static void IsError <T>(
     this ActualValue <Result <T> > actual, int line, int column, string message)
 {
     if (actual.Value is Result <T> .Error e)
     {
         AssertAll("Error Result does not have expected properties.",
                   () => Assert(e.Position)
                   .IsEqualTo(new Position(new Line(line), new Column(column)), "Position is not correct."),
                   () => Assert(e.ToString()).IsEqualTo(message, "Error message is not correct.")
                   );
     }
     else
     {
         Fail("Result is not an Error.");
     }
 }
예제 #10
0
 public static void IsSuccess <T>(
     this ActualValue <Result <T> > actual, T value, IEqualityComparer <T> comparer, int line, int column)
 {
     if (actual.Value is Result <T> .Success s)
     {
         AssertAll("Success Result does not have expected properties.",
                   () => Assert(comparer.Equals(value, s.Value)).IsTrue("Value is not correct."),
                   () => Assert(s.RemainingInput.Position)
                   .IsEqualTo(new Position(new Line(line), new Column(column)), "Position is not correct.")
                   );
     }
     else
     {
         Fail("Result is not a Success.");
     }
 }
예제 #11
0
 public static void IsLower(
     this ActualValue <string> actual,
     string message,
     params object[] args)
 {
     if (actual == null)
     {
         throw new ArgumentNullException(nameof(actual));
     }
     if (!actual.Value.All(c => !char.IsLetter(c) || char.IsLower(c)))
     {
         Throw(
             nameof(IsLower),
             $"{actual.Value} is not all lowercase.",
             message,
             args);
     }
 }
예제 #12
0
        private string TestResultTypeToString()
        {
            switch (TestResultType)
            {
            case TestResultType.Pass:
                return("//  PASS  Value: " + ActualValue);

            case TestResultType.TypeMismatch:
                return($"//  FAIL  Expected: {ExpectedValue} ({ExpectedValue.GetType().Name}), " +
                       $"Actual: {ActualValue} ({ActualValue.GetType().Name})");

            case TestResultType.ValueMismatch:
                return($"//  FAIL  Expected: {ExpectedValue}, Actual: {ActualValue}");

            case TestResultType.Error:
                return($"//  COMPILE/RUNTIME ERROR  Expected: {ExpectedValue}");

            case TestResultType.Ignore:
                return("//  IGNORE  Can not check this type for correctness");

            default:
                return("// Error");
            }
        }
예제 #13
0
 public static void IsLower(this ActualValue <string> actual, string message)
 {
     actual.IsLower(message, null);
 }
예제 #14
0
            public async ThreadingTask IsSet()
            {
                await prepare();

                ActualValue.Should().Be(ExpectedValue);
            }
예제 #15
0
 public static void IsEmpty <T>(
     this ActualValue <IEnumerable <T> > actual)
 => actual.IsSequenceEqualTo(Enumerable.Empty <T>());
예제 #16
0
 public static void IsEmpty <T>(
     this ActualValue <IEnumerable <T> > actual,
     string message,
     params object[] parameters)
 => actual.IsSequenceEqualTo(Enumerable.Empty <T>(), message, parameters);
        private void ThirdInterfaceSetup_CGNecessity()
        {
            if (RationalityCB.Checked)
            {
                for (int i = 0; i < TB.Count; i++)
                {
                    TB[i].Enabled = false;
                }
                RationalityCB.Enabled = false;

                NecessityPanel.Show();

                //delete
                string             Coalition = PanelsPanel.Controls[0].Controls[0].Text;
                List <List <int> > C         = new List <List <int> >();
                for (int i = 0; i < Coalition.Length; i++)
                {
                    if (Coalition[i] == '{')
                    {
                        C.Add(new List <int>());
                    }
                    if ((Coalition[i] >= '0') && (Coalition[i] <= '9'))
                    {
                        C.Last().Add(Convert.ToInt32(Coalition[i] - '0'));
                    }
                }


                for (int i = 0; i < TB.Count; i++)
                {
                    double ActualValue;
                    double IncooperativePrize      = Database.G.payoffs[i],
                           CoalitionPrize          = 0,
                           CoalitionPlayersPayoffs = 0;
                    int CoalitionIndex             = -1;
                    for (int p = 0; p < C.Count; p++)
                    {
                        for (int q = 0; q < C[p].Count; q++)
                        {
                            if (C[p][q] - 1 == i)
                            {
                                CoalitionIndex = p;
                            }
                        }
                    }
                    CoalitionPrize = G.payoffs[CoalitionIndex];
                    for (int j = 0; j < C[CoalitionIndex].Count; j++)
                    {
                        CoalitionPlayersPayoffs += Database.G.payoffs[C[CoalitionIndex][j] - 1];
                    }
                    ActualValue = IncooperativePrize * CoalitionPrize / CoalitionPlayersPayoffs;
                    TB[i].Text  = ActualValue.ToString("0.00");
                }

                UI.ControlsAligner npanel = new UI.ControlsAligner(NecessityPanel);
                npanel.AddElement(NecessityLabel);
                for (int i = 0; i < Database.G.N; i++)
                {
                    Label l = new Label();
                    l.Text      = "ΔV(" + (i + 1) + ") = ";
                    l.Font      = new System.Drawing.Font("Bookman Old Style", 14);
                    l.ForeColor = Color.White;
                    l.Size      = TextRenderer.MeasureText(l.Text, l.Font);

                    TextBox tb = new TextBox();
                    tb.Font      = new System.Drawing.Font("Bookman Old Style", 16);
                    tb.TextAlign = HorizontalAlignment.Center;
                    tb.Width     = 100;
                    tb.Text      = "";

                    if (i == 0)
                    {
                        npanel.AddElement(l, true);
                    }
                    else
                    {
                        npanel.AddElement(l, false);
                    }
                    npanel.AddElement(tb, false, "HorBind");

                    NecessityPanel.Controls.Add(l);
                    NecessityPanel.Controls.Add(tb);
                    NTB.Add(tb);
                }
                npanel.Align();

                UI.ControlsAligner form = new UI.ControlsAligner(this);
                form.AddElement(PanelsPanel);
                form.AddElement(DivisionPanel, false);
                form.AddElement(NecessityPanel);
                form.AddElement(FinishBTN, true, "Right");
                form.Align();
            }
            else
            {
                //Different division method
            }
        }
예제 #18
0
 public static void IsLower(this ActualValue <string> actual)
 {
     actual.IsLower(null, null);
 }