コード例 #1
0
        public void TestBDD_AjoutSupprJedi()
        {
            List<Jedi> lj = new List<Jedi>(data.getAllJedi());
            // Création du jedi
            int id = 42;
            String name = "Sloubi";
            bool isSith = true;
            Caracteristique carac = data.getAllCaracteristic().Find(c => c.Id == 1);

            List<Caracteristique> lc = new List<Caracteristique>();
            lc.Add(carac);

            Jedi jedi = new Jedi(id, name, isSith, lc);

            // Modifications BDD
            Assert.IsFalse(data.getAllJedi().Any(j => j.Id == id), "Ce jedi est déjà présent dans la BDD !");    // On vérifie que le jedi n'est pas déjà présent dans la BDD

            lj.Add(jedi);
            data.updateJedi(lj);

            Assert.IsTrue(data.getAllJedi().Any(j => j.Id == id), "Le jedi n'a pas été ajouté");     // On vérifie que le jedi a bien été rajouté
            Assert.AreEqual(data.getAllJedi().Find(j => j.Id == id).Nom, name, "Le nom du jedi ne correspond pas");
            Assert.AreEqual(data.getAllJedi().Find(j => j.Id == id).IsSith, isSith, "Le côté de la force du jedi ne correspond pas");

            lj.Remove(lj.Find(j => j.Id == id));
            data.updateJedi(lj);

            Assert.IsFalse(data.getAllJedi().Any(j => j.Id == id), "Le jedi n'a pas été supprimé");    // On vérifie que le jedi a bien été supprimé
        }
コード例 #2
0
        public void Initialize()
        {
            //Initialize_data
            User user1 = new User() { Id = 1, Email = "123", CreatedTime = DateTime.Now, Name = "user1", NickName = "梁贵", Password = "******", };
            User user2 = new User() { Id = 2, Email = "123", CreatedTime = DateTime.Now, Name = "user2", NickName = "梁贵2", Password = "******", };
            _users = new List<User> { user1, user2 };

            Role role1 = new Role() { Id = 1, Name = "role1", Remark = "role1" };
            Role role2 = new Role() { Id = 2, Name = "role2", Remark = "role2" };
            _roles = new List<Role> { role1, role2 };
            user1.Roles = _roles;

            //Initialize_interface
            _unitOfWork = Substitute.For<IUnitOfWork>();
            _identityService = Substitute.For<IdentityService>(_unitOfWork);
            _userRepository = Substitute.For<IRepository<User, int>>();
            _roleRepository = Substitute.For<IRepository<Role, int>>();
            _userRepository.GetByKey(Arg.Any<int>()).ReturnsForAnyArgs(x => _users.Find(r => r.Id == (int)x[0]));
            _userRepository.Entities.Returns(_users.AsQueryable());

            _roleRepository.Entities.Returns(_roles.AsQueryable());
            _roleRepository.GetByKey(Arg.Any<int>()).Returns(x => _roles.Find(r => r.Id == (int)x[0]));
            _identityService.UserRepository.Returns(_userRepository);
            _identityService.RoleRepository.Returns(_roleRepository);
        }
コード例 #3
0
        public void TestBDD_AjoutSupprCarac()
        {
            List<Caracteristique> lc = new List<Caracteristique>(data.getAllCaracteristic());
            // Création de la caractéristique
            int id = 42;
            EDefCaracteristique def = EDefCaracteristique.Chance;
            String text = "Carac ajoutée Jedi";
            ETypeCaracteristique type = ETypeCaracteristique.Jedi;
            int val = 20;
            Caracteristique carac = new Caracteristique(id, def, text, type, val);

            // Modifications BDD
            Assert.IsFalse(data.getAllCaracteristic().Any(c => c.Id == id), "Cette caractéristique est déjà présente dans la BDD !");    // On vérifie que la caractéristique n'est pas déjà présente dans la BDD
            
            lc.Add(carac);
            data.updateCaracteristique(lc);

            Assert.IsTrue(data.getAllCaracteristic().Any(c => c.Id == id), "La caractéristique n'a pas été ajoutée");     // On vérifie que la caractéristique a bien été rajoutée
            Assert.AreEqual(data.getAllCaracteristic().Find(c => c.Id == id).Definition, def);
            Assert.AreEqual(data.getAllCaracteristic().Find(c => c.Id == id).Nom, text);
            Assert.AreEqual(data.getAllCaracteristic().Find(c => c.Id == id).Type, type);
            Assert.AreEqual(data.getAllCaracteristic().Find(c => c.Id == id).Valeur, val);

            lc.Remove(lc.Find(c => c.Id == id));
            data.updateCaracteristique(lc);

            Assert.IsFalse(data.getAllCaracteristic().Any(c => c.Id == id), "La caractéristique n'a pas été supprimée");    // On vérifie que la caractéristique a bien été supprimée
        }
コード例 #4
0
        private void AssertViewModelContents( AllFoodGroupsViewModel viewModel, List<FoodGroup> foodGroups )
        {
            Assert.AreEqual( foodGroups.Count, viewModel.Items.Count );

             foreach (var foodGroup in viewModel.Items)
             {
            var foodGroupFromRepository = foodGroups.Find( fg => fg.ID == foodGroup.ID );

            Assert.IsNotNull( foodGroup );
            Assert.AreEqual( foodGroupFromRepository.Name, foodGroup.Name );
             }
        }
コード例 #5
0
        private void AssertViewModelContents( AllFoodItemsViewModel viewModel, List<FoodItem> foods )
        {
            Assert.AreEqual( foods.Count, viewModel.Items.Count );

             foreach (var food in viewModel.Items)
             {
            var foodItemFromRepository = foods.Find( f => f.ID == food.ID );

            Assert.IsNotNull( food );
            Assert.AreEqual( foodItemFromRepository.Name, food.Name );
             }
        }
コード例 #6
0
        private void AssertViewModelContents( AllMealTypesViewModel viewModel, List<MealType> mealTypes )
        {
            Assert.AreEqual( mealTypes.Count, viewModel.Items.Count );

             foreach (var mealType in viewModel.Items)
             {
            var mealTypeFromRepository = mealTypes.Find( mt => mt.ID == mealType.ID );

            Assert.IsNotNull( mealType );
            Assert.AreEqual( mealTypeFromRepository.Name, mealType.Name );
             }
        }
コード例 #7
0
        private void AssertViewModelContents( AllMealTemplatesViewModel viewModel, List<MealTemplate> mealTemplates )
        {
            Assert.AreEqual( mealTemplates.Count, viewModel.Items.Count );

             foreach (var template in viewModel.Items)
             {
            var templateFromRepository = mealTemplates.Find( mt => mt.ID == template.ID );

            Assert.IsNotNull( template );
            Assert.AreEqual( templateFromRepository.Name, template.Name );
            Assert.AreEqual( templateFromRepository.Calories, template.Calories );
             }
        }
コード例 #8
0
ファイル: ServiceTest.cs プロジェクト: Goblinftw/Upteka
        public void DeleteProduct()
        {
            var data = new List<Product>
            {
                new Product {Name = "BBB", BarCode = "112115", InStock = 15, Id = 1},
                new Product {Name = "ZZZ", BarCode = "112116", InStock = 23, Id = 2},
                new Product {Name = "AAA", BarCode = "112116", InStock = 30, Id = 3}
            };

            var mockSet = new Mock<DbSet<Product>>()
                .SetupData(data, objects => data.SingleOrDefault(d => d.Id == (int)objects.First()));
            

            var mockContext = new Mock<DAL.IDbContext>();
            mockContext.Setup(m => m.Set<Product>()).Returns(mockSet.Object);
            var service = new ProductService(mockContext.Object);

            service.Delete(1);
            Assert.IsNull(data.Find(x => x.Id == 1));
        }
コード例 #9
0
        public void Must_be_able_to_follow_another_user()
        {
            var test = new List<User>()
                       {
                           new User()
                           {
                               Name = "Alice",
                               _peopleFollowing = new List<User>()
                           }
                       };
            _userList = new UserList();
            _userList.ListOfUsers = test;

            var username = "******";
            var usernameOfFollowed = "Bob";

            _sut = new Follow(_userList);

            _sut.FollowUser(username, usernameOfFollowed);

            var user = test.Find(u => u.Name == username);
            Assert.AreEqual(user._peopleFollowing.Count, 1);
        }
コード例 #10
0
ファイル: Game.cs プロジェクト: B3J4y/Poker
        public Game(List<Player> players, int bb, int sb, Boolean train)
	    {
            log.Debug("Game() - Begin");
            log.Debug("New Game - Player: " + players.Count + " Stakes: " + sb + "/" + bb);
            trainMode = train;
            boolCancel = false;
            blindLevel = 0;
            foreach (Player p in players)
            {
                log.Info("Name: " + p.name + "; Position: " + p.position + "; Stack: " + p.stack);
            }
            this.players = players;
            this.smallBlind = sb;
            this.bigBlind = bb;
            pot = new Pot();
            round = 0;
            players.Sort((x, y) => x.position.CompareTo(y.position));
            for (int i = 2; i < players.Count + 2; i++)
            {
                players.Find(x => (x.position > (i - 2)) && (x.ingamePosition == -1)).ingamePosition = i;
            }
            log.Debug("Game() - End");
	    }
コード例 #11
0
        static void Verify_IsSelected_PublishesDebugSelectionChangedEventArgs(ActivityType activityType, ActivitySelectionType expectedSelectionType, int expectedCount, bool setIsSelected = false)
        {
            var expected = new DebugState { DisplayName = "IsSelectedTest", ID = Guid.NewGuid(), ActivityType = activityType };

            var events = new List<DebugSelectionChangedEventArgs>();

            var selectionChangedEvents = EventPublishers.Studio.GetEvent<DebugSelectionChangedEventArgs>();
            selectionChangedEvents.Subscribe(events.Add);

            var envRep = CreateEnvironmentRepository();

            var vm = new DebugStateTreeViewItemViewModelMock(envRep.Object) { Content = expected };

            if(setIsSelected)
            {
                // clear constructor events
                events.Clear();

                // events are only triggered when property changes to true
                vm.IsSelected = false;

                vm.SelectionType = expectedSelectionType;
                vm.IsSelected = true;
            }
            else
            {
                vm.IsSelected = false;
                vm.SelectionType = expectedSelectionType;
            }

            EventPublishers.Studio.RemoveEvent<DebugSelectionChangedEventArgs>();

            Assert.AreEqual(expectedCount, events.Count);
            if(events.Count > 0)
            {
                var foundEvent = events.Find(args => args.SelectionType == expectedSelectionType);
                Assert.IsNotNull(foundEvent);
                Assert.AreSame(expected, foundEvent.DebugState);
            }
        }
コード例 #12
0
 public void SearchCollection1SearchTermMultiplePropertiesDuplicateResultTest()
 {
     //Happy flow
     var searchCollection = new List<HelpItem>(_helpItems);
     searchCollection.Insert(2, searchCollection[3]);
     var target = new SearchList<HelpItem>(searchCollection);
     const string searchTerm = "Help omschrijving 4";
     var expected = searchCollection.Find(s => s.HelpDescription == searchTerm);
     _propertyNames[4] = string.Empty;
     var actual = target.SearchCollection1SearchTermAllProperties(searchTerm, _propertyNames);
     Assert.IsTrue(actual.Contains(expected));
 }
コード例 #13
0
		public void FindDisplaysClearErrorMessageWhenMoreThanOneElementMatchesCondition()
		{
			var emptyList = new List<int> { 2, 4, 6 };
			Expression<Func<int, bool>> condition = x => x > 2;
			var ex = TestUtils.ExpectException<InvalidOperationException>(() => emptyList.Find(condition));
			Assert.AreEqual("Sequence of type '" + IntTypeName + "' contains more than element that matches the condition '" + condition + "'. The first 2 are '4' and '6'", ex.Message);
		}
コード例 #14
0
		public void FindDisplaysClearErrorMessageWhenNoElementMatchesCondition()
		{
			var emptyList = new List<int> { 1, 2,3};
			Expression<Func<int, bool>> expr = x => x == 4;
			var ex = TestUtils.ExpectException<InvalidOperationException>(() => emptyList.Find(expr));
			Assert.AreEqual("Sequence of type '" + IntTypeName + "' contains no element that matches the condition '" + expr + "'", ex.Message);
		}
コード例 #15
0
ファイル: FindTester.cs プロジェクト: jehugaleahsa/NDex
 public void TestFind_NullComparer_Throws()
 {
     IExpandableSublist<List<int>, int> list = new List<int>().ToSublist();
     int value = 0;
     IEqualityComparer<int> comparer = null;
     list.Find(value, comparer);
 }
コード例 #16
0
ファイル: CopyToTest.cs プロジェクト: hmehr/OSS
        /// <summary>
        /// Compares the chapters.
        /// </summary>
        /// <param name="reference">The reference.</param>
        /// <param name="copy">The copy.</param>
        /// <remarks>Documented by Dev03, 2008-09-26</remarks>
        private void CompareChapters(IList<IChapter> reference, IList<IChapter> copy)
        {
            Assert.AreEqual<int>(reference.Count, copy.Count, "Numbers of chapters are not equal");

            //create Lists to work on
            List<IChapter> referenceList = new List<IChapter>();
            List<IChapter> copyList = new List<IChapter>();
            referenceList.AddRange(reference);
            copyList.AddRange(copy);

            //compare the cards
            foreach (IChapter chapter in reference)
            {
                IChapter match = copyList.Find(
                    delegate(IChapter chapterCopy)
                    {
                        bool isMatch = true;
                        isMatch = isMatch && (chapter.Title == chapterCopy.Title);
                        isMatch = isMatch && (chapter.Description == chapterCopy.Description);

                        Debug.WriteLine("#####" + chapter.Id);
                        Debug.WriteLine("########" + chapter.Title);
                        Debug.WriteLine("########" + chapter.Description);
                        Debug.WriteLine("########" + chapterCopy.Title);
                        Debug.WriteLine("########" + chapterCopy.Description);
                        Debug.WriteLine("########" + isMatch);

                        return isMatch;
                    }
                );

                Assert.IsTrue(match != null, "Chapter not found");

                //AAB_MBR not implemented for XML# CompareSettings(chapter.Settings, match.Settings);
                if ((chapter.Settings != null) && (match.Settings != null))
                {
                    CompareStyles(chapter.Settings.Style, match.Settings.Style);
                }
            }
        }
コード例 #17
0
ファイル: FindTester.cs プロジェクト: jehugaleahsa/NDex
 public void TestFind_NullComparison_Throws()
 {
     IExpandableSublist<List<int>, int> list = new List<int>().ToSublist();
     int value = 0;
     Func<int, int, bool> comparison = null;
     list.Find(value, comparison);
 }
コード例 #18
0
        public void ValidMealTypesContainsAllMealTypes()
        {
            var dataRepositoryMock = new Mock<IDataRepository>();

             var allMealTypes = new List<MealType>();
             allMealTypes.Add( new MealType( Guid.NewGuid(), "Type1", "", DateTime.Now, false ) );
             allMealTypes.Add( new MealType( Guid.NewGuid(), "Type2", "", DateTime.Now, false ) );
             allMealTypes.Add( new MealType( Guid.NewGuid(), "Type3", "", DateTime.Now, false ) );
             allMealTypes.Add( new MealType( Guid.NewGuid(), "Type4", "", DateTime.Now, false ) );

             dataRepositoryMock.Setup( x => x.GetAllFoodItems() )
            .Returns( new ReadOnlyCollection<FoodItem>( new List<FoodItem>() ) );
             dataRepositoryMock.Setup( x => x.GetAllMealTypes() )
            .Returns( new ReadOnlyCollection<MealType>( allMealTypes ) );

             var viewModel = CreateEmptyViewModel( dataRepositoryMock );

             Assert.AreEqual( allMealTypes.Count, viewModel.ValidMealTypes.Items.Count );
             foreach (var mealType in viewModel.ValidMealTypes.Items)
             {
            Assert.IsNotNull( allMealTypes.Find( x => x.Name == mealType.Name ) );
             }
             dataRepositoryMock.VerifyAll();
        }
コード例 #19
0
        public void ValidFoodItemsContainsAllFoodItems()
        {
            var dataRepositoryMock = new Mock<IDataRepository>();

             var allFoodItems = new List<FoodItem>();
             allFoodItems.Add( new FoodItem( Guid.NewGuid(), "Item1", "", 42 ) );
             allFoodItems.Add( new FoodItem( Guid.NewGuid(), "Item2", "", 52 ) );
             allFoodItems.Add( new FoodItem( Guid.NewGuid(), "Item3", "", 63 ) );
             allFoodItems.Add( new FoodItem( Guid.NewGuid(), "Item4", "", 78 ) );
             allFoodItems.Add( new FoodItem( Guid.NewGuid(), "Item5", "", 39 ) );

             dataRepositoryMock.Setup( x => x.GetAllFoodItems() )
            .Returns( new ReadOnlyCollection<FoodItem>( allFoodItems ) );
             dataRepositoryMock.Setup( x => x.GetAllMealTypes() )
            .Returns( new ReadOnlyCollection<MealType>( new List<MealType>() ) );

             var viewModel = CreateEmptyViewModel( dataRepositoryMock );

             Assert.AreEqual( allFoodItems.Count, viewModel.ValidFoodItems.Items.Count );
             foreach (var foodItem in viewModel.ValidFoodItems.Items)
             {
            Assert.IsNotNull( allFoodItems.Find( x => x.Name == foodItem.Name ) );
             }
             dataRepositoryMock.VerifyAll();
        }
コード例 #20
0
ファイル: utSkill.cs プロジェクト: CISC181/VolTeerNET
        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);
        }
コード例 #21
0
        public void AtualizaMultiplosRegistros()
        {
            // Arrange
            EstudanteDominio oEstudanteDominio = null;
            List<Estudante> oEstudanteList = null;
            Boolean isSucesso;

            // Act
            oEstudanteDominio = new EstudanteDominio();

            // selecionando e adicionando na lista
            oEstudanteList = new List<Estudante>()
            {
                  oEstudanteDominio.Selecionar(2)
                , oEstudanteDominio.Selecionar(3)
                , oEstudanteDominio.Selecionar(5)
            };

            // alterando valores
            oEstudanteList.Find(c => c.ID == 2).Nome = "Reginaldo Rossi";
            oEstudanteList.Find(c => c.ID == 3).Nome = "Mariana de Melo";
            oEstudanteList.Find(c => c.ID == 5).Nome = "Karine Roque";

            oEstudanteDominio = new EstudanteDominio();
            isSucesso = oEstudanteDominio.Atualizar(oEstudanteList);

            // Assert
            Assert.IsTrue(isSucesso);

            oEstudanteDominio = null;
            oEstudanteList = null;
        }
コード例 #22
0
ファイル: Game.cs プロジェクト: B3J4y/Poker
        /// <summary>
        /// determines the winning players and shows how much they won
        /// </summary>
        /// <returns></returns>
        public List<Winner> whoIsWinner(Pot pot, List<Player> playersInGame)
        {
            log.Debug("whoIsWinner() - Begin");
            List<Winner> result = new List<Winner>();
            //List<Player> playersInGame = players.FindAll(x => x.isActive);
            playersInGame.AddRange(pot.player);
            List<KeyValuePair<Player, Hand>> playerHand = new List<KeyValuePair<Player, Hand>>();
            Console.WriteLine(boardToString());
            if (playersInGame.Count > 0)
            {

                //determines Hand Value
                foreach (Player player in playersInGame)
                {
                    playerHand.Add(new KeyValuePair<Player, Hand>(player, new Hand(player.getCardsToString(), boardToString())));
                    Console.WriteLine(player.name + " " + player.getCardsToString() + " " + new Hand(player.getCardsToString(), boardToString()).HandValue + " " + new Hand(player.getCardsToString(), boardToString()).HandTypeValue);
                }
                playerHand.Sort((x, y ) => x.Value.HandValue.CompareTo(y.Value.HandValue));
                //WinnerHands
                result.Add(new Winner(playerHand[playerHand.Count - 1].Key, playerHand[playerHand.Count - 1].Value.HandTypeValue.ToString()));
                for (int i = playerHand.Count - 2; i >= 0; i--)
                {
                    if (playerHand[playerHand.Count - 1].Value.HandValue == playerHand[i].Value.HandValue)
                    {
                        result.Add(new Winner(playerHand[i].Key, playerHand[i].Value.HandTypeValue.ToString()));

                    }
                    else
                    {
                        playerHand[i].Key.isActive = false;
                    }
                }
                if (result.Count == 1)
                {
                    result[0].value = pot.value;
                    result[0].player.stack += result[0].value;
                    result[0].player.isAllin = false;
                }
                else
                {
                    int mod = (pot.value / result.Count) % bigBlind;
                    Player first = new Player(activePlayer);
                    try
                    {
                        // nonActives = players.FindAll(x => (!x.isActive)).Count;
                        first = whoIsNext(players.Count - nonActives - 1, false);
                    }
                    catch (NoPlayerInGameException e)
                    {
                        first = activePlayer;
                    }

                    while (mod > 0)
                    {
                        Winner myPlayer = result.Find(x => x.player.name == first.name);
                        myPlayer.value += smallBlind;
                        pot.value -= smallBlind;
                        mod = (pot.value / result.Count) % bigBlind;
                    }

                    for (int j = 0; j < result.Count; j++)
                    {
                        result[j].value += (pot.value / result.Count);
                        result[j].player.stack += result[j].value;
                        if (result[j].player.stack > 0)
                        {

                            result[j].player.isAllin = false;
                        }
                    }
                }
            
                foreach(Winner w in result){
                    Logger.action(this, w.player, Action.playerAction.wins, w.value, board);
                }
            }
            if (pot.sidePot != null)
            {
                result.AddRange(whoIsWinner(pot.sidePot, playersInGame));
                pot.sidePot = null;
            }
            pot.value = 0;
            pot.potThisRound = 0;
            pot.player = new List<Player>();
            log.Debug("whoIsWinner() - End");
            return result;
        }
コード例 #23
0
 private IList<Edge> GetUniqueEdgesWithStrength(IEnumerable<Edge> allEdges)
 {
     var rtn = new List<Edge>();
       foreach (var edge in allEdges)
       {
     var existingEdge = rtn.Find(e => e.Name == edge.Name);
     if (existingEdge != null)
     {
       existingEdge.Strength++;
     }
     else
     {
       rtn.Add(edge);
     }
       }
       return rtn;
 }
コード例 #24
0
ファイル: CopyToTest.cs プロジェクト: hmehr/OSS
 /// <summary>
 /// Finds the chapter.
 /// </summary>
 /// <param name="list">The list chapters to search.</param>
 /// <param name="chapter2find">The chapter to find.</param>
 /// <returns></returns>
 /// <remarks>Documented by Dev03, 2008-09-26</remarks>
 private IChapter FindChapter(IList<IChapter> chapters2search, IChapter chapter2find)
 {
     List<IChapter> list = new List<IChapter>();
     list.AddRange(chapters2search);
     IChapter match = list.Find(
         delegate(IChapter chapter)
         {
             bool isMatch = true;
             isMatch = isMatch && (chapter2find.Title == chapter.Title);
             isMatch = isMatch && (chapter2find.Description == chapter.Description);
             return isMatch;
         }
     );
     return match;
 }
コード例 #25
0
ファイル: FindTester.cs プロジェクト: jehugaleahsa/NDex
 public void TestFind_NullPredicate_Throws()
 {
     IExpandableSublist<List<int>, int> list = new List<int>().ToSublist();
     Func<int, bool> predicate = null;
     list.Find(predicate);
 }
コード例 #26
0
ファイル: CopyToTest.cs プロジェクト: hmehr/OSS
 /// <summary>
 /// Finds the chapter.
 /// </summary>
 /// <param name="chapters2search">The list chapters to search.</param>
 /// <param name="chapter2find">The chapter id to find.</param>
 /// <returns></returns>
 /// <remarks>Documented by Dev03, 2008-09-26</remarks>
 private IChapter FindChapter(IList<IChapter> chapters2search, int chapter2find)
 {
     List<IChapter> list = new List<IChapter>();
     list.AddRange(chapters2search);
     IChapter match = list.Find(
         delegate(IChapter chapter)
         {
             bool isMatch = true;
             isMatch = isMatch && (chapter2find == chapter.Id);
             return isMatch;
         }
     );
     return match;
 }
コード例 #27
0
ファイル: SparqlTest.cs プロジェクト: Garwin4j/BrightstarDB
        private static void CompareTripleCollections(BaseTripleCollection actualTriples, BaseTripleCollection expectedTriples, bool reduced)
        {
            var actualTripleList = new List<Triple>(actualTriples);
            var expectedTripleList = new List<Triple>(expectedTriples);
            var alreadySeen = new HashSet<Triple>();
            var bnodeMap = new Dictionary<string, string>();

            while (actualTripleList.Count > 0)
            {
                var at = actualTripleList[0];
                actualTripleList.Remove(at);
                if (alreadySeen.Contains(at)) continue;
                var match = expectedTripleList.Find(x => TripleMatch(x, at, bnodeMap));
                if (match == null)
                {
                    Assert.Fail("No match found for actual triple {0} in expected triples set", at);
                }

                expectedTripleList.Remove(match);
                alreadySeen.Add(at);
            }
            Assert.IsTrue(actualTripleList.Count == 0);
            Assert.IsTrue(expectedTripleList.Count == 0, "Left with some unmatched triples in the expected triples set: {0}",
                String.Join(",", expectedTripleList.Select(t => t.ToString())));
        }
コード例 #28
0
        /// <summary>
        /// Tests if a switch case (JAMC) belongs to more than one opcode.
        /// </summary>
        /// <param name="formula">The specific formula.</param>
        private void Test_Formula_JAMC(Base_Formula formula)
        {
            // contains all the results
            List<UInt16> resultList = new List<UInt16>();
            for (UInt16 opcode = 0; opcode < UInt16.MaxValue; ++opcode)
            {
                // bad type opcode
                if (!formula.FormulaChecker_JAMC(opcode))
                    continue;
                // calculate the switch case
                UInt16 switchCase = formula.Formula_JAMC(opcode);
                UInt16 alreadyHaveThis = resultList.Find(
                    delegate(UInt16 x)
                    {
                        return x == switchCase;
                    }
                );
                // assert if already contains that switch case
                Assert.IsNotNull(alreadyHaveThis, "More than one opcode belong to this switch case: 0x{0:X4}, formula: {1}", switchCase, formula.GetType().ToString());

                resultList.Add(switchCase);
            }
        }
コード例 #29
0
ファイル: CopyToTest.cs プロジェクト: hmehr/OSS
        /// <summary>
        /// Compares the cards.
        /// </summary>
        /// <param name="reference">The reference.</param>
        /// <param name="copy">The copy.</param>
        /// <remarks>Documented by Dev03, 2008-09-26</remarks>
        private void CompareCards(IList<ICard> reference, IList<ICard> copy, Dictionary referenceDic, Dictionary copyDic)
        {
            Assert.AreEqual<int>(reference.Count, copy.Count, "Numbers of cards are not equal");

            //create Lists to work on
            List<ICard> referenceList = new List<ICard>();
            List<ICard> copyList = new List<ICard>();
            referenceList.AddRange(reference);
            copyList.AddRange(copy);

            //compare the cards
            foreach (ICard card in reference)
            {
                ICard match = copyList.Find(
                    delegate(ICard cardCopy)
                    {
                        bool isMatch = true;
                        isMatch = isMatch && (card.Active == cardCopy.Active);
                        isMatch = isMatch && (card.Answer.ToString() == cardCopy.Answer.ToString());
                        isMatch = isMatch && (card.Question.ToString() == cardCopy.Question.ToString());
                        isMatch = isMatch && (card.AnswerExample.ToString() == cardCopy.AnswerExample.ToString());
                        isMatch = isMatch && (card.QuestionExample.ToString() == cardCopy.QuestionExample.ToString());
                        isMatch = isMatch && (card.AnswerDistractors.ToString() == cardCopy.AnswerDistractors.ToString());
                        isMatch = isMatch && (card.QuestionDistractors.ToString() == cardCopy.QuestionDistractors.ToString());
                        isMatch = isMatch && (card.Box == cardCopy.Box);
                        IChapter chapter2search = FindChapter(referenceDic.Chapters.Chapters, card.Chapter);
                        isMatch = isMatch && (FindChapter(copyDic.Chapters.Chapters, chapter2search) != null);

                        Debug.WriteLine("#####" + card.Id);
                        Debug.WriteLine("########" + card.Answer);
                        Debug.WriteLine("########" + cardCopy.Answer);
                        Debug.WriteLine("########" + isMatch);

                        return isMatch;
                    }
                );

                Assert.IsTrue(match != null, String.Format("Card not found:\n{0}", card.ToString()));
                //CompareMedia(card, match);

                //AAB_MBR not implemented for XML# CompareSettings(card.Settings, match.Settings);
                if ((card.Settings != null) && (match.Settings != null))
                {
                    CompareStyles(card.Settings.Style, match.Settings.Style);
                }
            }
        }
コード例 #30
0
ファイル: Game.cs プロジェクト: B3J4y/Poker
        private KeyValuePair<Player, List<Action>> getActions()
        {
            log.Debug("getActions() - Begin");
            List<Action> actions = new List<Action>();
            actions.Add(new Action(Action.playerAction.fold, 0));
            if (activePlayer.inPot == pot.amountPerPlayer)
            {
                actions.Add(new Action(Action.playerAction.check, 0));
            }
            else
            {
                if (pot.amountPerPlayer - activePlayer.inPot <= activePlayer.stack)
                {
                    actions.Add(new Action(Action.playerAction.call, (pot.amountPerPlayer - activePlayer.inPot)));
                }
                else
                {
                    actions.Add(new Action(Action.playerAction.call, (activePlayer.stack)));
                }
            }
            if (pot.amountPerPlayer == 0)
            {
                if (bigBlind < activePlayer.stack)
                {
                    actions.Add(new Action(Action.playerAction.bet, (bigBlind)));
                }
                else
                {
                    actions.Add(new Action(Action.playerAction.bet, (activePlayer.stack)));
                }
            }
            else
            {
                Action call = actions.Find(x => x.action == Action.playerAction.call);
                if ((pot.raiseSize + call.amount) < activePlayer.stack)
                {
                    actions.Add(new Action(Action.playerAction.raise, (pot.raiseSize) + call.amount));
                }
                else
                {
                    actions.Add(new Action(Action.playerAction.raise, (activePlayer.stack)));
                }
            }

            log.Debug("getActions() - End");
            return new KeyValuePair<Player, List<Action>>(activePlayer, actions);
        }