Coverage Summary for Class: CharacterDeckGenerator (it.polimi.ingsw.Model)
| Class | Method, % | Line, % |
|---|---|---|
| CharacterDeckGenerator | 50% (1/2) | 80% (4/5) |
| CharacterDeckGenerator$CharacterCardGenerator | ||
| Total | 50% (1/2) | 80% (4/5) |
1 package it.polimi.ingsw.Model; 2 3 import java.util.Arrays; 4 import java.util.Collections; 5 import java.util.List; 6 import java.util.Random; 7 8 /** 9 * Any {@link it.polimi.ingsw.Model.Enums.GameMode#ADVANCED} game must start with a selection of 3 different {@link CharacterCard}s 10 * and this class is the generator of such cards. <br> 11 */ 12 public class CharacterDeckGenerator { 13 /** 14 * Generate a random list of 3 Character cards (ensured to be non repeating in the list) 15 * 16 * @param context each generated {@link CharacterCard} needs a reference to the {@link Model} in order to work. 17 * @return a list of 3 randomly generated cards, in no specific order. 18 */ 19 public static List<CharacterCard> generateCardSet(Model context) { 20 List<CharacterCardGenerator> deck = Arrays.asList( 21 Card01::new, 22 Card02::new, 23 Card03::new, 24 Card04::new, 25 Card05::new, 26 Card06::new, 27 Card07::new, 28 Card08::new, 29 Card09::new, 30 Card10::new, 31 Card11::new, 32 Card12::new); 33 Collections.shuffle(deck, new Random(System.currentTimeMillis())); 34 return deck.subList(0, 3).stream() 35 .map(gen -> gen.build(context)).toList(); 36 } 37 38 /** 39 * in order to construct each card, the constructor must fall under an interface to be used in a lambda call. 40 * This interface is just for that. 41 */ 42 private interface CharacterCardGenerator { 43 /** 44 * the constructor of a {@link CharacterCard} has the same signature as this method 45 * 46 * @param ctx the reference to {@link Model} 47 * @return a {@link CharacterCard} 48 */ 49 CharacterCard build(Model ctx); 50 } 51 }