Coverage Summary for Class: Score (io.github.unisim)

Class Class, % Method, % Line, %
Score 100% (1/1) 20% (2/10) 23.8% (5/21)


 package io.github.unisim;
 
 import com.badlogic.gdx.utils.Json;
 import com.badlogic.gdx.utils.JsonValue;
 
 /**
  * Player score. Includes JSON serialisation/deserialisation and score
  * comparison for ranking
  */
 public class Score implements Comparable<Score>, Json.Serializable {
     private String playerName;
     private int score;
 
     /**
      * Default constructor for JSON deserialisation.
      */
     public Score() {
     }
 
     /**
      * Constructor: Initialises a score to a player name and sets the score.
      * 
      * @param playerName - Player Name - String
      * @param score      - Player initial score - Integer
      */
     public Score(String playerName, int score) {
         this.playerName = playerName;
         this.score = score;
     }
 
     /**
      * Updates player score
      * 
      * @param score - New score value - Integer
      */
     public void setScore(int score) {
         this.score = score;
     }
 
     /**
      * Adds the value given by parameter to the current score
      * 
      * @param score - The amount to add - Integer
      */
     public void addScore(int score) {
         this.score += score;
     }
 
     /**
      * Returns current player name
      * 
      * @return - Player Name - String
      */
     public String getPlayerName() {
         return playerName;
     }
 
     /**
      * Returns current player score
      * 
      * @return - Player Score - Integer
      */
     public int getScore() {
         return score;
     }
 
     /**
      * Updates the player name
      * 
      * @param playerName - Player Name - String
      */
     public void setPlayerName(String playerName) {
         this.playerName = playerName;
     }
 
     /**
      * Compares 2 score's together.
      * Sorting is in descending order of scores.
      * 
      * @param other - Another Score object to compare
      * @return - Returns the result of comparison (Lesser, equal or greater)
      */
     @Override
     public int compareTo(Score other) {
         return Integer.compare(other.score, this.score); // Descending order
     }
 
     /**
      * Serialises Score to JSON
      * 
      * @param json - JSON object used for serialisation
      */
     @Override
     public void write(Json json) {
         json.writeValue("playerName", playerName);
         json.writeValue("score", score);
     }
 
     /**
      * Deserialises Scire from JSON
      * 
      * @param json     - JSON object used for serialisation
      * @param jsonData - JSON value containing the data
      */
     @Override
     public void read(Json json, JsonValue jsonData) {
         playerName = jsonData.getString("playerName");
         score = jsonData.getInt("score");
     }
 }