Skip to content

Commit

Permalink
Merge pull request #14 from BME-MIT-IET/map-and-waterflow-unittests
Browse files Browse the repository at this point in the history
Map and waterflow unittests
  • Loading branch information
Abri02 authored May 22, 2024
2 parents 3daf8c0 + 9dfcecb commit 99d3857
Show file tree
Hide file tree
Showing 9 changed files with 461 additions and 38 deletions.
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 @@ -28,7 +28,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 @@ -46,7 +46,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 @@ -82,7 +82,7 @@ public boolean accept(Character c) {

/**
* Lelepes egy csorol
*
*
* @param c a karakter
* @return Sikeres volt-e a lelepes
*/
Expand All @@ -104,7 +104,7 @@ public boolean remove(Character c) {
*/
@Override
public void step() {
if (holeOnPipe) {
if (holeOnPipe&&containingWater) {
containingWater = false;
leakedWaterAmount++;
}
Expand Down Expand Up @@ -144,7 +144,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 @@ -182,7 +182,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 @@ -203,7 +203,7 @@ public Pipe lift(int dir) {

/**
* Uj szomszed hozzacsatlakoztatasa a csohoz.
*
*
* @param n - a csatlakoztatni kivant szomszed
*/
public void addNeighbor(NonPipe n) {
Expand All @@ -214,7 +214,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 @@ -223,7 +223,7 @@ public void removeNeighbor(NonPipe n) {

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

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

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

/**
* Visszaadja a szomszedait
*
*
* @return List<NonPipe> - a szomszedok
*/
public List<NonPipe> getNeighbors() {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/Pump.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ public void step(){
containingWater=true;
}
}
//Release water form leaking pipe neighbors
for(Element neighbor : neighbors)
{
if(outputPipe!=neighbor)
neighbor.step();
}
for(Element neighbor : inputPipe.getNeighbors())
{
if(this!=neighbor)
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

0 comments on commit 99d3857

Please sign in to comment.