当前位置: 首页>>代码示例>>C#>>正文


C# List.FindAll方法代码示例

本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.FindAll方法的典型用法代码示例。如果您正苦于以下问题:C# List.FindAll方法的具体用法?C# List.FindAll怎么用?C# List.FindAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.VisualStudio.TestTools.UnitTesting.List的用法示例。


在下文中一共展示了List.FindAll方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestLists

        public void TestLists()
        {
            List<Person> people = new List<Person> { new Person(), new Person("Ted", "TheDog"), new Person("Fred", "TheDog"), new Person("Joe", "Schmoo") };
            Assert.AreEqual("Joe", people[3].FirstName);
            Assert.AreEqual("Schmoo", people[3].LastName);
            Assert.AreEqual(4, people.Count);

            List<Person> theJoes = people.FindAll(p => p.FirstName.Equals("Joe"));
            Assert.AreEqual(1, theJoes.Count);

            theJoes.Add(new Person("Joe", "Soe"));
            Assert.AreEqual(2, theJoes.Count);
            Assert.AreEqual(4, people.Count);

            var joeschmoo = theJoes.FindAll(p => p.FirstName.Equals("Joe") && p.LastName.Equals("Schmoo"));
            Assert.AreEqual(1, joeschmoo.Count);

            var sando = theJoes.FindAll(p => p.FirstName.Equals("Joe") && Regex.IsMatch(p.LastName, "S.*o.*"));
            Assert.AreEqual(2, sando.Count);

            StringBuilder sb = new StringBuilder();
            foreach (Person person in people)
            {
                sb.Append(String.Format("{0}, {1}\n", person.LastName, person.FirstName));
            }

            string pretty = sb.ToString();
            Assert.AreEqual("Doe, John\nTheDog, Ted\nTheDog, Fred\nSchmoo, Joe\n", pretty);
        }
开发者ID:ctarrington,项目名称:CSharpSamples,代码行数:29,代码来源:PersonTest.cs

示例2: RandomWeightedTest

        public void RandomWeightedTest()
        {
            //Arrange
            Random randy = new Random();
            List<Move> myMoves = new List<Move>();
            int MoveCount = 1000;
            int Variance = 40;
            double Rweight = 6;
            double Pweight = 1;
            double Sweight = 1;
            double Dweight = 1;
            double Wweight = 1;

            //computed vars
            double TotalWeight = Rweight + Pweight + Sweight + Dweight + Wweight;
            double Rexpected = (Rweight / TotalWeight) * MoveCount;
            double Pexpected = (Pweight / TotalWeight) * MoveCount;
            double Sexpected = (Sweight / TotalWeight) * MoveCount;
            double Dexpected = (Dweight / TotalWeight) * MoveCount;
            double Wexpected = (Wweight / TotalWeight) * MoveCount;

            //Act
            for (int i = 0; i < MoveCount; i++)
            {
                myMoves.Add(Strats.RandomWeighted(randy, Rweight, Pweight, Sweight, Dweight, Wweight));
            }
            var RockCount = myMoves.FindAll(m => m.Equals(Moves.Rock)).Count;
            var PaperCount = myMoves.FindAll(m => m.Equals(Moves.Paper)).Count;
            var ScissorsCount = myMoves.FindAll(m => m.Equals(Moves.Scissors)).Count;
            var DynamiteCount = myMoves.FindAll(m => m.Equals(Moves.Dynamite)).Count;
            var WaterCount = myMoves.FindAll(m => m.Equals(Moves.WaterBalloon)).Count;

            Console.WriteLine("Rock: " + RockCount + ", Paper: " + PaperCount + ", Scissors: " + ScissorsCount + ", Dyanimite: " + DynamiteCount + ", Water: " + WaterCount);

            //Assert
            Assert.IsTrue(Rexpected - Variance < RockCount && RockCount < Rexpected + Variance, "RockCount: " + RockCount + " is outside statistical likelyhood.");
            Assert.IsTrue(Pexpected - Variance < PaperCount && PaperCount < Pexpected + Variance, "PaperCount: " + PaperCount + " is outside statistical likelyhood.");
            Assert.IsTrue(Sexpected - Variance < ScissorsCount && ScissorsCount < Sexpected + Variance, "ScissorsCount: " + ScissorsCount + " is outside statistical likelyhood.");
            Assert.IsTrue(Dexpected - Variance < DynamiteCount && DynamiteCount < Dexpected + Variance, "DynamiteCount: " + DynamiteCount + " is outside statistical likelyhood.");
            Assert.IsTrue(Wexpected - Variance < WaterCount && WaterCount < Wexpected + Variance, "DynamiteCount: " + WaterCount + " is outside statistical likelyhood.");
        }
开发者ID:ErikDonato,项目名称:MyBot,代码行数:41,代码来源:StratsTest.cs

示例3: GetSecondHandList

        private List<SecondHand> GetSecondHandList(List<CompanyGroup.Domain.MaintainModule.SecondHand> list, string key)
        {
            List<SecondHand> results = list.FindAll(m => m.ProductId.ToLower() == key.ToLower());

            return results != null ? results : new List<SecondHand>();
        }
开发者ID:juaqaai,项目名称:CompanyGroup.ServiceLayers,代码行数:6,代码来源:ProductRepositoryTest.cs

示例4: GetPictures

        //private ProductManager GetProductManager(List<CompanyGroup.Domain.MaintainModule.ProductManager> managers, string key)
        //{
        //    ProductManager manager = managers.FirstOrDefault(m => m.EmployeeId.ToLower() == key.ToLower());

        //    return manager != null ? manager : new ProductManager("", "", "", "", "");
        //}

        private List<Picture> GetPictures(List<CompanyGroup.Domain.MaintainModule.Picture> pictures, string key)
        {
            List<Picture> pictureList = pictures.FindAll(m => m.ItemId.ToLower() == key.ToLower());

            return pictureList != null ? pictureList : new List<Picture>();
        }
开发者ID:juaqaai,项目名称:CompanyGroup.ServiceLayers,代码行数:13,代码来源:ProductRepositoryTest.cs

示例5: AliveNeighborCount

        // this can be refactored later
        public int AliveNeighborCount(int x, int y)
        {
            Cell above, below, right, left;
            Cell top_right, top_left, bottom_left, bottom_right;
            List<Cell> neighbors = new List<Cell>();

            // x, y are in "row, column" order, not Cartesian coordinates!
            above = cells[y, x - 1];
            below = cells[y, x + 1];
            right = cells[y + 1, x];
            left = cells[y - 1, x];
            top_right = cells[y + 1, x - 1];
            top_left = cells[y - 1, x - 1];
            bottom_right = cells[y + 1, x + 1];
            bottom_left = cells[y - 1, x + 1];

            neighbors.Add(above);
            neighbors.Add(below);
            neighbors.Add(right);
            neighbors.Add(left);
            neighbors.Add(top_left);
            neighbors.Add(top_right);
            neighbors.Add(bottom_left);
            neighbors.Add(bottom_right);

            return neighbors.FindAll(IsCellAlive).Count;
        }
开发者ID:jbrooks036,项目名称:JB_GameOfLife,代码行数:28,代码来源:BoundedWorld.cs

示例6: ValidateXAxisDataRange

        /// <summary>
        /// Validate if the X - Axis range matches with the data from the MarketHistory.xml file
        /// </summary>
        /// <param name="defaultItems"></param>
        /// <returns></returns>
        private bool ValidateXAxisDataRange(List<MarketHistoryItem> defaultItems)
        {
            defaultItems.Sort((a, b) => a.Date.CompareTo(b.Date));
            //TODO: find a better mechanism to check the X-Axis data
            return defaultItems.FindAll(i => Window.AutomationElement.SearchInRawTreeByName(i.Date.ToString()) != null).Count.Equals(defaultItems.Count);

            //TODO: also verify the lower and upper bound of the X-Axis - but how?
        }
开发者ID:selvendiranj,项目名称:compositewpf-copy,代码行数:13,代码来源:MarketModuleFixture.cs

示例7: testDeleteSkill

        public void testDeleteSkill()
        {
            string[] tablesToFill = { "Volunteer.xlsx", "Group.xlsx", "GroupVol.xlsx", "VolAddress.xlsx",
                                "VolAddr.xlsx", "Skill.xlsx", "VolSkill.xlsx", "VolState.xlsx",
                                "VolEmail.xlsx", "VolPhone.xlsx"};
            cExcel.RemoveAllData();
            cExcel.InsertData(tablesToFill);

            string directory = cExcel.GetHelperFilesDir();
            string hdir = cExcel.GetHelperFilesDir();
            sp_Skill_BLL skillBLL = new sp_Skill_BLL();
            string query = "SELECT * FROM [Sheet1$]";
            DataTable dt = cExcel.QueryExcelFile(hdir + "Skill.xlsx", query);
            List<Tuple<Guid, String, int, Guid?>> rowTree = new List<Tuple<Guid, string, int, Guid?>>();

            foreach (DataRow row in dt.Rows)
            {
                var key = new Guid(row["SkillID"].ToString());
                var mstr = row["MstrSkillID"].ToString() == "" ? new Nullable<Guid>() : (Guid?)(new Guid(row["MstrSkillID"].ToString()));
                var activeFlag = Convert.ToInt32(row["ActiveFlg"]);
                var skillname = row["SkillName"].ToString();
                rowTree.Add(Tuple.Create<Guid, string, int, Guid?>(key, skillname, activeFlag, mstr));
            }
            //this function returns the guid of the parent we deleted
            Func<Guid, List<Tuple<Guid, String, int, Guid?>>> deleteReturnParent = (Guid key) =>
            {
                //Check to make sure this key is still contained in the database based
                //on the description of how it should work.
                var toDeleteRow = rowTree.Find((x) => {
                        return x.Item1.Equals(key);
                });
                rowTree.Remove(toDeleteRow);
                //Find all rows that have the key as their mstrskill
                var updateRows = rowTree.FindAll((x) =>
                {
                    return x.Item4.Equals(key);
                });
                //Remove them
                rowTree.RemoveAll((x) =>
                {
                    return x.Item4.Equals(key);
                });
                var returnList = new List<Tuple<Guid, String, int, Guid?>>();
                foreach (var row in updateRows){
                    //Update them so that their master skill ids point at the master skill of the deleted node
                    var guidTpl = Tuple.Create<Guid, String, int, Guid?>(row.Item1, row.Item2, row.Item3, toDeleteRow.Item4);
                    rowTree.Add(guidTpl);
                    returnList.Add(guidTpl);
                }
                return returnList;
            };

            foreach (DataRow row in dt.Rows)
            {
                sp_Skill_DM dmskill = new sp_Skill_DM();
                dmskill.ActiveFlg = Convert.ToInt32(row["ActiveFlg"]);
                dmskill.MstrSkillID = row["MstrSkillID"].ToString() == "" ? new Nullable<Guid>() : (Guid?)(new Guid(row["MstrSkillID"].ToString()));
                dmskill.SkillID = new Guid(row["SkillID"].ToString());
                dmskill.SkillName = row["SkillName"].ToString();

                //Delete a skill
                int before = cExcel.getNumRecordsFromDB("Vol.tblVolSkill");
                skillBLL.DeleteSkillContext(dmskill);
                var updatedList = deleteReturnParent(dmskill.SkillID);
                int after = cExcel.getNumRecordsFromDB("Vol.tblVolSkill");
                //Did the skill actually get deleted.
                Assert.AreEqual(before - 1, after);
                //Did all the values get properly updated
                foreach (var updatedRow in updatedList){
                    sp_Skill_DM updatedSkill = skillBLL.ListSingleSkill(updatedRow.Item1);
                    Assert.AreEqual(updatedSkill.ActiveFlg, updatedRow.Item3);
                    Assert.AreEqual(updatedSkill.MstrSkillID, updatedRow.Item4);
                    Assert.AreEqual(updatedSkill.SkillName, updatedRow.Item2);
                }
            }
            cExcel.RemoveData(tablesToFill);
        }
开发者ID:CISC181,项目名称:VolTeerNET,代码行数:77,代码来源:utSkill.cs

示例8: GetMinTemperatureOfTheMonth

 private float GetMinTemperatureOfTheMonth(List<DailyValues> listOfDailyValues, out List<DateTime> dayNumber)
 {
     float minValue = 50F;
     List<DateTime> days = new List<DateTime>();
     for (int i = 0; i < listOfDailyValues.Count; i++)
     {
         if (listOfDailyValues[i].minTemp < minValue)
         {
             minValue = listOfDailyValues[i].minTemp;
         }
     }
     var daysNo = listOfDailyValues.FindAll(day => day.minTemp == minValue);
     dayNumber = ExtractDayFieldFromStructData(daysNo);
     return minValue;
 }
开发者ID:sorinam,项目名称:TipuriPrimitive,代码行数:15,代码来源:Meteo.cs

示例9: GetDifTemperatureOfTheMonth

 private float GetDifTemperatureOfTheMonth(List<DailyValues> listOfDailyValues, out List<DateTime> foundDifDay)
 {
     float maxValue = 0F;
     List<DateTime> days = new List<DateTime>();
     for (int i = 0; i < listOfDailyValues.Count; i++)
     {
         if ((listOfDailyValues[i].maxTemp - listOfDailyValues[i].minTemp) > maxValue)
         {
             maxValue = listOfDailyValues[i].maxTemp - listOfDailyValues[i].minTemp;
          }
     }
     var daysNo = listOfDailyValues.FindAll(day => (day.maxTemp-day.minTemp) == maxValue);
     foundDifDay = ExtractDayFieldFromStructData(daysNo);
     return maxValue;
 }
开发者ID:sorinam,项目名称:TipuriPrimitive,代码行数:15,代码来源:Meteo.cs

示例10: creerEdTTest

        public void creerEdTTest()
        {
            Astronaute a = new Astronaute("Bob", "Machin", 20);
            int numJour = 20;
            a.creerEdT(numJour);

            Assert.IsNotNull(a.getJourneesMission(), "L'emploi du temps n'a pas été créé");

            List<Journee> journees = new List<Journee>(a.getJourneesMission().Values);

            int passees = journees.FindAll(e => (!e.isModifiable())).Count;
            int enCours = journees.FindAll(e => (e.isEnCours())).Count;
            int resultPassee = 19;
            int resultEnCours = 1;

            Assert.IsTrue(passees == resultPassee && enCours == resultEnCours, "L'emploi du temps a été créé, mais " +
                "les journées n'ont pas le bon état");
        }
开发者ID:Nalhyyk,项目名称:MarsCalendar,代码行数:18,代码来源:AstronauteTest.cs

示例11: When_RandomFactor_Is_10_Percent_Then_About_10_Percent_Of_Users_Will_Have_Feature_Enabled

        public void When_RandomFactor_Is_10_Percent_Then_About_10_Percent_Of_Users_Will_Have_Feature_Enabled()
        {
            // Setup
            const string FEATURE_NAME = "Feature1";
            const string TEN_PERCENT_RANDOM_FACTOR = "0.1";
            FeatureToggle.Initialize(
                new FeatureCollection
                    {
                        NewFeature(FEATURE_NAME, true, TEN_PERCENT_RANDOM_FACTOR)
                    },
                new UserListReaderMock());

            // Execute
            const int NR_OF_REQUESTS = 100;
            var resultList = new List<bool>();
            for (int i = 0; i < NR_OF_REQUESTS; i++)
            {
                resultList.Add(FeatureToggle.IsEnabled(FEATURE_NAME));
            }

            int nrIsEnabled = resultList.FindAll(b => b == true).Count;
            int nrIsDisabled = resultList.FindAll(b => b == false).Count;
            Console.WriteLine(nrIsEnabled + "/" + nrIsDisabled);

            // Verify
            Assert.IsFalse(nrIsDisabled == 0);
            Assert.IsFalse(nrIsDisabled == NR_OF_REQUESTS);
            Assert.IsTrue(nrIsDisabled > 80);

            Assert.IsFalse(nrIsEnabled == 0);
            Assert.IsFalse(nrIsEnabled == NR_OF_REQUESTS);
            Assert.IsTrue(nrIsEnabled > 3);
        }
开发者ID:esivertsson,项目名称:asp-net-feature-toggle,代码行数:33,代码来源:RandomToggleTypeTests.cs


注:本文中的Microsoft.VisualStudio.TestTools.UnitTesting.List.FindAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。