From cff74682a62fbd8f7617b2b1d3fc9067f304debf Mon Sep 17 00:00:00 2001 From: Whiton Nguyen Date: Wed, 1 May 2024 16:24:47 -0500 Subject: [PATCH] added more test cases --- src/main/java/com/cse3310/Game.java | 5 +++ src/test/java/com/cse3310/AppTest.java | 1 + src/test/java/com/cse3310/GameTest.java | 57 +++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 src/test/java/com/cse3310/GameTest.java diff --git a/src/main/java/com/cse3310/Game.java b/src/main/java/com/cse3310/Game.java index f2de005..4a2e715 100644 --- a/src/main/java/com/cse3310/Game.java +++ b/src/main/java/com/cse3310/Game.java @@ -15,6 +15,9 @@ public class Game public ArrayList ActiveButtons; public ArrayList CompletedButtons; public ArrayList AllCompletedButtons; + public double gridDensity; + public double gridTime; + public Game(ArrayList words, int GameId) { this.wordBank = new ArrayList(); @@ -204,6 +207,7 @@ else if(dY == -1) } System.out.println("Actual Density: " + (double)validWordsLetters / (length * width)); + this.gridDensity = (double)validWordsLetters / (length * width); System.out.println("Upward Diagonals: " + (diagUp/index)); System.out.println("Downward Diagonals: " + (diagDown/index)); System.out.println("Horizontals: " + (horizontals/index)); @@ -229,6 +233,7 @@ else if(dY == -1) } double endTime = System.currentTimeMillis(); System.out.println("Time to generate grid: " + (endTime - startTime) + " ms"); + this.gridTime = endTime - startTime; return grid; diff --git a/src/test/java/com/cse3310/AppTest.java b/src/test/java/com/cse3310/AppTest.java index 4b14916..a7e29f0 100644 --- a/src/test/java/com/cse3310/AppTest.java +++ b/src/test/java/com/cse3310/AppTest.java @@ -117,4 +117,5 @@ public void testGenerateGrid() GenerateGrid(B); } + } diff --git a/src/test/java/com/cse3310/GameTest.java b/src/test/java/com/cse3310/GameTest.java new file mode 100644 index 0000000..f869005 --- /dev/null +++ b/src/test/java/com/cse3310/GameTest.java @@ -0,0 +1,57 @@ +package com.cse3310; +//import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; + +import org.junit.Test; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +public class GameTest { + + @Test + public void densityIsWithinRange(){ + + String filename = "words.txt"; + ArrayList wordList = new ArrayList<>(); + + try (BufferedReader br = new BufferedReader(new FileReader(filename))) { + String line; + while ((line = br.readLine()) != null) { + wordList.add(line.trim()); + } + } catch (IOException e) { + System.err.println("Error reading file:" + e.getMessage()); + } + + Game g = new Game(wordList, 0); + + System.out.println("DENSITY IS " + g.gridDensity); + assertTrue(g.gridDensity >= 0.67); + } + + @Test + public void timeIsWithinRange(){ + + String filename = "words.txt"; + ArrayList wordList = new ArrayList<>(); + + try (BufferedReader br = new BufferedReader(new FileReader(filename))) { + String line; + while ((line = br.readLine()) != null) { + wordList.add(line.trim()); + } + } catch (IOException e) { + System.err.println("Error reading file:" + e.getMessage()); + } + + Game g = new Game(wordList, 0); + + System.out.println("TIME IS " + g.gridTime); + assertTrue(g.gridTime <= 1000); + } + +}