commit 9c4ddc5654146609001fb31c82ee3249137dda25 Author: Joshua Perry <45966243+jpez-development@users.noreply.github.com> Date: Sun Jan 29 21:40:57 2023 +0000 first commit diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..00e1ec2 --- /dev/null +++ b/.classpath @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..494cbd4 --- /dev/null +++ b/.project @@ -0,0 +1,34 @@ + + + assignment_2 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + + + 1675021093357 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..98ffe38 --- /dev/null +++ b/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + org.r0r5chach + assignment_2 + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + + org.junit.jupiter + junit-jupiter-api + 5.4.2 + + + org.junit.jupiter + junit-jupiter-engine + 5.4.2 + test + + + + \ No newline at end of file diff --git a/src/main/java/org/r0r5chach/CompetitorList.java b/src/main/java/org/r0r5chach/CompetitorList.java new file mode 100644 index 0000000..0a7f2f7 --- /dev/null +++ b/src/main/java/org/r0r5chach/CompetitorList.java @@ -0,0 +1,196 @@ +package org.r0r5chach; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Scanner; + +public class CompetitorList { + private final ArrayList competitors; + + + + private String reportContents; + + + public CompetitorList(File list) throws IOException { + competitors = new ArrayList<>(); + readCompetitors(list); + reportContents = reportTemplate(); + } + + public String getReportContents() { + return reportContents; + } + + public ArrayList getCompetitors() { + return competitors; + } + + private void readCompetitors(File list) throws FileNotFoundException { + Scanner reader = new Scanner(list); + while (reader.hasNextLine()) { + String[] row = reader.nextLine().split("%"); + competitors.add(parseRow(row)); + } + reader.close(); + } + + private ValorantPlayer parseRow(String[] row) { + int playerNumber = Integer.parseInt(row[0]); + Name playerName = new Name(row[1]); + ValorantRank playerLevel = ValorantRank.valueOf(row[2]); + ValorantAgent favoriteAgent = ValorantAgent.valueOf(row[3]); + int[] scores = parseScores(row[4]); + return new ValorantPlayer(playerNumber, playerName, playerLevel, favoriteAgent, scores); + } + + private int[] parseScores(String row) { + String[] scores = row.split(","); + int[] parsedScores = new int[scores.length]; + for (int i = 0; i < scores.length; i++) { + parsedScores[i] = Integer.parseInt(scores[i]); + } + return parsedScores; + } + + private String generateTable() { + StringBuilder table = new StringBuilder("Competitor Level Agent Scores Overall"); + for (ValorantPlayer player: getCompetitors()) { + table.append("\n"); + for (String detail: player.getFullDetails().split("\n")) { + String[] detailParts = detail.split(": "); + if (detailParts[0].equals("Player Number")) { + table.append(detailParts[1]).append(" "); + } + else { + table.append(detailParts[1]).append(" "); + } + } + } + return table.toString(); + } + + private int[] generateLevelFreqs() { + int[] freqs = {0, 0, 0, 0}; + for (ValorantPlayer player: getCompetitors()) { + switch (player.getPlayerLevel()) { + case IRON -> freqs[0] += 1; + case BRONZE -> freqs[1] += 1; + case SILVER -> freqs[2] += 1; + case GOLD -> freqs[3] += 1; + } + } + return freqs; + } + + private int[] generateScoreFreqs() { + int[] freqs = {0, 0, 0, 0, 0, 0}; + for (ValorantPlayer player: getCompetitors()) { + for (int score: player.getScores()) { + switch (score) { + case 0 -> freqs[0] += 1; + case 1 -> freqs[1] += 1; + case 2 -> freqs[2] += 1; + case 3 -> freqs[3] += 1; + case 4 -> freqs[4] += 1; + case 5 -> freqs[5] += 1; + } + } + } + return freqs; + } + + private double generateAverageScore() { + double avg = 0; + int totalScores = 0; + for (ValorantPlayer player: getCompetitors()) { + for (int score: player.getScores()) { + totalScores += 1; + avg += score; + } + } + avg /= totalScores; + return avg; + } + + private double getHighScore() { + double hS = 0; + for (ValorantPlayer player: getCompetitors()) { + if (player.getOverallScore() > hS) { + hS = player.getOverallScore(); + } + } + + return hS; + } + + public File createReportFile() throws IOException { + boolean exists; + int count = 0; + Path path; + FileWriter report = null; + + do { + path = Path.of("src/main/resources/report"+count+ ".txt"); + exists = Files.exists(path); + + if(exists) { + count += 1; + } + else { + Files.createFile(path); + report = new FileWriter(String.valueOf(path)); + } + }while (exists); + + generateReportContents(); + report.append(reportContents); + report.close(); + reportContents = reportTemplate(); + return new File(path.toUri()); + } + + public static String createErrorLog(Exception e, String path) { + try { + FileWriter log = new FileWriter(path); + log.append(String.valueOf(e)); + log.close(); + return Files.readString(Path.of(path)); + } + catch (IOException ie) { + return "Error"; + } + + } + + private void replaceVar(String target, String replacement) { + reportContents = reportContents.replace(target, replacement); + } + + private String reportTemplate() throws IOException { + return Files.readString(Path.of("src/main/resources/report.template")); + + } + + private void generateReportContents() { + replaceVar("%TABLE%", generateTable()); + replaceVar( "%HIGH-SCORE%", String.valueOf(getHighScore())); + replaceVar( "%AVG-SCORE%", String.valueOf(generateAverageScore())); + + int[] freqs = generateLevelFreqs(); + for (int i = 0; i < freqs.length; i++) { + replaceVar( "%LEVEL"+i+"%", ValorantRank.values()[i].getRank()); + replaceVar( "%VALUE"+i+"%", String.valueOf(freqs[i])); + } + + freqs = generateScoreFreqs(); + for (int i = 0; i < freqs.length; i++) { + replaceVar( "%SCORE"+i+"%", String.valueOf(freqs[i])); + } + } +} diff --git a/src/main/java/org/r0r5chach/Main.java b/src/main/java/org/r0r5chach/Main.java new file mode 100644 index 0000000..8b28bb5 --- /dev/null +++ b/src/main/java/org/r0r5chach/Main.java @@ -0,0 +1,17 @@ +package org.r0r5chach; + + +import java.io.IOException; +import java.nio.file.Files; + +public class Main { + public static void main(String[] args) { + Manager manager = new Manager(); + try { + System.out.println(Files.readString(manager.getReport().toPath())); + } + catch (IOException e) { + System.out.println("reading error"); + } + } +} \ No newline at end of file diff --git a/src/main/java/org/r0r5chach/Manager.java b/src/main/java/org/r0r5chach/Manager.java new file mode 100644 index 0000000..d996a02 --- /dev/null +++ b/src/main/java/org/r0r5chach/Manager.java @@ -0,0 +1,40 @@ +package org.r0r5chach; +import java.io.File; + +import static org.r0r5chach.CompetitorList.createErrorLog; + +public class Manager { + + private CompetitorList competitors; + + + public Manager() { + init(); + } + + public CompetitorList getCompetitors() { + return competitors; + } + + + public File getReport() { + File report; + try { + report = competitors.createReportFile(); + } + catch (Exception e) { + report = new File(createErrorLog(e, "src/main/resource/log.txt")); + } + return report; + } + + private void init() { + File sourceFile = new File("src/main/resources/test.txt"); + try { + competitors = new CompetitorList(sourceFile); + } + catch (Exception e) { + createErrorLog(e, "src/main/resources/log.txt"); + } + } +} diff --git a/src/main/java/org/r0r5chach/Name.java b/src/main/java/org/r0r5chach/Name.java new file mode 100644 index 0000000..1629900 --- /dev/null +++ b/src/main/java/org/r0r5chach/Name.java @@ -0,0 +1,131 @@ +package org.r0r5chach; + +/** + * Class that defines a name and it's parts + * @author John.Kanyaru@northampton.ac.uk + */ +public class Name { + /** + * The first name of the stored name + */ + private String firstName; + /** + * The middle name of the stored name + */ + private String middleName; + /** + * The last name of the stored name + */ + private String lastName; + /** + * Construct a name that does not contain a middle name + * @param fName the first name of the name to be stored + * @param lName the last name of the name to be stored + */ + public Name(String fName, String lName) { + firstName = fName; + middleName = ""; + lastName = lName; + } + /** + * Construct a name that does have a middle name + * @param fName the first name of the name to be stored + * @param mName the middle name of the name to be stored + * @param lName the last name of the name to be stored + */ + public Name(String fName, String mName, String lName) { + firstName = fName; + middleName = mName; + lastName = lName; + } + /** + * Construct a name from a single string + * @param fullName the first, middle, and last names of the name to be stored separated by whitespace + */ + public Name (String fullName) { + int spacePos1 = fullName.indexOf(' '); + firstName = fullName.substring(0, spacePos1); + int spacePos2 = fullName.lastIndexOf(' '); + if (spacePos1 == spacePos2) + middleName = ""; + else + middleName = fullName.substring(spacePos1+1, spacePos2); + lastName = fullName.substring(spacePos2 + 1); + } + /** + * Get the first name of the stored name + * @return the first name of the stored name + */ + public String getFirstName() {return firstName; } + /** + * Get the middle name of the stored name + * @return the middle name of the stored name + */ + public String getMiddleName() { return middleName; } + /** + * Get the last name of the stored name + * @return the last name of the stored name + */ + public String getLastName() {return lastName; } + /** + * Set the stored name's first name to that of the parameter + * @param fn the new first name + */ + public void setFirstName(String fn) { + firstName = fn; + } + /** + * Set the stored name's middle name to that of the parameter + * @param mn the new middle name + */ + public void setMiddleName(String mn) { + middleName = mn; + } + /** + * Set the stored name's last name to that of the parameter + * @param ln the new last name + */ + public void setLastName(String ln) { + lastName = ln; + } + /** + * Get the first and last name of the stored name + * @return a formatted string containing both the first and last names + */ + public String getFirstAndLastName() { + return firstName + " " + lastName; + } + /** + * Get the last and first names of the stored name + * @return a formatted string contains both the first and last names in reverse order + */ + public String getLastCommaFirst() { + return lastName + ", "+ firstName; + } + /** + * Get the full stored name + * @return a string containing the first, middle, and last names + */ + public String getFullName() { + String result = firstName + " "; + if (!middleName.equals("")) { + result += middleName + " "; + } + result += lastName; + return result; + } + /** + * Get the initials of the stored name + * @return a string containing the initials + * @author r0r5chach + */ + public String getInitials() { + String result = firstName.substring(0,1); + if (!middleName.equals("")) { + result += middleName.substring(0,1); + } + result += lastName.substring(0,1); + return result; + } +} + diff --git a/src/main/java/org/r0r5chach/ValorantAgent.java b/src/main/java/org/r0r5chach/ValorantAgent.java new file mode 100644 index 0000000..031e69f --- /dev/null +++ b/src/main/java/org/r0r5chach/ValorantAgent.java @@ -0,0 +1,37 @@ +package org.r0r5chach; + +import java.util.Locale; + +/** + * All Characters a ValorantPlayer can play + * @author r0r5chach + */ +public enum ValorantAgent { + BRIMSTONE, + VIPER, + OMEN, + KILLJOY, + CYPHER, + SOVA, + SAGE, + PHOENIX, + JETT, + REYNA, + RAZE, + BREACH, + SKYE, + YORU, + ASTRA, + KAYO, + CHAMBER, + NEON, + FADE, + HARBOR; + /** + * Get the name of the character + * @return a formatted string containing the character name + */ + public String getAgent() { + return this.name().charAt(0) + this.name().substring(1).toLowerCase(Locale.ROOT); //Capitalizes the first letter and makes sure the other letters are lowercase + } +} diff --git a/src/main/java/org/r0r5chach/ValorantPlayer.java b/src/main/java/org/r0r5chach/ValorantPlayer.java new file mode 100644 index 0000000..5d5fb6a --- /dev/null +++ b/src/main/java/org/r0r5chach/ValorantPlayer.java @@ -0,0 +1,155 @@ +package org.r0r5chach; + +import java.text.DecimalFormat; +import java.util.Arrays; + +/** + * Class that defines the various attributes and methods associated with a Valorant Player + * @author r0r5chach + */ +public class ValorantPlayer { + /** + * The format to use when converting decimal numbers to strings + */ + private static final DecimalFormat df = new DecimalFormat("0.00"); + /** + * The number of the player in the competition + */ + private int playerNumber; + /** + * The name of the player in the competition + */ + private Name playerName; + /** + * The level the player plays at in the competition + * These are derived from the first 4 ranks of the normal game + */ + private ValorantRank playerLevel; + /** + * The character the player plays the most + */ + private ValorantAgent favouriteAgent; + /** + * The scores the player has received + */ + private int[] scores; + /** + * Constructs an object with attributes matching the parameters passed + * @param playerNumber the number of the player + * @param playerName the name of the player + * @param playerLevel the level of the player + * @param favouriteAgent the character the player plays most + */ + public ValorantPlayer(int playerNumber, Name playerName, ValorantRank playerLevel, ValorantAgent favouriteAgent, int[] scores) { + this.playerNumber = playerNumber; + this.playerName = playerName; + this.playerLevel = playerLevel; + this.favouriteAgent = favouriteAgent; + this.scores = scores; + } + /** + * Set the player's number to that of the parameter + * @param playerNumber the new number of the player + */ + public void setPlayerNumber(int playerNumber) { + this.playerNumber = playerNumber; + } + /** + * Set the player's name to that of the parameter + * @param playerName the new name of the player + */ + public void setPlayerName(Name playerName) { + this.playerName = playerName; + } + /** + * Set the player's level to that of the parameter + * @param playerLevel the new level of the player + */ + public void setPlayerLevel(ValorantRank playerLevel) { + this.playerLevel = playerLevel; + } + /** + * Set the player's most played character to that of the parameter + * @param favouriteAgent the new most played character of the player + */ + public void setFavouriteAgent(ValorantAgent favouriteAgent) { + this.favouriteAgent = favouriteAgent; + } + /** + * Set the player's scores + * @param scores the new scores for the player + */ + public void setScores(int[] scores) { + this.scores = scores; + } + /** + * Get the player's number + * @return the player's number + */ + public int getPlayerNumber() { + return this.playerNumber; + } + /** + * Get the player's name + * @return the player's name + */ + public Name getPlayerName() { + return this.playerName; + } + /** + * Get the player's level + * @return the player's level + */ + public ValorantRank getPlayerLevel() { + return this.playerLevel; + } + /** + * Get the player's most played character + * @return the player's most played character + */ + public ValorantAgent getFavouriteAgent() { + return this.favouriteAgent; + } + /** + * Get the player's scores + * @return an array containing the scores + */ + public int[] getScores() { + return this.scores; + } + /** + * Calculates and then returns the overall score of the player. + * The score is calculated by taking the natural log of each score and then dividing the sum by 1.93 + * @return an aggregate of the individual scores the player has achieved + */ + public double getOverallScore() { + double output = 0; + for (int score: getScores()) { + output += Math.log(score); //get the sum of the natural log of the scores + } + output /= 1.93; //divide the sum by 1.93 + if (output == Double.NEGATIVE_INFINITY) { + output = 0; + } + return Double.parseDouble(df.format(output)); //df.format() allows the scores to be formatted to 2 decimal places + } + /** + * Get all the attributes of the player + * @return all attributes of the player in a formatted string + */ + public String getFullDetails() { + return "Player Number: " + getPlayerNumber() + + "\nName: " + getPlayerName().getFullName() + + "\nPlayer Level: " + getPlayerLevel().getRank() + + "\nFavourite Agent: " + getFavouriteAgent().getAgent() + + "\nScores: " + Arrays.toString(getScores()).replace("[","").replace("]", "") + //replace() allows the array to not be surrounded by brackets + "\nOverall Score: " + getOverallScore(); + } + /** + * Get the important attributes of the player + * @return a formatted string containing the playerNumber, playerName, and overall score + */ + public String getShortDetails() { + return "CN " + getPlayerNumber() + " (" + getPlayerName().getInitials() + ") has overall score " + getOverallScore(); + } +} diff --git a/src/main/java/org/r0r5chach/ValorantRank.java b/src/main/java/org/r0r5chach/ValorantRank.java new file mode 100644 index 0000000..144ab28 --- /dev/null +++ b/src/main/java/org/r0r5chach/ValorantRank.java @@ -0,0 +1,33 @@ +package org.r0r5chach; + +import java.util.Locale; + +/** + * All levels a ValorantPlayer can be + * @author r0r5chach + */ +public enum ValorantRank { + /** + * First Level + */ + IRON, + /** + * Second Level + */ + BRONZE, + /** + * Third Level + */ + SILVER, + /** + * Four Level + */ + GOLD; + /** + * Get the name of a level + * @return a formatted string containing the level name + */ + public String getRank() { + return this.name().charAt(0) + this.name().substring(1).toLowerCase(Locale.ROOT); //Capitalises the first letter and makes sure the other letters are lowercase + } +} diff --git a/src/main/resources/Part 1_SA - Tagged.pdf b/src/main/resources/Part 1_SA - Tagged.pdf new file mode 100644 index 0000000..fe6535d Binary files /dev/null and b/src/main/resources/Part 1_SA - Tagged.pdf differ diff --git a/src/main/resources/Part 2_SA - Tagged.pdf b/src/main/resources/Part 2_SA - Tagged.pdf new file mode 100644 index 0000000..6a89af1 Binary files /dev/null and b/src/main/resources/Part 2_SA - Tagged.pdf differ diff --git a/src/main/resources/report.template b/src/main/resources/report.template new file mode 100644 index 0000000..48da06f --- /dev/null +++ b/src/main/resources/report.template @@ -0,0 +1,12 @@ +%TABLE% + + +Statistics +The Highest Overall Score: %HIGH-SCORE% +Average Score: %AVG-SCORE% +Level Distribution: +%LEVEL0% %LEVEL1% %LEVEL2% %LEVEL3% +%VALUE0% %VALUE1% %VALUE2% %VALUE3% +Score Distribution: +0 1 2 3 4 5 +%SCORE0% %SCORE1% %SCORE2% %SCORE3% %SCORE4% %SCORE5% \ No newline at end of file diff --git a/src/main/resources/report0.txt b/src/main/resources/report0.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/test.txt b/src/main/resources/test.txt new file mode 100644 index 0000000..9bb920b --- /dev/null +++ b/src/main/resources/test.txt @@ -0,0 +1,4 @@ +101%Caitlin Emily Head%BRONZE%BREACH%0,1,4,2,1,1 +102%Joshua Luke Perry%IRON%SOVA%5,5,5,5,5,5 +103%Bradley Gordon-Taylor%SILVER%VIPER%3,1,3,2,4,1 +104%Nathan Perry%GOLD%BRIMSTONE%0,0,0,0,0,0 \ No newline at end of file diff --git a/src/test/java/CompetitorListTest.java b/src/test/java/CompetitorListTest.java new file mode 100644 index 0000000..3ff91c6 --- /dev/null +++ b/src/test/java/CompetitorListTest.java @@ -0,0 +1,107 @@ +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; +import org.r0r5chach.CompetitorList; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public class CompetitorListTest { + + @Test + public void competitorListTest() { + try { + CompetitorList cL = new CompetitorList(new File("src/main/resources/test.txt")); + assertEquals(Files.readString(Path.of("src/main/resources/report.template")), cL.getReportContents()); + assertEquals(102,cL.getCompetitors().get(1).getPlayerNumber()); + } + catch (IOException e) { + System.out.println("File doesn't exist"); + } + + } + + @Test + public void competitorListTestCreateReportFile() { + try { + CompetitorList cL = new CompetitorList(new File("src/main/resources/test.txt")); + assertEquals(Files.readString(Path.of("src/test/java/reportTest.txt")), Files.readString(cL.createReportFile().toPath())); + } + catch (IOException e) { + System.out.println("File doesn't exist"); + } + } + + @Test + public void competitorListTestCreateErrorLog() { + assertEquals("java.io.IOException", CompetitorList.createErrorLog(new IOException(), "src/main/resources/log.txt")); + assertEquals("Error", CompetitorList.createErrorLog(new IOException(), "src/main/java")); + + } + + @Test + public void competitorListTestGenerateTable() { + //Already tested in competitorListTestCreateReportFile + } + + @Test + public void competitorListTestGetHighScore() { + //Already tested in competitorListTestCreateReportFile + } + + @Test + public void competitorListTestGenerateAverageScore() { + //Already tested in competitorListTestCreateReportFile + } + + @Test + public void competitorListTestGenerateLevelFreqs() { + //Already tested in competitorListTestCreateReportFile + } + + @Test + public void competitorListTestGenerateScoreFreqs() { + //Already tested in competitorListTestCreateReportFile + } + + @Test + public void competitorListTestReplaceVar() { + //Already tested in competitorListTestCreateReportFile + } + + @Test + public void competitorListTestReportTemplate() { + //Already tested in competitorListTestCreateReportFile + } + + @Test + public void competitorListTestGenerateReportContents() { + //Already tested in competitorListTestCreateReportFile + } + + @Test + public void competitorListTestParseScores() { + //Already tested in competitorListTest + } + + @Test + public void competitorListTestParseRow() { + //Already tested in competitorListTest + } + + @Test + public void competitorListTestReadCompetitors() { + //Already tested in competitorListTest + } + + @Test + public void competitorListTestGetReportContents() { + //Already tested in competitorListTest + } + + @Test + public void competitorListTestGetCompetitors() { + //Already tested in competitorListTest + } +} diff --git a/src/test/java/MainTest.java b/src/test/java/MainTest.java new file mode 100644 index 0000000..b8608df --- /dev/null +++ b/src/test/java/MainTest.java @@ -0,0 +1,27 @@ +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; +import org.r0r5chach.Main; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.nio.file.Files; +import java.nio.file.Path; + +public class MainTest { + @Test + public void mainTest() { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + ByteArrayOutputStream expected = new ByteArrayOutputStream(); + System.setOut(new PrintStream(expected)); + try { + System.out.println(Files.readString(Path.of("src/test/java/reportTest.txt"))); + } + catch (IOException e) { + System.out.println("File doesn't exist"); + } + System.setOut(new PrintStream(output)); + Main.main(new String[0]); + assertEquals(expected.toString(), output.toString()); + } +} diff --git a/src/test/java/ManagerTest.java b/src/test/java/ManagerTest.java new file mode 100644 index 0000000..00c10c4 --- /dev/null +++ b/src/test/java/ManagerTest.java @@ -0,0 +1,38 @@ +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; +import org.r0r5chach.Manager; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public class ManagerTest { + + @Test + public void managerTest() { + Manager m = new Manager(); + assertEquals("Joshua Luke Perry", m.getCompetitors().getCompetitors().get(1).getPlayerName().getFullName()); + } + + @Test + public void managerTestGetReport() { + try { + Manager m = new Manager(); + assertEquals(Files.readString(Path.of("src/test/java/reportTest.txt")), Files.readString(m.getReport().toPath())); + } + catch (IOException e) { + System.out.println("File does not exist"); + } + } + + @Test + public void managerTestGetCompetitors() { + //Already tested in managerTest() + } + + @Test + public void managerTestInit() { + //Already tested in managerTest() + } + +} diff --git a/src/test/java/NameTest.java b/src/test/java/NameTest.java new file mode 100644 index 0000000..9a77ea6 --- /dev/null +++ b/src/test/java/NameTest.java @@ -0,0 +1,101 @@ +import org.junit.jupiter.api.Test; +import org.r0r5chach.Name; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class NameTest { + + @Test + public void nameTestFNameLName() { + Name n = new Name("Joshua", "Perry"); + assertEquals("Joshua", n.getFirstName()); + assertEquals("", n.getMiddleName()); + assertEquals("Perry", n.getLastName()); + } + + @Test + public void nameTestFNameMNameLName() { + Name n = new Name("Joshua", "Luke", "Perry"); + assertEquals("Joshua", n.getFirstName()); + assertEquals("Luke", n.getMiddleName()); + assertEquals("Perry", n.getLastName()); + } + + @Test + public void nameTestFullName() { + Name n = new Name("Joshua Luke Perry"); + assertEquals("Joshua", n.getFirstName()); + assertEquals("Luke", n.getMiddleName()); + assertEquals("Perry", n.getLastName()); + + n = new Name("Joshua Perry"); + assertEquals("Joshua", n.getFirstName()); + assertEquals("", n.getMiddleName()); + assertEquals("Perry", n.getLastName()); + } + + @Test + public void nameTestSetFirstName() { + Name n = new Name("Joshua Luke Perry"); + + n.setFirstName("Bradley"); + assertEquals("Bradley", n.getFirstName()); + } + + @Test + public void nameTestSetLastName() { + Name n = new Name("Joshua Luke Perry"); + + n.setLastName("Gordon-Taylor"); + assertEquals("Gordon-Taylor", n.getLastName()); + } + + @Test + public void nameTestGetFirstAndLastName() { + Name n = new Name("Joshua Luke Perry"); + assertEquals("Joshua Perry", n.getFirstAndLastName()); + } + + @Test + public void nameTestGetLastCommaFirst() { + Name n = new Name("Joshua Luke Perry"); + assertEquals("Perry, Joshua", n.getLastCommaFirst()); + } + + @Test + public void nameTestGetFullName() { + Name n = new Name("Joshua Luke Perry"); + assertEquals("Joshua Luke Perry", n.getFullName()); + n.setMiddleName(""); + assertEquals("Joshua Perry", n.getFullName()); + } + + @Test + public void nameTestGetInitials() { + Name n = new Name("Joshua Luke Perry"); + assertEquals("JLP", n.getInitials()); + n.setMiddleName(""); + assertEquals("JP", n.getInitials()); + } + + + @Test + public void nameTestGetFirstName() { + //Already tested in nameTestFNameLName() + } + + @Test + public void nameTestGetMiddleName() { + //Already tested in nameTestFNameMNameLName() + } + + @Test + public void nameTestGetLastName() { + //Already tested in nameTestFullName() + } + + @Test + public void nameTestSetMiddleName() { + //Already tested in nameTestGetFullName() + } +} diff --git a/src/test/java/ValorantAgentTest.java b/src/test/java/ValorantAgentTest.java new file mode 100644 index 0000000..0be9057 --- /dev/null +++ b/src/test/java/ValorantAgentTest.java @@ -0,0 +1,11 @@ +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; +import org.r0r5chach.ValorantAgent; + +public class ValorantAgentTest { + @Test + public void valorantAgentTestGetAgent() { + ValorantAgent vA = ValorantAgent.HARBOR; + assertEquals("Harbor", vA.getAgent()); + } +} diff --git a/src/test/java/ValorantPlayerTest.java b/src/test/java/ValorantPlayerTest.java new file mode 100644 index 0000000..77b8c5c --- /dev/null +++ b/src/test/java/ValorantPlayerTest.java @@ -0,0 +1,113 @@ +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; +import org.r0r5chach.Name; +import org.r0r5chach.ValorantAgent; +import org.r0r5chach.ValorantPlayer; +import org.r0r5chach.ValorantRank; +public class ValorantPlayerTest { + @Test + public void valorantPlayerTest() { + int[] scores = {5,5,5,5,5,5}; + ValorantPlayer vP = new ValorantPlayer(2,new Name("Joshua Luke Perry"), ValorantRank.GOLD, ValorantAgent.FADE, scores); + assertEquals(2, vP.getPlayerNumber()); + assertEquals("Joshua Luke Perry", vP.getPlayerName().getFullName()); + assertEquals("Gold", vP.getPlayerLevel().getRank()); + assertEquals("Fade", vP.getFavouriteAgent().getAgent()); + assertEquals(5, vP.getOverallScore()); + } + + @Test + public void valorantPlayerTestSetPlayerNumber() { + int[] scores = {5,5,5,5,5,5}; + ValorantPlayer vP = new ValorantPlayer(2,new Name("Joshua Luke Perry"), ValorantRank.GOLD, ValorantAgent.FADE, scores); + + vP.setPlayerNumber(5); + assertEquals(5, vP.getPlayerNumber()); + } + + @Test + public void valorantPlayerTestSetPlayerName() { + int[] scores = {5,5,5,5,5,5}; + ValorantPlayer vP = new ValorantPlayer(2,new Name("Joshua Luke Perry"), ValorantRank.GOLD, ValorantAgent.FADE, scores); + + vP.setPlayerName(new Name("Bradley Gordon-Taylor")); + assertEquals("Bradley Gordon-Taylor", vP.getPlayerName().getFullName()); + } + + @Test + public void valorantPlayerTestSetPlayerLevel() { + int[] scores = {5,5,5,5,5,5}; + ValorantPlayer vP = new ValorantPlayer(2,new Name("Joshua Luke Perry"), ValorantRank.GOLD, ValorantAgent.FADE, scores); + + vP.setPlayerLevel(ValorantRank.BRONZE); + assertEquals("Bronze", vP.getPlayerLevel().getRank()); + } + + @Test + public void valorantPlayerTestSetFavouriteAgent() { + int[] scores = {5,5,5,5,5,5}; + ValorantPlayer vP = new ValorantPlayer(2,new Name("Joshua Luke Perry"), ValorantRank.GOLD, ValorantAgent.FADE, scores); + + vP.setFavouriteAgent(ValorantAgent.VIPER); + assertEquals("Viper", vP.getFavouriteAgent().getAgent()); + } + + @Test + public void valorantPlayerTestSetScores() { + int[] scores = {5,5,5,5,5,5}; + ValorantPlayer vP = new ValorantPlayer(2,new Name("Joshua Luke Perry"), ValorantRank.GOLD, ValorantAgent.FADE, scores); + + vP.setScores(new int[]{0, 0, 0, 0, 0, 0}); + assertEquals(0, vP.getOverallScore()); + } + + @Test + public void valorantPlayerTestGetOverallScore() { + int[] scores = {5,5,5,5,5,5}; + ValorantPlayer vP = new ValorantPlayer(2,new Name("Joshua Luke Perry"), ValorantRank.GOLD, ValorantAgent.FADE, scores); + assertEquals(5, vP.getOverallScore()); + } + + @Test + public void valorantPlayerTestGetFullDetails() { + int[] scores = {5,5,5,5,5,5}; + ValorantPlayer vP = new ValorantPlayer(2,new Name("Joshua Luke Perry"), ValorantRank.GOLD, ValorantAgent.FADE, scores); + + assertEquals(""" + Player Number: 2 + Name: Joshua Luke Perry + Player Level: Gold + Favourite Agent: Fade + Scores: 5, 5, 5, 5, 5, 5 + Overall Score: 5.0""", vP.getFullDetails()); + } + + @Test + public void valorantPlayerTestGetShortDetails() { + int[] scores = {5,5,5,5,5,5}; + ValorantPlayer vP = new ValorantPlayer(2,new Name("Joshua Luke Perry"), ValorantRank.GOLD, ValorantAgent.FADE, scores); + + assertEquals("CN 2 (JLP) has overall score 5.0", vP.getShortDetails()); + } + + + @Test + public void valorantPlayerTestGetPlayerNumber() { + //Already tested in valorantPlayerTest() + } + + @Test + public void valorantPlayerTestGetPlayerName() { + //Already tested in valorantPlayerTest() + } + + @Test + public void valorantPlayerTestGetPlayerLevel() { + //Already tested in valorantPlayerTest() + } + + @Test + public void valorantPlayerTestGetFavouriteAgent() { + //Already tested in valorantPlayerTest() + } +} diff --git a/src/test/java/ValorantRankTest.java b/src/test/java/ValorantRankTest.java new file mode 100644 index 0000000..bbc4b7c --- /dev/null +++ b/src/test/java/ValorantRankTest.java @@ -0,0 +1,12 @@ +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; +import org.r0r5chach.ValorantRank; + + +public class ValorantRankTest { + @Test + public void valorantRankTestGetRank() { + ValorantRank vR = ValorantRank.IRON; + assertEquals("Iron", vR.getRank()); + } +} diff --git a/src/test/java/reportTest.txt b/src/test/java/reportTest.txt new file mode 100644 index 0000000..f61e90a --- /dev/null +++ b/src/test/java/reportTest.txt @@ -0,0 +1,16 @@ +Competitor Level Agent Scores Overall +101 Caitlin Emily Head Bronze Breach 0, 1, 4, 2, 1, 1 0.0 +102 Joshua Luke Perry Iron Sova 5, 5, 5, 5, 5, 5 5.0 +103 Bradley Gordon-Taylor Silver Viper 3, 1, 3, 2, 4, 1 2.22 +104 Nathan Perry Gold Brimstone 0, 0, 0, 0, 0, 0 0.0 + + +Statistics +The Highest Overall Score: 5.0 +Average Score: 2.2083333333333335 +Level Distribution: +Iron Bronze Silver Gold +1 1 1 1 +Score Distribution: +0 1 2 3 4 5 +7 5 2 2 2 6 \ No newline at end of file