diff --git a/UnitTest/.DS_Store b/UnitTest/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1ed35cb68642a6b083a1eed663a0f9fd62b974cb Binary files /dev/null and b/UnitTest/.DS_Store differ diff --git a/UnitTest/pom.xml b/UnitTest/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..b31d6b9eeee278d2dc9bcd7bfe5e0cfff3526e7b --- /dev/null +++ b/UnitTest/pom.xml @@ -0,0 +1,43 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>com.example</groupId> + <artifactId>MagicSquareGame</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <properties> + <maven.compiler.source>11</maven.compiler.source> + <maven.compiler.target>11</maven.compiler.target> + </properties> + + <dependencies> + <!-- JUnit 5 API and Jupiter Engine --> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + <version>5.9.2</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <version>5.9.2</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <!-- Maven Surefire Plugin to run tests --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>3.0.0-M7</version> + </plugin> + </plugins> + </build> +</project> diff --git a/UnitTest/src/.DS_Store b/UnitTest/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e5fb7450caf2ac632e9e027e4f565e6ab5354db6 Binary files /dev/null and b/UnitTest/src/.DS_Store differ diff --git a/UnitTest/src/main/.DS_Store b/UnitTest/src/main/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..77624ad75d34d842145eaacbefefcb771a678b1f Binary files /dev/null and b/UnitTest/src/main/.DS_Store differ diff --git a/UnitTest/src/main/java/.DS_Store b/UnitTest/src/main/java/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 Binary files /dev/null and b/UnitTest/src/main/java/.DS_Store differ diff --git a/UnitTest/src/main/java/MagicSquare.class b/UnitTest/src/main/java/MagicSquare.class new file mode 100644 index 0000000000000000000000000000000000000000..a51fa093b66515a834116017082e5113d7018ff7 Binary files /dev/null and b/UnitTest/src/main/java/MagicSquare.class differ diff --git a/UnitTest/src/main/java/MagicSquare.java b/UnitTest/src/main/java/MagicSquare.java new file mode 100644 index 0000000000000000000000000000000000000000..8764ee47c55a406dd55d27ff904ce0a8f26bf0ed --- /dev/null +++ b/UnitTest/src/main/java/MagicSquare.java @@ -0,0 +1,149 @@ +// Importing the Random class for shuffling the magic square +import java.util.Random; + +public class MagicSquare { + private int size; + // Using a 2-D array as advised + private int[][] square; + + // Class to store the square matrix (as advised) + public MagicSquare(int size) { + this.size = size; + this.square = new int[size][size]; + generateMagicSquare(); + } + + // Generating a magic square using the given algorithm + // Adjusting where necessary (e.g - 1-based indexing to 0-based) + private void generateMagicSquare() { + int x = 0, y = size / 2; + for (int i = 1; i <= size * size; i++) { + square[x][y] = i; + int newX = (x - 1 + size) % size; + int newY = (y - 1 + size) % size; + + if (square[newX][newY] == 0) { + x = newX; + y = newY; + } else { + x = (x + 1) % size; + } + } + } + + public void shuffleSquare() { + Random rand = new Random(); + for (int i = 0; i < size * size; i++) { // Repeat for n^2 (size^2) times + int row = rand.nextInt(size); // Choosing a random elt + int col = rand.nextInt(size); // Choosing a random elt + // Swapping w/ random neighbor + // U, D, L, R corresponds to 0,1,2,3 + int direction = rand.nextInt(4); // Swapping w/ random neighbor + // Shuffling the magic square simulates what the player does, just with randomized values + // This is why we call swapElement() in shuffleSquare() with true (swap happens during shuffling) + swapElement(row, col, direction, true); + } + } + + // Swaps elts in the magic square to shuffle them + // Does row/column shifts in the even that the swap moves the elt outside the square matrix (wrap around) + public boolean swapElement(int row, int col, int direction, boolean isShuffling) { + + if (direction == 0) { // Up move + if (row == 0) { // First row → shift column up + int firstVal = square[0][col]; + for (int i = 0; i < size - 1; i++) { + square[i][col] = square[i + 1][col]; + } + square[size - 1][col] = firstVal; + } else { // Just swap up with adjacent element + int temp = square[row][col]; + square[row][col] = square[row - 1][col]; + square[row - 1][col] = temp; + } + + } else if (direction == 1) { // Down move + if (row == size - 1) { // Last row → shift column down + int lastVal = square[size - 1][col]; + for (int i = size - 1; i > 0; i--) { + square[i][col] = square[i - 1][col]; + } + square[0][col] = lastVal; + } else { // Just swap down with adjacent element + int temp = square[row][col]; + square[row][col] = square[row + 1][col]; + square[row + 1][col] = temp; + } + + } else if (direction == 2) { // Left move + if (col == 0) { // First column → shift entire row left to wrap around + int firstVal = square[row][0]; + for (int j = 0; j < size - 1; j++) { + square[row][j] = square[row][j + 1]; + } + square[row][size - 1] = firstVal; + } else { // Just swap left with adjacent element + int temp = square[row][col]; + square[row][col] = square[row][col - 1]; + square[row][col - 1] = temp; + } + + } else if (direction == 3) { // Right move + if (col == size - 1) { // Last column → perform a row shift + int lastVal = square[row][size - 1]; + for (int j = size - 1; j > 0; j--) { + square[row][j] = square[row][j - 1]; + } + square[row][0] = lastVal; + } else { // Just swap right with adjacent element + int temp = square[row][col]; + square[row][col] = square[row][col + 1]; + square[row][col + 1] = temp; + } + + } else { + return false; // Invalid direction + } + + return true; // Successful swap +} + + public boolean isMagicSquare() { + int magicSum = size * (size * size + 1) / 2; + + for (int i = 0; i < size; i++) { + // Reset rowSum and colSum at the start of each iteration + int rowSum = 0, colSum = 0; + for (int j = 0; j < size; j++) { + + rowSum += square[i][j]; + // Switch i and j since Java uses row-major order + colSum += square[j][i]; + } + if (rowSum != magicSum || colSum != magicSum) return false; + } + + // Need a separate for loop to iterate over the diagonals + int diag1 = 0, diag2 = 0; + for (int i = 0; i < size; i++) { + diag1 += square[i][i]; + diag2 += square[i][size - 1 - i]; + } + // This will return true if and only if both diagonals match the magic sum + return diag1 == magicSum && diag2 == magicSum; + } + + public void display() { + // Iterate over each row + for (int[] row : square) { + // Iterate over each number in the current row (since row is an array, an iterable) + for (int num : row) { + // Print 3 spaces for the number including digits and padding + // This makes the grid look even + System.out.printf("%3d ", num); + } + // After printing a row, move to the next line + System.out.println(); + } + } +} \ No newline at end of file diff --git a/UnitTest/src/main/java/MagicSquareGame.class b/UnitTest/src/main/java/MagicSquareGame.class new file mode 100644 index 0000000000000000000000000000000000000000..b0ca09d2e0be3ff3366b52f388ddf162480b4947 Binary files /dev/null and b/UnitTest/src/main/java/MagicSquareGame.class differ diff --git a/UnitTest/src/main/java/MagicSquareGame.java b/UnitTest/src/main/java/MagicSquareGame.java new file mode 100644 index 0000000000000000000000000000000000000000..9478d95659b2652e05544359161ec20be01a5806 --- /dev/null +++ b/UnitTest/src/main/java/MagicSquareGame.java @@ -0,0 +1,287 @@ +// To play SFX, must first import Java sound lib +// Doing a wildcard import to avoid importing each class one-by-one +import javax.sound.sampled.*; + +// To check and open audio files and handle file errors +import java.io.File; +import java.io.IOException; + +// For input +import java.util.Scanner; + +public class MagicSquareGame { + // No need to recreated + private static final String PURPLE = "\u001B[35m"; + private static final String RESET = "\u001B[0m"; + + public static void printTitle() { + //String PURPLE = "\u001B[35m"; // ANSI escape code for purple + // String RESET = "\u001B[0m"; // Reset color + + // Store ASCII art as an array + String[] asciiArt = { // Store ASCII art as an array of lines + "█ █ █ █ ██ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ ██ █ █ █ █ █ █ █ █ █ █ █ █ ", + "█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █", + "█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █", + "█ ██ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ ", + "█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █", + "█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █", + "█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █" + }; + + + // Set the color of the text to purple + System.out.println(PURPLE); // Set text color to purple + + // Iterate over each line in the ASCII art array print it with a typing effect + for (String line : asciiArt) { + typewriterEffect(line); + } + + // Reset color after printing + System.out.println(RESET); + } + + // The purpose of this function is to make the game seem more dynamic + public static void typewriterEffect(String text) { + // Setting a fixed delay of 10ms to achieve typing effect + // (Storing in var to make code more readable) + int delay = 10; + + for (int i = 0; i < text.length(); i++) { + System.out.print(text.charAt(i)); + try { + // + Thread.sleep(delay); + // Highly unlikely that the current sleeping thread will be interrupted + // But the Thread class in Java requires error handling + } catch (InterruptedException e) { + // Good practice to invoke interrupt() so the thread doesn't lose the info that was interrupted + Thread.currentThread().interrupt(); + } + } + System.out.println(); + } + + public static void playSound(String soundFile) { + try { + File file = new File(soundFile); + if (!file.exists()) return; // Fails silently if file is missing + + // AudioInputStream represents an audio file that is being read as a stream of bytes + AudioInputStream audioStream = AudioSystem.getAudioInputStream(file); + + // Creating an audio player for playback + Clip clip = AudioSystem.getClip(); + + // Loafing audio into clip + clip.open(audioStream); + + // Playing audio + clip.start(); + + // Halt other threads until sound finishes playing + // Need to divide by 1000 since Thread.sleep takes milliseconds not microseconds (1000 microseconds fit into one millisecond) + Thread.sleep(clip.getMicrosecondLength() / 1000); + + } catch (Exception ignored) { + // Fault masking -- Silently fail + // Sound wasn't a requirement to begin with, so the player doesn't need to know that there's smth w/ sound file + } + } + + public static void clearScreen() { + // Don't need exception handling b/c clearing the screen wasn't a req in the first place + // And it's highly unlikely for the ANSI escape seq to fail (except w/ Windows CMD/ some IDEs like Eclipse) + System.out.print("\033[H\033[2J"); + + // Flushing the buffer to clear the screen immediately (ensure there are no glitches) + System.out.flush(); + } + + public static void main(String[] args) { + // Reading input from terminal + Scanner scanner = new Scanner(System.in); + + // Flag to control game loop + boolean playAgain = true; + + while (playAgain) { + clearScreen(); + printTitle(); + typewriterEffect("Welcome to the Magic Square Game!"); + typewriterEffect("Your goal is to reconstruct the magic square."); + + System.out.println("\n========== PART A: MAGIC SQUARE GENERATION =========="); + int size; + while (true) { + System.out.print("Enter an odd integer for the magic square size: "); + + // If the 's input is not an integer, display an error message and consume the invalid input + if (!scanner.hasNextInt()) { + System.out.println("Invalid input. Please enter a positive odd integer."); + scanner.next(); + + // Skip the rest of the loop, go back to the start of the loop + continue; + } + // Read integer input and check whether it's both pos&&odd, in which case you can exit the loop + size = scanner.nextInt(); + if (size % 2 == 1 && size > 0) break; + System.out.println("Invalid input. Please enter a positive odd integer."); + } + + // Instantiate a new MagicSquare object and display the magic square + // This is what lets us use the logic in MagicSquare.java + MagicSquare magicSquare = new MagicSquare(size); + System.out.println("\nGenerated Magic Square:"); + magicSquare.display(); + + + System.out.print("\nPress any key to continue to Part B..."); + + // First one consumes the leftover newline from input + scanner.nextLine(); + + // Second one waits for input before moving to Part B + scanner.nextLine(); + clearScreen(); + + System.out.println("\n========== PART B: MAGIC SQUARE GAME ==========\n"); + magicSquare.display(); + + System.out.println("\nShuffling the Magic Square...\n"); + try { Thread.sleep(300); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } + playSound("shuffle.wav"); + magicSquare.shuffleSquare(); + + System.out.println("\nShuffled Magic Square:\n"); + magicSquare.display(); + System.out.println("\nTo win, simply reconstruct the original magic square!"); + + + int moves = 0; + int moveLimit = 20; + + // Loop runs until player wins/ runs out of moves + while (!magicSquare.isMagicSquare() && moves < moveLimit) { + System.out.println("\nMoves Left: " + (moveLimit - moves)); + System.out.print("Enter move (row col direction [U/D/L/R] or X to exit):"); + + // Initializing variables as unset + boolean validInput = false; + int row = -1, col = -1, direction = -1; + + while (!validInput) { + + // Read the entire line and trim extra spaces + String inputLine = scanner.nextLine().trim(); // Read full line, remove extra spaces + + // Deal w/ player wanting to exit first + if (inputLine.equalsIgnoreCase("X")) { + System.out.println("\nThanks for playing! Goodbye!"); + return; + } + + // Split input into parts (using whitespace regex) + String[] parts = inputLine.split("\\s+"); + + // The user's input must consist of 3 parts (row, col, dir), otherwise invalid + if (parts.length != 3) { + System.out.println("Invalid input. Please enter row, column, and direction (or X to exit)."); + continue; + } + + // To validate row input, first check if it's even a number then ensure it's non-negative + if (!parts[0].matches("-?\\d+")) { + System.out.println("Invalid row. Must be a number."); + continue; + } + + row = Integer.parseInt(parts[0]) - 1; + if (row < 0 || row >= size) { + System.out.println("Invalid row. Must be between 1 and " + size); + continue; + } + + // Use same logic for column input validation + if (!parts[1].matches("-?\\d+")) { + System.out.println("Invalid column. Must be a number."); + continue; + } + + col = Integer.parseInt(parts[1]) - 1; + if (col < 0 || col >= size) { + System.out.println("Invalid column. Must be between 1 and " + size); + continue; + } + + // 🔹 Check if Direction is valid (U, D, L, R) + char dir; + if (parts[2].length() == 1) { + // use charAt(0) since toUpperCase() returns a string + dir = parts[2].toUpperCase().charAt(0); + } else { + System.out.println("Invalid direction. Use U, D, L, or R."); + continue; + } + + switch (dir) { + case 'U': direction = 0; break; + case 'D': direction = 1; break; + case 'L': direction = 2; break; + case 'R': direction = 3; break; + default: direction = -1; + } + + if (direction == -1) { + System.out.println("Invalid direction. Use U, D, L, or R."); + continue; + } + + // If we reach this point, then the input must be valid + validInput = true; + } + + // Important that we call swapElement with false (swap does NOT happen during shuffling) + if (magicSquare.swapElement(row, col, direction, false)) { + moves++; + System.out.println(); + magicSquare.display(); + } + } + + // Check whether the player + if (magicSquare.isMagicSquare()) { + + // Reporting the number of moves as required + System.out.println("\nYou solved the magic square in " + moves + " moves!"); + + playSound("victory.wav"); + } else { + System.out.println("\nGame Over! You ran out of moves."); + playSound("defeat.wav"); + } + + // Giving player option to replay and validating their response + String response; + while (true) { + System.out.print("\nWould you like to play again? (Y/N): "); + response = scanner.next().trim().toUpperCase(); + + if (response.equalsIgnoreCase("Y")){ + playAgain = true; + break; + } else if (response.equalsIgnoreCase("N")){ + playAgain = false; + break; + } else{ + System.out.println("Invalid input. Please enter either 'Y' for yes or 'N' for no."); + } + } + } + + System.out.println("\nThanks for playing! Goodbye!"); + scanner.close(); + } +} \ No newline at end of file diff --git a/UnitTest/src/main/java/defeat.wav b/UnitTest/src/main/java/defeat.wav new file mode 100644 index 0000000000000000000000000000000000000000..1e1a783bacad0947cccd8bb0e322cf09ed71bcd8 Binary files /dev/null and b/UnitTest/src/main/java/defeat.wav differ diff --git a/UnitTest/src/main/java/game.bat b/UnitTest/src/main/java/game.bat new file mode 100644 index 0000000000000000000000000000000000000000..691fc3b8a622a193aecbd65ad8a74d78f2980dc1 --- /dev/null +++ b/UnitTest/src/main/java/game.bat @@ -0,0 +1,3 @@ +@echo off +javac MagicSquare2.java MagicSquareGame2.java +java MagicSquareGame2 \ No newline at end of file diff --git a/UnitTest/src/main/java/game.sh b/UnitTest/src/main/java/game.sh new file mode 100755 index 0000000000000000000000000000000000000000..bfc99229a9194834b6548d393c48550f68ccea09 --- /dev/null +++ b/UnitTest/src/main/java/game.sh @@ -0,0 +1,3 @@ +#!/bin/bash +javac MagicSquare.java MagicSquareGame.java +java MagicSquareGame \ No newline at end of file diff --git a/UnitTest/src/main/java/shuffle.wav b/UnitTest/src/main/java/shuffle.wav new file mode 100644 index 0000000000000000000000000000000000000000..45a7019036a02856b971e9df1361662f4854e34a Binary files /dev/null and b/UnitTest/src/main/java/shuffle.wav differ diff --git a/UnitTest/src/main/java/victory.wav b/UnitTest/src/main/java/victory.wav new file mode 100644 index 0000000000000000000000000000000000000000..1e475e4a4dad4521a27b3123db951608454c7d14 Binary files /dev/null and b/UnitTest/src/main/java/victory.wav differ diff --git a/UnitTest/src/test/.DS_Store b/UnitTest/src/test/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..fae2dfe07e97cac3747680c46803e312489264ff Binary files /dev/null and b/UnitTest/src/test/.DS_Store differ diff --git a/UnitTest/src/test/java/.DS_Store b/UnitTest/src/test/java/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7f79747c7588a5cf46531eda3eef1bad6db8d6bd Binary files /dev/null and b/UnitTest/src/test/java/.DS_Store differ diff --git a/UnitTest/src/test/java/MagicSquareGameTest.java b/UnitTest/src/test/java/MagicSquareGameTest.java new file mode 100644 index 0000000000000000000000000000000000000000..67a4f0a045bc10befcb4efa1c7bf73681d8bda32 --- /dev/null +++ b/UnitTest/src/test/java/MagicSquareGameTest.java @@ -0,0 +1,30 @@ +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +class MagicSquareGameTest{ + + // Normal case: No error thrown if sound file exists + @Test + void PlaySoundNormal () { + assertDoesNotThrow(() -> { + MagicSquareGame.playSound("shuffling.wav"); + }); + } + + // Abnormal case: Even if sound file does not exist, fail silently + @Test + void PlaySoundAbnormal () { + assertDoesNotThrow(() -> { + MagicSquareGame.playSound("misc.wav"); + }); + } + + // Normal case: Screen is cleared with no issues (still need to check console output) + @Test + void ClearScreenNormal () { + assertDoesNotThrow (() -> { + MagicSquareGame.clearScreen(); + }); + } + +} \ No newline at end of file diff --git a/UnitTest/src/test/java/MagicSquareTest.java b/UnitTest/src/test/java/MagicSquareTest.java new file mode 100644 index 0000000000000000000000000000000000000000..19b5a3458d3b251f2f832c6547da7717567d665d --- /dev/null +++ b/UnitTest/src/test/java/MagicSquareTest.java @@ -0,0 +1,99 @@ +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +class MagicSquareTest{ + + // Normal case: 5x5 square should be generated with no issues + @Test + void GenerateMagicSquareNormal() { + MagicSquare magicSquare = new MagicSquare(5); + assertNotNull(magicSquare); + } + + // Abnormal case: -5x-5 square is not possible since dimensions must be non-negative + @Test + void GenerateMagicSquareAbnormal() { + assertThrows(NegativeArraySizeException.class, () -> { + new MagicSquare(-5); + }); + } + + // Boundary case: A 1x1 square should be generated with no isses + @Test + void GenerateMagicSquareBoundary() { + MagicSquare magicSquare = new MagicSquare(1); + assertNotNull(magicSquare); + } + + // Normal case: Swap is valid (within bounds, but no wrap around) + @Test + void SwapElementNormal() { + MagicSquare magicSquare = new MagicSquare(3); + assertTrue(magicSquare.swapElement(1, 1, 3, false)); + } + + // Abnormal case: Swap is invalid because the direction is invalid + @Test + void SwapElementAbnormal() { + MagicSquare magicSquare = new MagicSquare(3); + assertFalse(magicSquare.swapElement(2, 2, 5, false)); + } + + // Boundary case: Swap is valid (wrap around - up) + @Test + void SwapElementBoundaryUp() { + MagicSquare magicSquare = new MagicSquare(3); + assertTrue(magicSquare.swapElement(0, 1, 0, false)); + } + + // Boundary case: Swap is valid (wrap around - down) + @Test + void SwapElementBoundaryDown() { + MagicSquare magicSquare = new MagicSquare(3); + assertTrue(magicSquare.swapElement(2, 2, 1, false)); + } + + // Boundary case: Swap is valid (wrap around - left) + @Test + void SwapElementBoundaryLeft() { + MagicSquare magicSquare = new MagicSquare(3); + assertTrue(magicSquare.swapElement(1, 0, 2, false)); + } + + // Boundary case: Swap is valid (wrap around - right) + @Test + void SwapElementBoundaryRight() { + MagicSquare magicSquare = new MagicSquare(3); + assertTrue(magicSquare.swapElement(1, 2, 3, false)); + } + + // Normal case: A freshly generated magic square should indeed be magic + @Test + void IsMagicSquareNormal() { + MagicSquare magicSquare = new MagicSquare(3); + assertTrue(magicSquare.isMagicSquare()); + } + + // Abnormal case: A magic square w/ one element swapped out of place should no longer be magic + @Test + void IsMagicSquareAbnormal() { + MagicSquare magicSquare = new MagicSquare(3); + magicSquare.swapElement(1, 0, 3, false); + assertFalse(magicSquare.isMagicSquare()); + } + + // Boundary case: A 1x1 square is trivially magic + @Test + void IsMagicSquareBoundary() { + MagicSquare magicSquare = new MagicSquare(1); + assertTrue(magicSquare.isMagicSquare()); + } + + // Normal case: shuffling the magic square results in a square which is no longer magic + @Test + void ShuffleSquareNormal() { + MagicSquare magicSquare = new MagicSquare(3); + magicSquare.shuffleSquare(); + assertFalse(magicSquare.isMagicSquare()); + } +} \ No newline at end of file diff --git a/UnitTest/target/classes/MagicSquare.class b/UnitTest/target/classes/MagicSquare.class new file mode 100644 index 0000000000000000000000000000000000000000..84ff6a3086b200cfc731888878627a02ef14962b Binary files /dev/null and b/UnitTest/target/classes/MagicSquare.class differ diff --git a/UnitTest/target/classes/MagicSquareGame.class b/UnitTest/target/classes/MagicSquareGame.class new file mode 100644 index 0000000000000000000000000000000000000000..fb1c9b9349e59e0fa7c81735cf8d7a913e5e2ab1 Binary files /dev/null and b/UnitTest/target/classes/MagicSquareGame.class differ diff --git a/UnitTest/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/UnitTest/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..ef1fbc5702140447129cf7c879dd8c25cf450362 --- /dev/null +++ b/UnitTest/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,2 @@ +MagicSquareGame.class +MagicSquare.class diff --git a/UnitTest/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/UnitTest/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..305b3fe4b9d67cb1ec694508d9622f417844f1b1 --- /dev/null +++ b/UnitTest/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,2 @@ +/Users/ghalaalmasri/Desktop/UnitTest/src/main/java/MagicSquare.java +/Users/ghalaalmasri/Desktop/UnitTest/src/main/java/MagicSquareGame.java diff --git a/UnitTest/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/UnitTest/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..f4c4ad9598d55a23e5d5a8c1b4d8a2ea4b17acd5 --- /dev/null +++ b/UnitTest/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1,2 @@ +MagicSquareGameTest.class +MagicSquareTest.class diff --git a/UnitTest/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/UnitTest/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..725859e99977e4c74d59bc8337856921a1439f0e --- /dev/null +++ b/UnitTest/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1,2 @@ +/Users/ghalaalmasri/Desktop/UnitTest/src/test/java/MagicSquareGameTest.java +/Users/ghalaalmasri/Desktop/UnitTest/src/test/java/MagicSquareTest.java diff --git a/UnitTest/target/surefire-reports/MagicSquareGameTest.txt b/UnitTest/target/surefire-reports/MagicSquareGameTest.txt new file mode 100644 index 0000000000000000000000000000000000000000..d46c2248aa92a2641598411b80d6ff5cdd3b9a0e --- /dev/null +++ b/UnitTest/target/surefire-reports/MagicSquareGameTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: MagicSquareGameTest +------------------------------------------------------------------------------- +Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 s - in MagicSquareGameTest diff --git a/UnitTest/target/surefire-reports/MagicSquareTest.txt b/UnitTest/target/surefire-reports/MagicSquareTest.txt new file mode 100644 index 0000000000000000000000000000000000000000..3c670ad4129d1fd84e59da43bd246784286e69ff --- /dev/null +++ b/UnitTest/target/surefire-reports/MagicSquareTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: MagicSquareTest +------------------------------------------------------------------------------- +Tests run: 13, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.018 s - in MagicSquareTest diff --git a/UnitTest/target/surefire-reports/TEST-MagicSquareGameTest.xml b/UnitTest/target/surefire-reports/TEST-MagicSquareGameTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..6f88366dd4f478cc98b7e1e3df0854b730ea5ce7 --- /dev/null +++ b/UnitTest/target/surefire-reports/TEST-MagicSquareGameTest.xml @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="UTF-8"?> +<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd" version="3.0" name="MagicSquareGameTest" time="0.001" tests="3" errors="0" skipped="0" failures="0"> + <properties> + <property name="gopherProxySet" value="false"/> + <property name="awt.toolkit" value="sun.lwawt.macosx.LWCToolkit"/> + <property name="java.specification.version" value="11"/> + <property name="sun.cpu.isalist" value=""/> + <property name="sun.jnu.encoding" value="UTF-8"/> + <property name="java.class.path" value="/Users/ghalaalmasri/Desktop/UnitTest/target/test-classes:/Users/ghalaalmasri/Desktop/UnitTest/target/classes:/Users/ghalaalmasri/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.9.2/junit-jupiter-api-5.9.2.jar:/Users/ghalaalmasri/.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar:/Users/ghalaalmasri/.m2/repository/org/junit/platform/junit-platform-commons/1.9.2/junit-platform-commons-1.9.2.jar:/Users/ghalaalmasri/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/Users/ghalaalmasri/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.9.2/junit-jupiter-engine-5.9.2.jar:/Users/ghalaalmasri/.m2/repository/org/junit/platform/junit-platform-engine/1.9.2/junit-platform-engine-1.9.2.jar:"/> + <property name="java.vm.vendor" value="JetBrains s.r.o."/> + <property name="sun.arch.data.model" value="64"/> + <property name="java.vendor.url" value="https://openjdk.java.net/"/> + <property name="user.timezone" value=""/> + <property name="java.vm.specification.version" value="11"/> + <property name="os.name" value="Mac OS X"/> + <property name="sun.java.launcher" value="SUN_STANDARD"/> + <property name="user.country" value="US"/> + <property name="sun.boot.library.path" value="/opt/anaconda3/lib"/> + <property name="sun.java.command" value="/Users/ghalaalmasri/Desktop/UnitTest/target/surefire/surefirebooter-20250314225728466_3.jar /Users/ghalaalmasri/Desktop/UnitTest/target/surefire 2025-03-14T22-57-28_362-jvmRun1 surefire-20250314225728466_1tmp surefire_0-20250314225728466_2tmp"/> + <property name="jdk.debug" value="release"/> + <property name="surefire.test.class.path" value="/Users/ghalaalmasri/Desktop/UnitTest/target/test-classes:/Users/ghalaalmasri/Desktop/UnitTest/target/classes:/Users/ghalaalmasri/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.9.2/junit-jupiter-api-5.9.2.jar:/Users/ghalaalmasri/.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar:/Users/ghalaalmasri/.m2/repository/org/junit/platform/junit-platform-commons/1.9.2/junit-platform-commons-1.9.2.jar:/Users/ghalaalmasri/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/Users/ghalaalmasri/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.9.2/junit-jupiter-engine-5.9.2.jar:/Users/ghalaalmasri/.m2/repository/org/junit/platform/junit-platform-engine/1.9.2/junit-platform-engine-1.9.2.jar:"/> + <property name="sun.cpu.endian" value="little"/> + <property name="user.home" value="/Users/ghalaalmasri"/> + <property name="user.language" value="en"/> + <property name="java.specification.vendor" value="Oracle Corporation"/> + <property name="java.version.date" value="2021-10-19"/> + <property name="java.home" value="/opt/anaconda3"/> + <property name="file.separator" value="/"/> + <property name="basedir" value="/Users/ghalaalmasri/Desktop/UnitTest"/> + <property name="java.vm.compressedOopsMode" value="Zero based"/> + <property name="line.separator" value=" "/> + <property name="java.specification.name" value="Java Platform API Specification"/> + <property name="java.vm.specification.vendor" value="Oracle Corporation"/> + <property name="java.awt.graphicsenv" value="sun.awt.CGraphicsEnvironment"/> + <property name="surefire.real.class.path" value="/Users/ghalaalmasri/Desktop/UnitTest/target/surefire/surefirebooter-20250314225728466_3.jar"/> + <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/> + <property name="java.runtime.version" value="11.0.13+7-b1751.21"/> + <property name="user.name" value="ghalaalmasri"/> + <property name="path.separator" value=":"/> + <property name="os.version" value="15.1.1"/> + <property name="java.runtime.name" value="OpenJDK Runtime Environment"/> + <property name="file.encoding" value="UTF-8"/> + <property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/> + <property name="java.vendor.version" value="JBR-11.0.13.7-1751.21-jcef"/> + <property name="localRepository" value="/Users/ghalaalmasri/.m2/repository"/> + <property name="java.vendor.url.bug" value="https://bugreport.java.com/bugreport/"/> + <property name="java.io.tmpdir" value="/var/folders/ny/94znt2hs7tlgk2swz46c4ylh0000gn/T/"/> + <property name="java.version" value="11.0.13"/> + <property name="user.dir" value="/Users/ghalaalmasri/Desktop/UnitTest"/> + <property name="os.arch" value="aarch64"/> + <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/> + <property name="java.awt.printerjob" value="sun.lwawt.macosx.CPrinterJob"/> + <property name="sun.os.patch.level" value="unknown"/> + <property name="java.library.path" value="/Users/ghalaalmasri/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:."/> + <property name="java.vm.info" value="mixed mode"/> + <property name="java.vendor" value="JetBrains s.r.o."/> + <property name="java.vm.version" value="11.0.13+7-b1751.21"/> + <property name="sun.io.unicode.encoding" value="UnicodeBig"/> + <property name="java.class.version" value="55.0"/> + </properties> + <testcase name="ClearScreenNormal" classname="MagicSquareGameTest" time="0.001"> + <system-out><![CDATA[&#27;[H&#27;[2J]]></system-out> + </testcase> + <testcase name="PlaySoundAbnormal" classname="MagicSquareGameTest" time="0"/> + <testcase name="PlaySoundNormal" classname="MagicSquareGameTest" time="0"/> +</testsuite> \ No newline at end of file diff --git a/UnitTest/target/surefire-reports/TEST-MagicSquareTest.xml b/UnitTest/target/surefire-reports/TEST-MagicSquareTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..c8ae127c2022e083d93cd69fa1d274c1640c832b --- /dev/null +++ b/UnitTest/target/surefire-reports/TEST-MagicSquareTest.xml @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="UTF-8"?> +<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd" version="3.0" name="MagicSquareTest" time="0.018" tests="13" errors="0" skipped="0" failures="0"> + <properties> + <property name="gopherProxySet" value="false"/> + <property name="awt.toolkit" value="sun.lwawt.macosx.LWCToolkit"/> + <property name="java.specification.version" value="11"/> + <property name="sun.cpu.isalist" value=""/> + <property name="sun.jnu.encoding" value="UTF-8"/> + <property name="java.class.path" value="/Users/ghalaalmasri/Desktop/UnitTest/target/test-classes:/Users/ghalaalmasri/Desktop/UnitTest/target/classes:/Users/ghalaalmasri/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.9.2/junit-jupiter-api-5.9.2.jar:/Users/ghalaalmasri/.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar:/Users/ghalaalmasri/.m2/repository/org/junit/platform/junit-platform-commons/1.9.2/junit-platform-commons-1.9.2.jar:/Users/ghalaalmasri/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/Users/ghalaalmasri/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.9.2/junit-jupiter-engine-5.9.2.jar:/Users/ghalaalmasri/.m2/repository/org/junit/platform/junit-platform-engine/1.9.2/junit-platform-engine-1.9.2.jar:"/> + <property name="java.vm.vendor" value="JetBrains s.r.o."/> + <property name="sun.arch.data.model" value="64"/> + <property name="java.vendor.url" value="https://openjdk.java.net/"/> + <property name="user.timezone" value=""/> + <property name="java.vm.specification.version" value="11"/> + <property name="os.name" value="Mac OS X"/> + <property name="sun.java.launcher" value="SUN_STANDARD"/> + <property name="user.country" value="US"/> + <property name="sun.boot.library.path" value="/opt/anaconda3/lib"/> + <property name="sun.java.command" value="/Users/ghalaalmasri/Desktop/UnitTest/target/surefire/surefirebooter-20250314225728466_3.jar /Users/ghalaalmasri/Desktop/UnitTest/target/surefire 2025-03-14T22-57-28_362-jvmRun1 surefire-20250314225728466_1tmp surefire_0-20250314225728466_2tmp"/> + <property name="jdk.debug" value="release"/> + <property name="surefire.test.class.path" value="/Users/ghalaalmasri/Desktop/UnitTest/target/test-classes:/Users/ghalaalmasri/Desktop/UnitTest/target/classes:/Users/ghalaalmasri/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.9.2/junit-jupiter-api-5.9.2.jar:/Users/ghalaalmasri/.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar:/Users/ghalaalmasri/.m2/repository/org/junit/platform/junit-platform-commons/1.9.2/junit-platform-commons-1.9.2.jar:/Users/ghalaalmasri/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/Users/ghalaalmasri/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.9.2/junit-jupiter-engine-5.9.2.jar:/Users/ghalaalmasri/.m2/repository/org/junit/platform/junit-platform-engine/1.9.2/junit-platform-engine-1.9.2.jar:"/> + <property name="sun.cpu.endian" value="little"/> + <property name="user.home" value="/Users/ghalaalmasri"/> + <property name="user.language" value="en"/> + <property name="java.specification.vendor" value="Oracle Corporation"/> + <property name="java.version.date" value="2021-10-19"/> + <property name="java.home" value="/opt/anaconda3"/> + <property name="file.separator" value="/"/> + <property name="basedir" value="/Users/ghalaalmasri/Desktop/UnitTest"/> + <property name="java.vm.compressedOopsMode" value="Zero based"/> + <property name="line.separator" value=" "/> + <property name="java.specification.name" value="Java Platform API Specification"/> + <property name="java.vm.specification.vendor" value="Oracle Corporation"/> + <property name="java.awt.graphicsenv" value="sun.awt.CGraphicsEnvironment"/> + <property name="surefire.real.class.path" value="/Users/ghalaalmasri/Desktop/UnitTest/target/surefire/surefirebooter-20250314225728466_3.jar"/> + <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/> + <property name="java.runtime.version" value="11.0.13+7-b1751.21"/> + <property name="user.name" value="ghalaalmasri"/> + <property name="path.separator" value=":"/> + <property name="os.version" value="15.1.1"/> + <property name="java.runtime.name" value="OpenJDK Runtime Environment"/> + <property name="file.encoding" value="UTF-8"/> + <property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/> + <property name="java.vendor.version" value="JBR-11.0.13.7-1751.21-jcef"/> + <property name="localRepository" value="/Users/ghalaalmasri/.m2/repository"/> + <property name="java.vendor.url.bug" value="https://bugreport.java.com/bugreport/"/> + <property name="java.io.tmpdir" value="/var/folders/ny/94znt2hs7tlgk2swz46c4ylh0000gn/T/"/> + <property name="java.version" value="11.0.13"/> + <property name="user.dir" value="/Users/ghalaalmasri/Desktop/UnitTest"/> + <property name="os.arch" value="aarch64"/> + <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/> + <property name="java.awt.printerjob" value="sun.lwawt.macosx.CPrinterJob"/> + <property name="sun.os.patch.level" value="unknown"/> + <property name="java.library.path" value="/Users/ghalaalmasri/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:."/> + <property name="java.vm.info" value="mixed mode"/> + <property name="java.vendor" value="JetBrains s.r.o."/> + <property name="java.vm.version" value="11.0.13+7-b1751.21"/> + <property name="sun.io.unicode.encoding" value="UnicodeBig"/> + <property name="java.class.version" value="55.0"/> + </properties> + <testcase name="GenerateMagicSquareNormal" classname="MagicSquareTest" time="0.008"/> + <testcase name="SwapElementNormal" classname="MagicSquareTest" time="0.001"/> + <testcase name="SwapElementBoundaryDown" classname="MagicSquareTest" time="0"/> + <testcase name="SwapElementBoundaryLeft" classname="MagicSquareTest" time="0"/> + <testcase name="IsMagicSquareAbnormal" classname="MagicSquareTest" time="0"/> + <testcase name="IsMagicSquareBoundary" classname="MagicSquareTest" time="0"/> + <testcase name="GenerateMagicSquareAbnormal" classname="MagicSquareTest" time="0.001"/> + <testcase name="ShuffleSquareNormal" classname="MagicSquareTest" time="0"/> + <testcase name="SwapElementBoundaryRight" classname="MagicSquareTest" time="0"/> + <testcase name="SwapElementBoundaryUp" classname="MagicSquareTest" time="0"/> + <testcase name="GenerateMagicSquareBoundary" classname="MagicSquareTest" time="0"/> + <testcase name="IsMagicSquareNormal" classname="MagicSquareTest" time="0.001"/> + <testcase name="SwapElementAbnormal" classname="MagicSquareTest" time="0"/> +</testsuite> \ No newline at end of file diff --git a/UnitTest/target/test-classes/MagicSquareGameTest.class b/UnitTest/target/test-classes/MagicSquareGameTest.class new file mode 100644 index 0000000000000000000000000000000000000000..6aaaaf6707a2a05ed282cf2c6969bdc5927f1e01 Binary files /dev/null and b/UnitTest/target/test-classes/MagicSquareGameTest.class differ diff --git a/UnitTest/target/test-classes/MagicSquareTest.class b/UnitTest/target/test-classes/MagicSquareTest.class new file mode 100644 index 0000000000000000000000000000000000000000..ff8f9e02520b5f7ce46c58b35d93ee8c6f3825e5 Binary files /dev/null and b/UnitTest/target/test-classes/MagicSquareTest.class differ