diff --git a/Qwirkle/TestBase/TestGame.cs b/Qwirkle/TestBase/TestGame.cs index 8558e4a..d205135 100644 --- a/Qwirkle/TestBase/TestGame.cs +++ b/Qwirkle/TestBase/TestGame.cs @@ -241,8 +241,11 @@ public class TestGame game.StartGame(); game.SetNextPlayer(); - Assert.True(game.DrawTiles(game.GetPlayingPlayer())); + + /*test*/ + TileBag bag = new TileBag(0); + Assert.False(game.DrawTiles(game.GetPlayingPlayer())); return; } @@ -341,6 +344,39 @@ public class TestGame } + [Theory] + [InlineData(3, 1, 4, 1, 5, 1, 5)] + [InlineData(2, 2, 3, 2, 4, 2, 5)] + [InlineData(3, 1, 3, 2, 3, 3, 6)] + public void GetPlayerScore_ReturnsCorrectScore(int x1, int y1, int x2, int y2, int x3, int y3, int expectedScore) + { + var game = new Game(); + var player = new Player("TestPlayer"); + var board = new Board(8, 8); + + board.AddTileInCell(1, 1, new Tile(Shape.Club, Color.Red)); + board.AddTileInCell(2, 1, new Tile(Shape.Square, Color.Red)); + + var c1 = new Cell(x1, y1); + var c2 = new Cell(x2, y2); + var c3 = new Cell(x3, y3); + + c1.SetTile(new Tile(Shape.Club, Color.Red)); + c2.SetTile(new Tile(Shape.Square, Color.Red)); + c3.SetTile(new Tile(Shape.Star, Color.Red)); + + var cellsPlayed = new List + { + c1, + c2, + c3 + }.AsReadOnly(); + + var score = game.GetPlayerScore(player, cellsPlayed, board); + + Assert.Equal(expectedScore, score); + } + [Fact] public void Test_EndOfGame() { 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 diff --git a/Qwirkle/cm7/cm7.cs b/Qwirkle/cm7/cm7.cs deleted file mode 100644 index 21194e3..0000000 --- a/Qwirkle/cm7/cm7.cs +++ /dev/null @@ -1,28 +0,0 @@ -// DataBinding Baby !! - -// Applcation se basant sur le site wtatennis.com - -// class : Player, Place (Birth Places), Manager, IPersistanceManager -// enum : Hand (lfet-handed or right-handed) - -// Player.cs - -public string FirstName -{ - get => firstName; - set - { - if(value == firstName) return; - firstName = value; - OnPropertyChanged(); - } -} - -private string firstName; - -public event PropertyChangedEventHandler PropertyChanged; - -public void OnPropertyChanged([CallerMemberName] string propertyName = null) -{ - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); -} \ No newline at end of file diff --git a/Qwirkle/cm7/cm7.xaml b/Qwirkle/cm7/cm7.xaml deleted file mode 100644 index 3ef2d31..0000000 --- a/Qwirkle/cm7/cm7.xaml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - -