Coverage Summary for Class: Slot (it.polimi.ingsw.gc14.Model)

Class Class, % Method, % Branch, % Line, %
Slot 100% (1/1) 90% (9/10) 53.3% (8/15) 82.2% (37/45)


 package it.polimi.ingsw.gc14.Model;
 import java.io.Serializable;
 
 /**
  * Represents a slot with a specific identifier and associated values
  * for upper cards, lower cards, food, and minimum number of players.
  * The slot configuration depends on the specified slot identifier.
  */
 public class Slot implements Serializable {
 
     /**
      * The identifier of this slot.
      */
     private final char slotId;
 
     /**
      * Returns the identifier of this slot.
      *
      * @return the identifier of this slot.
      */
     public char getSlotId() {
         return slotId;
     }
 
     /**
      * The number of upper cards associated with this slot.
      */
     private final int nUpper;
     /**
      * Returns the number of upper cards associated with this slot.
      *
      * @return the number of upper cards associated with this slot.
      */
     public int getNUpper(){
         return nUpper;
     }
 
     /**
      * The minimum number of players required for this slot.
      */
     private int nMinPlayer;
 
     /**
      * Returns the minimum number of players required for this slot.
      *
      * @return the minimum number of players required for this slot.
      */
     public int getNMinPlayer()
     {
         return nMinPlayer;
     }
 
     /**
      * The number of lower cards associated with this slot.
      */
     private final int nLower;
 
     /**
      * Returns the number of lower cards associated with this slot.
      *
      * @return the number of lower cards associated with this slot.
      */
     public int getNLower(){
         return nLower;
     }
 
     /**
      * The amount of Food associated with this slot.
      */
     private final int food;
 
     /**
      * Returns the amount of Food associated with this slot.
      *
      * @return the amount of Food associated with this slot.
      */
     public int getFood(){
         return food;
     }
 
 
     /**
      * Creates a slot with the specified identifier.
      * The slot values for Food, NLower, NUpper, and minimum number of players
      * are determined by the given slot identifier.
      *
      * @param slotId the identifier of the slot.
      * @throws IllegalArgumentException if the specified slot identifier is not valid.
      */
     public Slot(char slotId) throws IllegalArgumentException
     {
         this.slotId = slotId;
         this.nMinPlayer=0;
         switch(slotId)
         {
             case 'A':
                 this.food = 3;
                 this.nLower = 0;
                 this.nUpper = 0;
                 this.nMinPlayer=5;
                 break;
             case 'B':
                 this.food = 0;
                 this.nLower = 1;
                 this.nUpper = 0;
                 break;
             case 'C':
                 this.food = 0;
                 this.nLower = 0;
                 this.nUpper = 1;
                 break;
             case 'D':
                 this.food = 0;
                 this.nLower = 2;
                 this.nUpper = 0;
                 this.nMinPlayer = 3;
                 break;
             case 'E':
                 this.food = 0;
                 this.nLower = 1;
                 this.nUpper = 1;
                 break;
             case 'F':
                 this.food = 0;
                 this.nLower = 0;
                 this.nUpper = 2;
                 break;
             case 'G':
                 this.food = 0;
                 this.nLower = 1;
                 this.nUpper = 2;
                 this.nMinPlayer = 4;
                 break;
             default:
                 throw new IllegalArgumentException();
         }
     }
 
 
     /**
      * Returns the string representation of this slot.
      * The returned string includes the slot identifier, number of upper cards,
      * number of lower cards, food value, and minimum number of players.
      *
      * @return the string representation of this slot.
      */
     @Override
     public String toString() {
         return ("SlotID: "+this.getSlotId()+"\nNUpper: "+this.getNUpper()+"\nNLower: "+this.getNLower()+"\nFood: "+this.getFood()+"\n");
     }
 
 
     /**
      * Returns a compact string representation of this {@code Slot} for the TUI.
      * <p>Includes:
      * <ul>
      * <li>{@link #slotId}</li>
      * <li>{@link #nUpper} (shown as ▲ symbols)</li>
      * <li>{@link #nLower} (shown as ▼ symbols)</li>
      * <li>{@link #food} (if non-zero)</li>
      * </ul>
      * @return a compact TUI string representation of this {@code Slot}.
      * @see it.polimi.ingsw.gc14.Model.Game Game
      * @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
      */
     public String toStringTUI()
     {
         StringBuilder  s = new StringBuilder(" ");
         s.repeat("▲", Math.max(0, this.getNUpper()));
         s.repeat("▼", Math.max(0, this.getNLower()));
         if(getFood()!=0) s.append("+").append(getFood()).append(" \uD83C\uDF56");
         s.append(" ");
         return s.toString();
     }
 
 
     /**
      * Checks equality between this {@code Slot} and another object.
      * Two slots are equal if and only if they share the same {@code slotId}.
      *
      * @param obj the object to compare with.
      * @return {@code true} if {@code obj} is a {@code Slot} with the same identifier; {@code false} otherwise.
      */
     @Override
     public boolean equals(Object obj) {
         if (this == obj) return true;
         if (!(obj instanceof Slot)) return false;
         return slotId == ((Slot) obj).slotId;
     }
 
     /**
      * Returns the hash code for this {@code Slot}, derived from {@link #slotId}.
      *
      * @return the hash code of the slot identifier.
      */
     @Override
     public int hashCode() {
         return Character.hashCode(slotId);
     }
 
 }