Example #1
0
        public void CopyFromAnonimousObjectsWithFieldsOfSameTypes()
        {
            var A = new { First = (int)RV(), Second = (int)RV() };
            var B = new APair <int>();

            ObjectCloner.MemberwiseCopy(A, B);
            AssertAreEquals(A, B);
        }
Example #2
0
        public void FailToCopyFieldsOfUnassignableTypes()
        {
            var A = new { First = (int)10, Second = (long)20 };
            var B = new APair <byte>();

            Assert.ThrowsException <ArgumentException>(() =>
            {
                ObjectCloner.MemberwiseCopy(A, B);
            });
        }
Example #3
0
        public void CopyObjectsWithFieldsOfAssignableTypes()
        {
            var A = new APair <int>()
            {
                First = RV(), Second = RV()
            };
            var B = new APair <long>();

            ObjectCloner.MemberwiseCopy(A, B);
            AssertAreEquals(A, B);
        }
Example #4
0
        public void CloneObjects()
        {
            //var a = new { First = 101, Second = 102 };
            //var b = new { First = 201L, Second = 202L };

            if (true)
            {
                var A = new APair <int> {
                    First = RV(), Second = RV()
                }; AssertAreEquals(A, ObjectCloner.CreateMemberwiseClone(A));
            }
            if (true)
            {
                var A = new APair <long> {
                    First = RV(), Second = RV()
                }; AssertAreEquals(A, ObjectCloner.CreateMemberwiseClone(A));
            }
            if (true)
            {
                var A = new APair <float> {
                    First = RV(), Second = RV()
                }; AssertAreEquals(A, ObjectCloner.CreateMemberwiseClone(A));
            }
            if (true)
            {
                var A = new APair <double> {
                    First = RV(), Second = RV()
                }; AssertAreEquals(A, ObjectCloner.CreateMemberwiseClone(A));
            }
            if (true)
            {
                var A = new APair <decimal> {
                    First = RV(), Second = RV()
                }; AssertAreEquals(A, ObjectCloner.CreateMemberwiseClone(A));
            }
            if (true)
            {
                var A = new APair <string> {
                    First = RS(), Second = RS()
                }; AssertAreEquals(A, ObjectCloner.CreateMemberwiseClone(A));
            }
        }
Example #5
0
        private List <APair <int, double> > FindMaximums(List <double> distances)
        {
            List <APair <int, double> > maximums = new List <APair <int, double> >();

            // find maximums (starting from a small offset to avoid rogue results)
            for (int i = (int)(distances.Count * 0.05f); i < distances.Count - 1; ++i)
            {
                // check if higher than next neighbors
                if (distances[i] >= distances[i - 1] && distances[i] >= distances[i + 1])
                {
                    // if within 32 pixels from last found maximum and the value is higher, replace
                    if (maximums.Count > 0 && Math.Abs(maximums[maximums.Count - 1].First - i) < 32)
                    {
                        APair <int, double> lastMax = maximums[maximums.Count - 1];
                        if (distances[i] > lastMax.Second)
                        {
                            maximums.Remove(lastMax);
                            maximums.Add(new APair <int, double>(i, distances[i]));
                        }
                    }
                    else
                    {
                        maximums.Add(new APair <int, double>(i, distances[i]));
                    }
                }
            }

            // narrow down to 5 highest results
            maximums = maximums.OrderByDescending(o => o.Second).ToList();
            if (maximums.Count >= MAX_COUNT)
            {
                maximums.RemoveRange(MAX_COUNT, maximums.Count - MAX_COUNT);
            }

            // re-sort by occurence
            maximums = maximums.OrderBy(o => o.First).ToList();

            return(maximums);
        }