Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map and waterflow unittests #14

Merged
merged 6 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,33 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=BME-MIT-IET_iet-hf-2024-iet-arcok
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Install TightVnc for UI tests
run: sudo apt-get install tightvncserver
- name: Add permission to run vnc script
run: chmod +x ./execute-on-vnc.sh
- name: Build with Maven
run: ./execute-on-vnc.sh mvn -B package --file pom.xml
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./execute-on-vnc.sh mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=BME-MIT-IET_iet-hf-2024-iet-arcok
32 changes: 32 additions & 0 deletions execute-on-vnc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#/bin/bash
NEW_DISPLAY=42
DONE="no"

umask 0077
mkdir -p "$HOME/.vnc"
chmod go-rwx "$HOME/.vnc"
vncpasswd -f <<<"$password" >"$HOME/.vnc/passwd"

while [ "$DONE" == "no" ]
do
out=$(xdpyinfo -display :${NEW_DISPLAY} 2>&1)
if [[ "$out" == name* ]] || [[ "$out" == Invalid* ]]
then
# command succeeded; or failed with access error; display exists
(( NEW_DISPLAY+=1 ))
else
# display doesn't exist
DONE="yes"
fi
done

echo "Using first available display :${NEW_DISPLAY}"

OLD_DISPLAY=${DISPLAY}
vncserver ":${NEW_DISPLAY}" -localhost -geometry 1600x1200 -depth 16
export DISPLAY=:${NEW_DISPLAY}

"$@"

export DISPLAY=${OLD_DISPLAY}
vncserver -kill ":${NEW_DISPLAY}"
24 changes: 12 additions & 12 deletions src/main/java/Pipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Pipe extends Element implements SaboteurPointSource {

/**
* Beállítja a betöltés során a Pipe változóit.
*
*
* @param hole holeOnPipe
* @param leakedWater leakedWaterAmount
* @param _slimey _slimey
Expand All @@ -45,7 +45,7 @@ public class Pipe extends Element implements SaboteurPointSource {

/**
* Ot kell meghivni ha ra szeretnek lepni a csore.
*
*
* @param c - a karakterunk
* @return boolean - a ralepes sikeressege
*/
Expand Down Expand Up @@ -87,7 +87,7 @@ public boolean accept(Character c) {

/**
* Lelepes egy csorol
*
*
* @param c a karakter
* @return Sikeres volt-e a lelepes
*/
Expand All @@ -110,7 +110,7 @@ public boolean remove(Character c) {
*/
@Override
public void step() {
if (holeOnPipe) {
if (holeOnPipe&&containingWater) {
containingWater = false;
leakedWaterAmount++;
}
Expand Down Expand Up @@ -155,7 +155,7 @@ public void damage() {

/**
* Letrehoz egy uj csovet, majd koze es a meglevo cso koze lehelyezi a pumpat.
*
*
* @param holdingPump - a lehelyezni kivant pumpa
* @return Pipe - az ujonnan letrehozott cso
*/
Expand Down Expand Up @@ -192,7 +192,7 @@ public Pipe placePump(Pump holdingPump) {
/**
* Olyan cso felemelesenel hasznaljuk, amelyiknek az egyik fele nincs sehova
* bekotve.
*
*
* @param dir - nem hasznaljuk ebben a megvalositsban
* @return Pipe - a cso, amit felemelunk
*/
Expand All @@ -215,7 +215,7 @@ public Pipe lift(int dir) {

/**
* Uj szomszed hozzacsatlakoztatasa a csohoz.
*
*
* @param n - a csatlakoztatni kivant szomszed
*/
public void addNeighbor(NonPipe n) {
Expand All @@ -226,7 +226,7 @@ public void addNeighbor(NonPipe n) {

/**
* Ezen keresztul lehet rola szomszedot lecsatlakoztatni.
*
*
* @param n - a lecsatlakoztatni kivant szomszed
*/
public void removeNeighbor(NonPipe n) {
Expand All @@ -235,7 +235,7 @@ public void removeNeighbor(NonPipe n) {

/**
* Visszadja a kifolyott viz mennyiseget, majd nullara allitja
*
*
* @return int - a kifolyott viz mennyisege
*/
@Override
Expand All @@ -247,7 +247,7 @@ public int measureAndResetLeakedWaterAmount() {

/**
* Kiszivja az adott csobol a vizet
*
*
* @return boolean - volt-e benne viz
*/
public boolean waterExtraction() {
Expand All @@ -262,7 +262,7 @@ public boolean waterExtraction() {

/**
* Vizet probal a csobe tenni
*
*
* @return boolean - sikerult-e bele vizet tenni
*/
public boolean giveWater() {
Expand Down Expand Up @@ -292,7 +292,7 @@ public void slime() {

/**
* Visszaadja a szomszedait
*
*
* @return List<NonPipe> - a szomszedok
*/
public List<NonPipe> getNeighbors() {
Expand Down
98 changes: 98 additions & 0 deletions src/test/java/MapTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertFalse;

public class MapTest extends MapTestBase
{
@Test
@DisplayName("Map Initialization Test")
public void MapInitTest()
{
TestNeighbors();

TestPumpBreak();

TestHole();

TestSliminess();

TestStickiness();
}

private void TestNeighbors()
{
assertAll("Pipe Neighbors Test",
() -> assertTrue(w.getNeighbors().contains(pi1)),
() -> assertTrue(w.getNeighbors().contains(pi3)),

() -> assertTrue(pi1.getNeighbors().contains(w)),
() -> assertTrue(pi1.getNeighbors().contains(p1)),

() -> assertTrue(pi2.getNeighbors().contains(p1)),
() -> assertTrue(pi2.getNeighbors().contains(c)),

() -> assertTrue(pi3.getNeighbors().contains(w)),
() -> assertTrue(pi3.getNeighbors().contains(p2)),

() -> assertTrue(pi4.getNeighbors().contains(p2)),
() -> assertTrue(pi4.getNeighbors().contains(c)),

() -> assertTrue(c.getNeighbors().contains(pi2)),
() -> assertTrue(c.getNeighbors().contains(pi4))
);
}

private void TestStickiness()
{
assertEquals(0, pi1.getSticky());
assertEquals(0, pi2.getSticky());
assertEquals(0, pi3.getSticky());
assertEquals(0, pi4.getSticky());

pi3.stick();

assertEquals(0, pi1.getSticky());
assertEquals(0, pi2.getSticky());
assertEquals(0, pi4.getSticky());
assertNotEquals(0, pi3.getSticky());
}

private void TestHole()
{
//Only pi4 should be broken
assertFalse(pi1.getHoleOnPipe());
assertFalse(pi2.getHoleOnPipe());
assertFalse(pi3.getHoleOnPipe());
assertTrue(pi4.getHoleOnPipe());
}

private void TestSliminess()
{
assertEquals(0, pi1.getSlimey());
assertEquals(0, pi2.getSlimey());
assertEquals(0, pi3.getSlimey());
assertEquals(0, pi4.getSlimey());

pi2.slime();

assertEquals(0, pi1.getSlimey());
assertEquals(0, pi3.getSlimey());
assertEquals(0, pi4.getSlimey());
assertNotEquals(0, pi2.getSlimey());
}

private void TestPumpBreak()
{
//Pumps are Not broken at first
assertFalse(p1.getBroken());
assertFalse(p2.getBroken());

//If we break one it should be broken
p2.breakPump();

assertTrue(p2.getBroken());
assertFalse(p1.getBroken());
}
}
Loading
Loading