private void Init(IProvider provider) { worldCup = new WorldCup(); worldCup.TeamProvider = provider; preRound = new PreRound(); preRound.InputTeams = worldCup.TeamList; }
public void IsNotValid() { var movies = GetListOfMovies(7); var worldCup = new WorldCup(movies); Assert.IsFalse(worldCup.IsValid()); }
public void IsValid() { var movies = GetListOfMovies(8); var worldCup = new WorldCup(movies); Assert.IsTrue(worldCup.IsValid()); }
public ActionResult DeleteConfirmed(int id) { WorldCup worldCup = db.WorldCups.Find(id); db.WorldCups.Remove(worldCup); db.SaveChanges(); return(RedirectToAction("Index")); }
private void MainGrid_Loaded(object sender, RoutedEventArgs e) { worldCup = new WorldCup(); worldCup.TeamProvider = new FootballLib.DataProviders.SqlProvider(); PreRound preRound = new PreRound(); PlayOff playOff = new PlayOff(); OctRound octRound = new OctRound(); QuadRound quadRound = new QuadRound(); FinalRound finalRound = new FinalRound(); preRound.InputTeams = worldCup.TeamList; playOff.InputTeams = preRound.Play(); resultPlayOff = playOff.Play(); matchesPlayOff = playOff.MatchList; octRound.InputTeams = new List <Team>(resultPlayOff); resultOct = octRound.Play(); matchesOct = octRound.MatchList; quadRound.InputTeams = new List <Team>(resultOct); resultQuad = quadRound.Play(); matchesQuad = quadRound.MatchList; finalRound.InputTeams = new List <Team>(resultQuad); Team championship = finalRound.Play()[0]; matchesFinal = finalRound.MatchList; groupA.OnClick += Group_OnClick; groupB.OnClick += Group_OnClick; groupC.OnClick += Group_OnClick; groupD.OnClick += Group_OnClick; groupE.OnClick += Group_OnClick; groupF.OnClick += Group_OnClick; groupG.OnClick += Group_OnClick; groupH.OnClick += Group_OnClick; sc1.OnClick += Sc_Playoff; sc2.OnClick += Sc_Playoff; sc3.OnClick += Sc_Playoff; sc4.OnClick += Sc_Playoff; sc5.OnClick += Sc_Playoff; sc6.OnClick += Sc_Playoff; sc7.OnClick += Sc_Playoff; sc8.OnClick += Sc_Playoff; groupQuad1.OnClick += GroupQuad_OnClick; groupQuad2.OnClick += GroupQuad_OnClick; groupQuad3.OnClick += GroupQuad_OnClick; groupQuad4.OnClick += GroupQuad_OnClick; scQ1.OnClick += ScQ_OnClick; scQ2.OnClick += ScQ_OnClick; scQ3.OnClick += ScQ_OnClick; scQ4.OnClick += ScQ_OnClick; }
private void Init(IProvider provider) { worldCup = new WorldCup(); worldCup.TeamProvider = provider; worldCup.RoundList.Add(new PreRound()); worldCup.RoundList.Add(new PlayOff()); worldCup.RoundList.Add(new OctRound()); worldCup.RoundList.Add(new QuadRound()); worldCup.RoundList.Add(new FinalRound()); }
public ActionResult Edit([Bind(Include = "WC_Id,Location,Year")] WorldCup worldCup) { if (ModelState.IsValid) { db.Entry(worldCup).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(worldCup)); }
public ActionResult Create([Bind(Include = "WC_Id,Location,Year")] WorldCup worldCup) { if (ModelState.IsValid) { db.WorldCups.Add(worldCup); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(worldCup)); }
public void Init(IProvider provider) { worldCup = new WorldCup(); worldCup.TeamProvider = provider; preRound = new PreRound(); preRound.InputTeams = worldCup.TeamList; playOff = new PlayOff(); playOff.InputTeams = preRound.Play(); }
public void RunWorldCup() { var top1 = new Movie() { Title = "Vingadores: Guerra Infinita", Score = 8.8M }; var top2 = new Movie() { Title = "Os Incríveis 2", Score = 8.5M }; var listMovies = new List <Movie>() { top2, new Movie() { Title = "Jurassic World: Reino Ameaçado", Score = 6.7M }, new Movie() { Title = "Oito Mulheres e um Segredo", Score = 6.3M }, new Movie() { Title = "Hereditário", Score = 7.8M }, top1, new Movie() { Title = "Deadpool 2", Score = 8.1M }, new Movie() { Title = "Han Solo: Uma História Star Wars", Score = 7.2M }, new Movie() { Title = "Thor: Ragnarok", Score = 7.9M }, }; var worldCup = new WorldCup(listMovies); var rankTopTwo = worldCup.RunCup(); Assert.AreEqual(2, rankTopTwo.Count); Assert.AreEqual(top1, rankTopTwo.FirstOrDefault()); Assert.AreEqual(top2, rankTopTwo.LastOrDefault()); }
public void GetWinnerWithSameScore() { var top1 = new Movie() { Title = "Toy Story 1", Score = 10 }; var top2 = new Movie() { Title = "Toy Story 4", Score = 10 }; var winner = WorldCup.GetWinner(top1, top2).FirstOrDefault(); Assert.AreEqual(top1, winner); }
public void GetWinner() { var top1 = new Movie() { Title = "Vingadores: Guerra Infinita", Score = 8.8M }; var top2 = new Movie() { Title = "Os Incríveis 2", Score = 8.5M }; var winner = WorldCup.GetWinner(top1, top2).FirstOrDefault(); Assert.AreEqual(top1, winner); }
// GET: WorldCups/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } WorldCup worldCup = db.WorldCups.Find(id); if (worldCup == null) { return(HttpNotFound()); } return(View(worldCup)); }
public async void Create_Given8MovieIdsIfReturns8Movies_ReturnWorldCup() { // Arrange var movieIds = new List <string>( new string[] { "id1", "id2", "id3", "id4", "id5", "id6", "id7", "id8" } ); var movies = new List <Movie>( new Movie[] { new Movie { Id = "id1" }, new Movie { Id = "id2" }, new Movie { Id = "id3" }, new Movie { Id = "id4" }, new Movie { Id = "id5" }, new Movie { Id = "id6" }, new Movie { Id = "id7" }, new Movie { Id = "id8" } } ); var worldCup = new WorldCup(); _movieService.Setup(x => x.GetByMovieId(movieIds)) .Returns(Task.FromResult(movies)); _worldCupBuilder.Setup(x => x.Build(movies)) .Returns(worldCup); // Act var worldCupResponse = await _worldCupService.Create(movieIds); // Assert Assert.Equal(worldCup, worldCupResponse); }
private void Init(IProvider provider) { worldCup = new WorldCup(); worldCup.TeamProvider = provider; preRound = new PreRound(); playOff = new PlayOff(); octRound = new OctRound(); quadRound = new QuadRound(); preRound.InputTeams = worldCup.TeamList; playOff.InputTeams = preRound.Play(); octRound.InputTeams = playOff.Play(); quadRound.InputTeams = octRound.Play(); }
public async Task <ActionResult <List <MovieViewModel> > > GetWinner(List <string> moviesIds) { var moviesViewModel = (await _movieWorldCupService.GetMovies()) .Where(a => moviesIds.Contains(a.Id)); var movies = _mapper.Map <List <Movie> >(moviesViewModel); var worldCup = new WorldCup(movies); if (!worldCup.IsValid()) { return(UnprocessableEntity()); } return(_mapper.Map <List <MovieViewModel> >(worldCup.RunCup())); }
static void SupprimerTOUS(ArrayList pers, string nomRecherche) { WorldCup aChercher = new WorldCup(nomRecherche, ' ', 0.0, 0.0, 0); int indice = 123456, rang = 0; while (indice >= 0) { indice = pers.BinarySearch(aChercher); Console.WriteLine(indice); if (indice >= 0) { Console.WriteLine("{0, 2:D}) {1}", ++rang, pers[indice]); pers.RemoveAt(indice); } } if (rang > 0) Console.WriteLine("On a supprime {0} WorldCup(s)", rang); else Console.WriteLine("On ne trouve pas:\n" + aChercher); Console.WriteLine(); }
// nescessaire pour la fonction Trier static void Permuter(ref WorldCup a, ref WorldCup b){ WorldCup tempo = a; a = b; b = tempo; }
//Redefinition de Afficher sans message static void Afficher(WorldCup[] pers, int i){ Console.WriteLine("{0}) {1} {2} {3} tasse(s)", i, pers[i].sexe, pers[i].naissance, pers[i].nbCafe); }
//Soustraire une tasse de café de chaque WorldCup static void SousCafe (WorldCup[]pers , char sexeVoulu){ for (int i = 0; i < pers.Length; i++){ if (pers[i].sexe == sexeVoulu) pers[i].Cafe = pers[i].nbCafe - 1; } }
//Retourne l'indice de la WorldCup qui a bus le plus de café static int MaxiCafe(WorldCup[] pers, char sexeVoulu){ int plusGrand = int.MinValue; int indice = 0; for (int j = 0; j < pers.Length; j++){ if (pers[j].nbCafe > plusGrand && pers[j].sexe == sexeVoulu){ plusGrand = pers[j].nbCafe; indice = j; } } return indice; }
//Affiche le tableau des WorldCups static void Afficher(WorldCup[] pers, string mess){ Console.WriteLine(mess); for(int i = 0; i < pers.Length; i++){ Console.WriteLine("{0}) {1} {2} {3} tasse(s)", i, pers[i].sexe, pers[i].naissance, pers[i].Cafe); } Console.WriteLine(); }
static void Main(string[] args){ WorldCup pers1 = new WorldCup('F', "19/02/1996", 3), pers2 = new WorldCup('M', "27/07/1990");// par défaut 0 tasse pers1.Afficher("Informations de pers1 : "); pers2.Afficher("Informations de pers2 : "); WorldCup[] pers = { new WorldCup('F', "16/11/1992", 2), new WorldCup('F', "02/05/1990", 1), new WorldCup('M', "23/05/1990", 5), new WorldCup('F', "19/02/1985"), new WorldCup('F', "30/06/1991", 3), new WorldCup('M', "14/05/1997", 1)}; //1 Afficher(pers, "tableaux pers avant le tri : "); //2 Afficher(pers, MaxiCafe(pers, 'F'), "La femme qui consomme le plus de café : "); //3 SousCafe(pers, 'M'); Afficher(pers, "Après une soustraction d'un café des hommes : "); //4 Trier(pers); // selon le nombre de café consommé. Afficher(pers, "Trier selon le nombre de café conssomé : "); //5 CountMoisAffiche(pers, "mai", "05"); }
//-------------------------------------------------------------Suprimer WorldCup static void Delete(ref WorldCup[] pers, ref int nbPers, int numAChercher){ for(int i = 0; i < nbPers-1; i++){ if(pers[i].Numero == numAChercher) for(int j = i; j < nbPers-1; j++) pers[j] = pers[j+1]; } nbPers-=1; }
static void Inserer(ArrayList pers, string nom, char sexe, double taille, double poids, int numero) { nom = nom.ToUpper(); for (int i = nom.Length; i < 30; i++) nom += " "; WorldCup aAjouter = new WorldCup(nom, sexe, taille, poids, numero); int indice = pers.BinarySearch(aAjouter); if (indice < 0) indice = (-indice) - 1; pers.Insert(indice, aAjouter); }
//----------------------------------------------------------------RechercheDicho static int indDicho(int aChercher, WorldCup[] pers, int nbPers) { int mini = 0, maxi = nbPers - 1; while (mini <= maxi) { int milieu = (mini + maxi) / 2; if (aChercher < pers[milieu].Numero) maxi = milieu - 1; else if (aChercher > pers[milieu].Numero) mini = milieu + 1; else return milieu; } return -1; }
/* 0123456789012345678901234567890123456789012345678901234567890123456789 ROY CHANTAL F 1,75 57,9 2754 MOLAISON CLAUDE M 1,57 62,2 1848 ROBITAILLE CHANTALE F 1,79 72,3 2007 BEDARD MARC-ANDRE M 1,43 55,5 2636 MONAST STEPHANE M 1,65 61,7 1750 JALBERT LYNE F 1,63 52,6 2168 DUBE FRANCOISE F 1,68 67,5 4612 ROBITAILLE SUZANNE M 1,72 75,4 2325 LEMELIN SOPHIE F 1,88 57,8 7777 LABELLE LISE F 1,79 68,0 1512 CHOQUETTE HELENE F 1,71 60,8 2340 ROBITAILLE SUZANNE F 1,82 76,1 8007 MICHAUD NORMAND M 1,73 103,7 3428 RICHER AGATHE F 1,65 53,1 3563 BEGIN MARIE-LUCE F 1,62 49,0 4101 ROBITAILLE SUZANNE F 1,63 75,1 7654 COUTU PIERRE M 1,72 62,1 4008 TREMBLAY SUZANNE F 1,48 61,5 4371 BERGEVIN GUILLAUME M 1,84 86,4 2277 DUMITRU PIERRE M 1,82 99,4 3629 ROBITAILLE MICHEL M 1,78 85,1 6002 FILLION ERIC M 1,78 75,7 2630 DESMARAIS DENISE F 1,79 58,7 3215 TREMBLAY MARC M 1,79 64,9 3529 TREMBLAY SYLVAIN M 1,83 86,2 1538 ROBITAILLE SUZANNE F 1,68 60,2 4119 */ static void LireRemplir(string nomFichier, WorldCup[] pers, out int n) { Console.WriteLine("On lit le fichier texte " + nomFichier); n = 0; // localiser et ouvrir pour lire StreamReader aLire = File.OpenText(nomFichier); string ligneLue = null; // lire ligne par ligne while ((ligneLue = aLire.ReadLine()) != null) { string nomPrenom = ligneLue.Substring(0, 30); char sexe = ligneLue[30]; double taille = double.Parse(ligneLue.Substring(37, 4)); double poids = double.Parse(ligneLue.Substring(51, 4)); int numero = int.Parse(ligneLue.Substring(64, 4)); pers[n++] = new WorldCup(nomPrenom, sexe, taille, poids, numero); } aLire.Close(); Console.WriteLine("\nFin de la lecture du fichier texte " + nomFichier); }
//---------------------------------------------------------------------5.Ajouter static void Inserer(ArrayList paysInscrits, char groupe, int continent, string pays, string capitale, int superficie, int population) { pays = pays.ToUpper(); pays = pays.ToUpper(); for (int i = pays.Length; i < 34; i++) pays += " "; for (int i = capitale.Length; i < 9; i++) capitale += " "; WorldCup aAjouter = new WorldCup(groupe, continent, pays, capitale, superficie, population); int indice = paysInscrits.BinarySearch(aAjouter); if (indice < 0) indice = (-indice) - 1; paysInscrits.Insert(indice, aAjouter); Console.WriteLine("Nous avons ajouté le pays :\n {1}) {0}\n", aAjouter, indice); }
static void Main(string[] args) { const int MAX_PERS = 30; WorldCup[] pers = new WorldCup[MAX_PERS]; int nbPers; //1 LireRemplir("met_h16.txt", pers, out nbPers); Console.WriteLine("\nIl y a {0} WorldCups lues\n", nbPers); //2 Afficher(pers, nbPers, "après la lecture"); //3 Modif(pers, nbPers, 2325, 'F'); //4 Afficher(pers, nbPers, rechercheSequentielle(pers, nbPers, "Coutu Pierre")); Afficher(pers, nbPers, rechercheSequentielle(pers, nbPers, "Robitaille Suzanne")); Afficher(pers, nbPers, rechercheSequentielle(pers, nbPers, "Gagnon Daniel")); //5 QuickSort(pers, 0, nbPers - 1); //6 Afficher(pers, nbPers, "après le tri"); //7 RechercherDicho(pers, nbPers); //8 Delete(ref pers, ref nbPers, 4371); //9 Modif(pers, nbPers, 2636, 4); //10 AjouterPers(ref pers,ref nbPers, IndiceAjout(pers, 3430, nbPers), "Gosselin Laurent", 'M', 1.68, 72.1, 3430); Afficher(pers, nbPers, "après une supression une modification et un ajout"); }
//--------------------------------------------------------Recherche séquentielle static int rechercheSequentielle(WorldCup[] pers, int nbPers, string aChercher){ int i; for(i=0; i<nbPers; i++){ if(pers[i].NomPrenom.Trim() == aChercher.ToUpper()) { return i; } } return -1; }
//----------------------------------------------------------Ajout d'une WorldCup static int IndiceAjout(WorldCup[] pers, int numero, int nbPers){ bool indiceTrouve = false; int j = 0; for (int i = 0; i < nbPers; i++){ if (pers[i].Numero > numero && indiceTrouve == false){ j = i; indiceTrouve = true; } } return j; }
//Trier un tableau static void Trier(WorldCup[] pers){ for(int i = 0; i < pers.Length - 1; i++){ int indMin = i; for (int j = i + 1; j < pers.Length; j++) if (pers[j].nbCafe < pers[indMin].nbCafe) indMin = j; if (indMin != i) Permuter(ref pers[i], ref pers[indMin]); } }
/* Cette fonction est récursive car dans son corps on appelle cette même fonction (2 fois) */ static void QuickSort(WorldCup[] tab, int gauche, int droite) { int indPivot; if (droite > gauche) /* au moins 2 éléments */ { Partitionner(tab, gauche, droite, out indPivot); QuickSort(tab, gauche, indPivot - 1); QuickSort(tab, indPivot + 1, droite); } }
//affiche et compte le nombre de WorldCup correspondant au mois désiré static void CountMoisAffiche(WorldCup [] pers, string moisVoulu, string indiceMois){ int count = 0; Console.WriteLine("Les WorldCups qui sont née au mois de {0} : ", moisVoulu); for (int i = 0; i < pers.Length; i++){ if(pers[i].naissance.Substring(3, 2) == indiceMois){ count++; Afficher(pers, i); } } Console.WriteLine("Il y a {0} WorldCups qui sont née au mois de mai", count); }
// une simulation sera faite en classe : une des questions // pour l'intra. static void Partitionner(WorldCup[] tab, int debut, int fin, out int indPivot) { int g = debut, d = fin; int valPivot = tab[debut].Numero; do { while (g <= d && tab[g].Numero <= valPivot) g++; while (tab[d].Numero > valPivot) d--; if (g < d) Permuter(ref tab[g], ref tab[d]); } while (g <= d); Permuter(ref tab[debut], ref tab[d]); indPivot = d; }
static void Afficher(WorldCup[] pers, int nbPers, string mess) { Console.WriteLine("Contenu du tableau des WorldCups {0} :", mess); Console.WriteLine(" i nom et prenom sexe taille" + " poids numero"); for (int i = 0; i < nbPers; i++){ if (pers[i] != null) { Console.WriteLine("{0,3}) {1}", i, pers[i]); } else break; } Console.WriteLine(); }
static void RechercherDicho(WorldCup[] pers, int nbPers) { int aChercher; char reponse; do { aChercher = LireEntier("Tapez un numéro recherché "); int k = indDicho(aChercher, pers, nbPers); if (k != -1) // trouvé { Console.WriteLine("On trouve {0} à l'indice {1}\n", aChercher, k); Console.WriteLine("{0,3}) {1}", k, pers[k]); } else Console.WriteLine("On ne trouve pas le numéro : {0} ", aChercher); Console.Write("\nAvez-vous autre numéro recherché ? (o/n) "); reponse = Console.ReadLine().ToUpper()[0]; } while (reponse == 'O'); Console.WriteLine(); }
static void Modif(WorldCup[] pers, int nbPers, int numeroChercher, double tailleAjout){ for(int i = 0; i < nbPers; i++){ if (pers[i].Numero == numeroChercher) { pers[i].Taille += tailleAjout; } } }
//------------------------------------------------Recherche de valeur à modifier static void Modif(WorldCup[] pers, int nbPers, int numeroChercher, char sexeVoulu){ for(int i = 0; i < nbPers; i++){ if (pers[i].Numero == numeroChercher) { pers[i].Sexe = sexeVoulu; } } }
static void AjouterPers (ref WorldCup[] pers,ref int nbPers, int indVoulu, string nomPrenomVoulu, char sexeVoulu, double tailleVoulu, double poidsVoulu, int numeroVoulu){ nbPers +=1; for(int i = nbPers-1; i > indVoulu; i--){ pers[i] = pers[i-1]; } pers[indVoulu] = new WorldCup(nomPrenomVoulu.ToUpper() + " ", sexeVoulu, tailleVoulu, poidsVoulu, numeroVoulu); }
//Redéfinition de Afficher. afficher la WorldCup à l'indiceVoulu. static void Afficher (WorldCup[] pers , int nbPers, int indice){ if (indice != -1){ Console.WriteLine("Information de la WorldCup cherché :"); Console.WriteLine(" i nom et prenom sexe" + " taille poids numero"); Console.WriteLine("{0,3}) {1}", indice, pers[indice]); Console.WriteLine(); } else{ Console.WriteLine("La WorldCup recherché est introuvable."); Console.WriteLine(); } }