예제 #1
0
파일: Type.cs 프로젝트: thwaringiii/Rosetta
        public T Combine <T>(object input, CombineMethod method, T value)
        {
            var type        = GetType();
            var inputType   = input.GetType();
            var methodInfos = type.GetMethods().Where(x => x.Name == "Combine");
            var methodInfo  = methodInfos.FirstOrDefault(x =>
            {
                var parameter = x.GetParameters().First();
                if (!parameter.ParameterType.IsGenericType)
                {
                    return(false);
                }

                var generic = parameter.ParameterType.GetGenericArguments()[0];
                return(generic != null && generic.FullName == inputType.FullName);
            });

            if (methodInfo == null)
            {
                throw new ArgumentException("The type converter does not support this type.");
            }

            var genericMethod = methodInfo.MakeGenericMethod(typeof(T));

            return((T)genericMethod.Invoke(this, new[] { input, method, value }));
        }
예제 #2
0
파일: Type.cs 프로젝트: thwaringiii/Rosetta
        public object Combine(IEnumerable input, string type, CombineMethod method, object value)
        {
            var toType = System.Type.GetType(type);

            if (toType == null)
            {
                throw new ArgumentException("Failed to find the target type.", nameof(type));
            }

            var myType      = GetType();
            var methodInfos = myType.GetMethods().Where(x => x.Name == "Combine");
            var methodInfo  = methodInfos.FirstOrDefault(x =>
            {
                var parameter = x.GetParameters().First();
                if (!parameter.ParameterType.IsGenericType)
                {
                    return(false);
                }

                var generic = parameter.ParameterType.GetGenericArguments()[0];
                return(generic != null && generic.FullName == type);
            });

            if (methodInfo == null)
            {
                throw new ArgumentException("The type converter does not support this type.");
            }

            return(methodInfo.Invoke(this, new[] { input, method, value }));
        }
예제 #3
0
파일: Combine.cs 프로젝트: salerth/Idol.net
 private Combine(CombineMethod method, params Field[] fields)
 {
     Method = method;
     if ((fields != null) && (fields.Count( ) > 0))
     {
         Fields = new List<Field>(fields);
     }
 }
예제 #4
0
        public void CombinePowerTest()
        {
            Project project = new Project(@"..\..\..\ProjectTest\测试项目\测试combineMethod.combinePower");
            List <List <ResultFile> > sameRxTypeFiles  = project.SearchSameRxTypeFile(project.ResultFiles, project.GetRxType(project.ResultFiles));
            List <ResultFile>         singleRxTypeFile = sameRxTypeFiles[0];
            string expected = "-1.41980E+02    7.16500E+01";
            string actual   = CombineMethod.CombinePower(singleRxTypeFile);

            StringAssert.Contains(actual, expected);
            //Assert.Inconclusive("验证此测试方法的正确性。");
        }
예제 #5
0
        public CardCombine Combine(CombineMethod method = CombineMethod.SMART)
        {
            // min combine group count 1;
            // min combine group count 5;
            Debug.Log("> Combining : " + method);

            List <CardGroup> groups = null;

            switch (method)
            {
            case CombineMethod.COMBINE123:
                groups = Group123(Sort());
                break;

            case CombineMethod.COMBINE777:
                groups = Group777(Sort());
                break;

            case CombineMethod.SMART:
                groups = Group(Sort());
                break;
            }


            CardCombine bestCombine = new CardCombine();


            int debug_iteration            = 0; //debug
            int debug_iteration_validation = 0; //debug

            for (int i = 1; i < 6; i++)
            {
                foreach (IEnumerable <CardGroup> combine in Combiner.Combinations(groups, i))
                {
                    int count = combine.Sum((group) => group.members.Count);
                    debug_iteration++;//debug
                    if (count > bestCombine.CardCount)
                    {
                        HashSet <int> slotIDs = new HashSet <int>();
                        bool          valid   = combine.All((group) => group.members.All((card) => slotIDs.Add(card.slot)));
                        debug_iteration_validation++;//debug
                        if (valid)
                        {
                            bestCombine.members = combine.ToList();
                        }
                    }
                }
            }

            Debug.Log("Iteration Count :" + debug_iteration);
            Debug.Log("Validation Iteration Count :" + debug_iteration_validation);

            return(bestCombine);
        }
예제 #6
0
        public void CombineSituationErmsTest()
        {
            Project       project             = new Project(@"..\..\..\ProjectTest\测试项目\测试combineMethod.CombineSituationErms");
            List <string> midPointFrequencies = project.GetMidPointFrequency(project.ResultFiles);
            List <Dictionary <ResultFile, double> > resultFilesWithWeights = project.GetWeight(project.ResultFiles, midPointFrequencies);
            Dictionary <ResultFile, double>         singleMidpointResultFilesWithWeight = resultFilesWithWeights[0];
            string expected = "1.94932E-02"; // TODO: 初始化为适当的值
            string actual;

            actual = CombineMethod.CombineSituationErms(singleMidpointResultFilesWithWeight);
            StringAssert.Contains(actual, expected);
            //Assert.Inconclusive("验证此测试方法的正确性。");
        }
예제 #7
0
        public void CombineEtrmsTest()
        {
            Project project = new Project(@"..\..\..\ProjectTest\测试项目\测试combineMethod.combineEtrms");
            List <List <ResultFile> > sameRxTypeFile                  = project.SearchSameRxTypeFile(project.ResultFiles, project.GetRxType(project.ResultFiles));
            List <ResultFile>         singleRxTypeFile                = sameRxTypeFile[0];
            List <string>             midPointFrequencies             = project.GetMidPointFrequency(singleRxTypeFile);
            List <List <ResultFile> > sameMidPointAndSameRxtypeFile   = project.SearchSameMidPointAndSameRxTypeFile(singleRxTypeFile, midPointFrequencies);
            List <ResultFile>         singleMidPointAndSameRxTypeFile = sameMidPointAndSameRxtypeFile[0];
            string actual   = CombineMethod.CombineEtrms(singleMidPointAndSameRxTypeFile);
            string expected = "1.25195E-03";

            StringAssert.Contains(actual, expected);
            //Assert.Inconclusive("验证此测试方法的正确性。");
        }
예제 #8
0
        /// <summary>
        /// Combines the list of items using the provided method.
        /// </summary>
        /// <param name="items"> The items to be combined. </param>
        /// <param name="method"> The method used to combine the items. </param>
        /// <param name="delimiter"> The delimiter used when combining the item. </param>
        /// <returns> The items in a combined format. </returns>
        public double Combine(IEnumerable <double> items, CombineMethod method, string delimiter)
        {
            switch (method)
            {
            case CombineMethod.Sum:
                return(items.Sum());

            case CombineMethod.Join:
                return(double.Parse(string.Join("", items.Select(x => x.ToString()))));

            default:
                throw new NotImplementedException();
            }
        }
예제 #9
0
        public void CombineMagTest()
        {
            Project       project             = new Project(@"..\..\..\ProjectTest\测试项目\测试combineMethod.combineMag");
            List <string> midPointFrequencies = project.GetMidPointFrequency(project.ResultFiles); // TODO: 初始化为适当的值
            List <Dictionary <ResultFile, double> > resultFilesWithWeights = project.GetWeight(project.ResultFiles, midPointFrequencies);
            List <string> actual = new List <string>();

            foreach (Dictionary <ResultFile, double> singleMidpointResultFilesWithWeight in resultFilesWithWeights)
            {
                actual.Add(CombineMethod.CombineMag(singleMidpointResultFilesWithWeight));
            }
            string expected = "7.53574E-01  6.01320E-01  4.54190E-01"; // TODO: 初始化为适当的值

            StringAssert.Contains(actual[0], expected);
            //Assert.Inconclusive("验证此测试方法的正确性。");
        }
예제 #10
0
        /// <summary>
        /// Combines the list of items using the provided method.
        /// </summary>
        /// <param name="items"> The items to be combined. </param>
        /// <param name="method"> The method used to combine the items. </param>
        /// <param name="delimiter"> The delimiter used when combining the item. </param>
        /// <returns> The items in a combined format. </returns>
        public TimeSpan Combine(IEnumerable <TimeSpan> items, CombineMethod method, string delimiter)
        {
            var ticks = items.Sum(x => x.Ticks);

            return(new TimeSpan(ticks));
        }
예제 #11
0
        /// <summary>
        /// Combines the list of items using the provided method.
        /// </summary>
        /// <param name="items"> The items to be combined. </param>
        /// <param name="method"> The method used to combine the items. </param>
        /// <param name="delimiter"> The delimiter used when combining the item. </param>
        /// <returns> The items in a combined format. </returns>
        public DateTime Combine(IEnumerable <DateTime> items, CombineMethod method, string delimiter)
        {
            var ticks = items.Sum(x => x.Ticks);

            return(new DateTime(ticks));
        }
예제 #12
0
 public static T Combine <T>(IEnumerable <T> input, string type, CombineMethod method, T value)
 {
     return(Providers[type].Combine(input, method, value));
 }
예제 #13
0
 public static object Combine(IEnumerable input, string type, CombineMethod method, object value)
 {
     return(Providers[type].Combine(input, type, method, value));
 }
예제 #14
0
 /// <summary>
 /// Combines the list of items using the provided method.
 /// </summary>
 /// <param name="items"> The items to be combined. </param>
 /// <param name="method"> The method used to combine the items. </param>
 /// <param name="delimiter"> The delimiter used when combining the item. </param>
 /// <returns> The items in a combined format. </returns>
 public bool Combine(IEnumerable <bool> items, CombineMethod method, string delimiter)
 {
     return(items.Aggregate((x, y) => x & y));
 }
예제 #15
0
 /// <summary>
 /// Combines the list of items using the provided method.
 /// </summary>
 /// <param name="items"> The items to be combined. </param>
 /// <param name="method"> The method used to combine the items. </param>
 /// <param name="delimiter"> The delimiter used when combining the item. </param>
 /// <returns> The items in a combined format. </returns>
 public char Combine(IEnumerable <char> items, CombineMethod method, string delimiter)
 {
     return(items.FirstOrDefault());
 }
예제 #16
0
 /// <summary>
 /// Combines the list of items using the provided method.
 /// </summary>
 /// <param name="items"> The items to be combined. </param>
 /// <param name="method"> The method used to combine the items. </param>
 /// <param name="delimiter"> The delimiter used when combining the item. </param>
 /// <returns> The items in a combined format. </returns>
 public string Combine(IEnumerable <string> items, CombineMethod method, string delimiter)
 {
     return(string.Join(delimiter ?? "", items));
 }