From 95039ecb306dd68beda5f48be6726cbedaed8796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Mouyon?= Date: Wed, 22 May 2024 10:29:17 +0200 Subject: [PATCH] Supprimer 'Qwirkle/cm4.cs' --- Qwirkle/cm4.cs | 162 ------------------------------------------------- 1 file changed, 162 deletions(-) delete mode 100644 Qwirkle/cm4.cs diff --git a/Qwirkle/cm4.cs b/Qwirkle/cm4.cs deleted file mode 100644 index 87a68a5..0000000 --- a/Qwirkle/cm4.cs +++ /dev/null @@ -1,162 +0,0 @@ -// Pas de console.WriteLine() dans les classes - -// Mot clé abstract dans la déclaration de la méthode et la déclaration de la classe pour faire une méthode virtuelle pure et une classe abstraite -// => ON utilise pas normalement - -using panier; - -namespace Animaux // Héritage -{ - public class Animal - { - public string Name {get; private set;} - - public Animal(string name) - { - this.Name = name; - } - - public virtual string Crie() - { - return "GRR"; - } - } - - public class Chien : Animal - { - public Chien(string name) : base(name) {} - - public override string Crie() - { - return $"{base.Crie()} + Wouf"; - } - } -} - - -namespace panier // Interfaces -{ - public class Article : IEqualTable
- { - public string Name { get; set; } - public float Price { get; set; } - - public Article(string name, float price) - { - Name = name; - Price = price; - } - - public override bool Equals(object? obj) - { - if(ReferenceEquals(obj, null)) return false; - if(ReferenceEquals(obj, this)) return true; - if(obj.GetType() != typeof(Article)) return false; - return Equals(obj as Article); - } - - public bool Equals(Article? other) - { - return other.Name.Equals(Name); - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - } - - public class PanierDAchat - { - - /* - 1) Créer une collection privée readonly - 2) Créer une ReadOnlyCollection public avec un set privé - 3) On l'initialise dans le constructeur - */ - - public ReadOnlyCollection
Articles { get; private set; }; - private List
Articles = new List
(); - - public ICalculPromo Promo {get; private set; } - - public float TotalPrice() - { - return Promo.GetTotal(this); - } - - public void AddArticle(Article article) - { - if(!Articles.Contains(article)) - { - Articles.Add(article); - } - } - } - - public interface ICalculPromo - { - float GetTotal(PanierDAchat panier); - } - - public class SansPromotion : ICalculPromo - { - public float GetTotal(PanierDAchat panier) - { - return panier.Articles.Sum(a => a.Price); - } - } - - public class SansTVA : ICalculPromo - { - public float GetTotal(PanierDAchat panier) - { - return panier.Articles.Sum(a => a.Price) * 0.8f; - } - } - - public class TroisPourLePrixDeDeux : ICalculPromo - { - public float GetTotal(PanierDAchat panier) - { - var sortedArticles = panier.Articles.OrderByDescending(a => a.Price); - int count = sortedArticles.count(); - sortedArticles.take((int)(count / 3) * 3).Sum(a => a.Price); - } - } -} - - -PanierDAchat p = new PanierDAchat(); - -p.Promo = new SansPromotion(); -p.Promo = new SansTVA(); - - - -namespace TestUnitairePanier -{ - public class UnitTest1 - { - [Fact] - public void Test_AddArticle() - { - PanierDAchat p = new PanierDAchat(); - bool result = p.AddArticle(new Article("Jp", 0.4)) - Assert.True(result); - } - } - - public class UnitTest2 - { - [Theory] - [InlineData(true, "Jp", 0.5)] - [InlineData(false, "Jp", -0.5)] - public void Test_AddArticle(bool expectedResult, string name, float price) - { - PanierDAchat p = new PanierDAchat(); - bool result = p.AddArticle(new Article("Jp", 0.4)) - Assert.True(result); - } - } -} \ No newline at end of file