Skip to content

Commit

Permalink
Merge pull request #4 from Peter200204/errors
Browse files Browse the repository at this point in the history
Tests and code coverage added
  • Loading branch information
Peter200204 authored May 10, 2024
2 parents 9609372 + 85792d3 commit 424d274
Show file tree
Hide file tree
Showing 50 changed files with 4,228 additions and 62 deletions.
18 changes: 18 additions & 0 deletions Tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Test 1
Single, előtte a primary torpedoval egy loves vegrehajtasa (ekkor a masodikkal kell loni a masodik single hívaskor, tehat 2 single hivas utan 1-1
kell, hogy legyen a fire hivasok szama.

Test 2
3 single kilovese, ekkor 2szer kell a primaryt, egyszer a secondaryt hasznalni.

Test 3
Single utana All kilovese, utana 1 single, ekkor 2szer kell a primaryt, 2szer a secondaryt hasznalni.

Test 4
Single kilovese, sikertelene, arrangbe beallitva, hogy a loves ne sikeruljon egyik torpedostore-nal se.

Test 5
Single loves masodikkal, majd megegyszer a masodikkal, mivel az elso ures.

Test 6
Loves elsovel, majd megegyszer a elsovel, mivel az masodik ures.
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
5 changes: 5 additions & 0 deletions src/main/java/hu/bme/mit/spaceship/GT4500.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public GT4500() {
this.primaryTorpedoStore = new TorpedoStore(10);
this.secondaryTorpedoStore = new TorpedoStore(10);
}

public GT4500(TorpedoStore pTS, TorpedoStore sTS) {
this.primaryTorpedoStore =pTS;
this.secondaryTorpedoStore =sTS;
}

public boolean fireLaser(FiringMode firingMode) {
// TODO not implemented yet
Expand Down
111 changes: 103 additions & 8 deletions src/test/java/hu/bme/mit/spaceship/GT4500Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,133 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.*;

public class GT4500Test {

private GT4500 ship;
private TorpedoStore mockpTS;
private TorpedoStore mocksTS;

@BeforeEach
public void init(){
this.ship = new GT4500();
mockpTS=mock(TorpedoStore.class);
mocksTS=mock(TorpedoStore.class);
this.ship = new GT4500(mockpTS, mocksTS);
}

@Test
public void fireTorpedo_Single_Success(){
// Arrange

when(mockpTS.fire(1)).thenReturn(true);
// Act
boolean result = ship.fireTorpedo(FiringMode.SINGLE);
ship.fireTorpedo(FiringMode.SINGLE);

// Assert
assertEquals(true, result);
// Assert
verify(mockpTS,times(1)).fire(1);
verify(mocksTS,times(0)).fire(1);
}

@Test
public void fireTorpedo_All_Success(){
// Arrange

when(mocksTS.fire(1)).thenReturn(true);
// Act
boolean result = ship.fireTorpedo(FiringMode.ALL);
ship.fireTorpedo(FiringMode.ALL);

// Assert
assertEquals(true, result);
verify(mockpTS,times(1)).fire(1);
verify(mocksTS,times(1)).fire(1);
}

//Single, előtte a primary torpedoval
//egy loves vegrehajtasa (ekkor a masodikkal kell loni a masodik single hívaskor, tehat 2 single hivas utan 1-1
//kell, hogy legyen a fire hivasok szama.
@Test
public void fireBothTorpedo_Single_Success(){
// Arrange
when(mocksTS.fire(1)).thenReturn(true);
//Act
ship.fireTorpedo(FiringMode.SINGLE);
ship.fireTorpedo(FiringMode.SINGLE);
//Assert
verify(mockpTS,times(1)).fire(1);
verify(mocksTS,times(1)).fire(1);
}

//3 single kilovese, igy 2szer kell a primaryt, egyszer a secondaryt hasznalni.
@Test
public void fire_First_Second_First_Torpedo_Single_Success(){
// Arrange
when(mockpTS.fire(anyInt())).thenReturn(true);
when(mocksTS.fire(anyInt())).thenReturn(true);
//Act
ship.fireTorpedo(FiringMode.SINGLE);
ship.fireTorpedo(FiringMode.SINGLE);
ship.fireTorpedo(FiringMode.SINGLE);
//Assert
verify(mockpTS,times(2)).fire(anyInt());
verify(mocksTS,times(1)).fire(1);
}

//Single utana All kilovese, utana 1 single, ekkor 2szer kell a primaryt, 2szer a secondaryt hasznalni.
@Test
public void fire_All_Then_Single_Torpedo_Success(){
//Arrange
when(mockpTS.fire(anyInt())).thenReturn(true);
when(mocksTS.fire(anyInt())).thenReturn(true);
//Act
ship.fireTorpedo(FiringMode.SINGLE);
ship.fireTorpedo(FiringMode.ALL);
ship.fireTorpedo(FiringMode.SINGLE);
//Assert
verify(mockpTS,times(2)).fire(anyInt());
verify(mocksTS,times(2)).fire(anyInt());
}

//Single kilovese, sikertelene, arrangbe beallitva, hogy a loves ne sikeruljon egyik torpedostore-nal se.
@Test
public void fire_Single_Failed(){
//Arrange
when(mockpTS.fire(anyInt())).thenReturn(false);
when(mocksTS.fire(anyInt())).thenReturn(false);

//Assert
assertEquals(false, ship.fireTorpedo(FiringMode.SINGLE));

}

//Loves masodikkal, majd megegyszer a masodikkal, mivel az elso ures.
@Test
public void second_fired_Twice_In_a_Row(){
//Arrange
when(mockpTS.isEmpty()).thenReturn(true);
when(mocksTS.fire(anyInt())).thenReturn(true);
//Act
ship.fireTorpedo(FiringMode.SINGLE);
ship.fireTorpedo(FiringMode.SINGLE);
//Assert
verify(mockpTS,times(0)).fire(anyInt());
verify(mocksTS,times(2)).fire(anyInt());

}

//Loves masodikkal majd elsovel, majd megegyszer a elsovel, mivel az masodik ures.
@Test
public void first_fired_Twice_In_a_Row(){
//Arrange
when(mocksTS.isEmpty()).thenReturn(true);
when(mockpTS.fire(anyInt())).thenReturn(true);
//Act
ship.fireTorpedo(FiringMode.SINGLE);
ship.fireTorpedo(FiringMode.SINGLE);
//Assert
verify(mockpTS,times(2)).fire(anyInt());
verify(mocksTS,times(0)).fire(anyInt());

}

}
Binary file modified target/classes/hu/bme/mit/spaceship/GT4500.class
Binary file not shown.
Binary file added target/hu.bme.mit.spaceship-0.5.0-SNAPSHOT.jar
Binary file not shown.
Binary file added target/jacoco.exec
Binary file not shown.
3 changes: 3 additions & 0 deletions target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifactId=hu.bme.mit.spaceship
groupId=hu.bme.mit.spaceship
version=0.5.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
hu/bme/mit/spaceship/TorpedoStore.class
hu/bme/mit/spaceship/SpaceShip.class
hu/bme/mit/spaceship/FiringMode.class
hu/bme/mit/spaceship/GT4500$1.class
hu/bme/mit/spaceship/GT4500.class
hu\bme\mit\spaceship\GT4500$1.class
hu\bme\mit\spaceship\GT4500.class
hu\bme\mit\spaceship\FiringMode.class
hu\bme\mit\spaceship\TorpedoStore.class
hu\bme\mit\spaceship\SpaceShip.class
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/home/cloud/ivt-lab/src/main/java/hu/bme/mit/spaceship/SpaceShip.java
/home/cloud/ivt-lab/src/main/java/hu/bme/mit/spaceship/GT4500.java
/home/cloud/ivt-lab/src/main/java/hu/bme/mit/spaceship/FiringMode.java
/home/cloud/ivt-lab/src/main/java/hu/bme/mit/spaceship/TorpedoStore.java
C:\Users\peter\OneDrive\Desktop\BME\6. felev\Integr\ivt-lab\src\main\java\hu\bme\mit\spaceship\GT4500.java
C:\Users\peter\OneDrive\Desktop\BME\6. felev\Integr\ivt-lab\src\main\java\hu\bme\mit\spaceship\FiringMode.java
C:\Users\peter\OneDrive\Desktop\BME\6. felev\Integr\ivt-lab\src\main\java\hu\bme\mit\spaceship\SpaceShip.java
C:\Users\peter\OneDrive\Desktop\BME\6. felev\Integr\ivt-lab\src\main\java\hu\bme\mit\spaceship\TorpedoStore.java
Original file line number Diff line number Diff line change
@@ -1 +1 @@
hu/bme/mit/spaceship/GT4500Test.class
hu\bme\mit\spaceship\GT4500Test.class
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/home/cloud/ivt-lab/src/test/java/hu/bme/mit/spaceship/GT4500Test.java
C:\Users\peter\OneDrive\Desktop\BME\6. felev\Integr\ivt-lab\src\test\java\hu\bme\mit\spaceship\GT4500Test.java
1 change: 1 addition & 0 deletions target/site/jacoco/hu.bme.mit.spaceship/FiringMode.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>FiringMode</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">hu.bme.mit.spaceship</a> &gt; <a href="index.html" class="el_package">hu.bme.mit.spaceship</a> &gt; <span class="el_class">FiringMode</span></div><h1>FiringMode</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">0 of 24</td><td class="ctr2">100%</td><td class="bar">0 of 0</td><td class="ctr2">n/a</td><td class="ctr1">0</td><td class="ctr2">1</td><td class="ctr1">0</td><td class="ctr2">2</td><td class="ctr1">0</td><td class="ctr2">1</td></tr></tfoot><tbody><tr><td id="a0"><a href="FiringMode.java.html#L7" class="el_method">static {...}</a></td><td class="bar" id="b0"><img src="../jacoco-resources/greenbar.gif" width="120" height="10" title="24" alt="24"/></td><td class="ctr2" id="c0">100%</td><td class="bar" id="d0"/><td class="ctr2" id="e0">n/a</td><td class="ctr1" id="f0">0</td><td class="ctr2" id="g0">1</td><td class="ctr1" id="h0">0</td><td class="ctr2" id="i0">2</td><td class="ctr1" id="j0">0</td><td class="ctr2" id="k0">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html>
10 changes: 10 additions & 0 deletions target/site/jacoco/hu.bme.mit.spaceship/FiringMode.java.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>FiringMode.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">hu.bme.mit.spaceship</a> &gt; <a href="index.source.html" class="el_package">hu.bme.mit.spaceship</a> &gt; <span class="el_source">FiringMode.java</span></div><h1>FiringMode.java</h1><pre class="source lang-java linenums">package hu.bme.mit.spaceship;

/**
* Weapon firing mode enumeration
*
*/
<span class="fc" id="L7">public enum FiringMode {</span>
<span class="fc" id="L8"> SINGLE, ALL</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html>
1 change: 1 addition & 0 deletions target/site/jacoco/hu.bme.mit.spaceship/GT4500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>GT4500</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">hu.bme.mit.spaceship</a> &gt; <a href="index.html" class="el_package">hu.bme.mit.spaceship</a> &gt; <span class="el_class">GT4500</span></div><h1>GT4500</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">22 of 132</td><td class="ctr2">83%</td><td class="bar">6 of 21</td><td class="ctr2">71%</td><td class="ctr1">8</td><td class="ctr2">15</td><td class="ctr1">5</td><td class="ctr2">38</td><td class="ctr1">2</td><td class="ctr2">4</td></tr></tfoot><tbody><tr><td id="a2"><a href="GT4500.java.html#L11" class="el_method">GT4500()</a></td><td class="bar" id="b0"><img src="../jacoco-resources/redbar.gif" width="21" height="10" title="18" alt="18"/></td><td class="ctr2" id="c2">0%</td><td class="bar" id="d1"/><td class="ctr2" id="e1">n/a</td><td class="ctr1" id="f1">1</td><td class="ctr2" id="g1">1</td><td class="ctr1" id="h0">5</td><td class="ctr2" id="i1">5</td><td class="ctr1" id="j0">1</td><td class="ctr2" id="k0">1</td></tr><tr><td id="a1"><a href="GT4500.java.html#L44" class="el_method">fireTorpedo(FiringMode)</a></td><td class="bar" id="b1"><img src="../jacoco-resources/redbar.gif" width="2" height="10" title="2" alt="2"/><img src="../jacoco-resources/greenbar.gif" width="117" height="10" title="98" alt="98"/></td><td class="ctr2" id="c1">98%</td><td class="bar" id="d0"><img src="../jacoco-resources/redbar.gif" width="34" height="10" title="6" alt="6"/><img src="../jacoco-resources/greenbar.gif" width="85" height="10" title="15" alt="15"/></td><td class="ctr2" id="e0">71%</td><td class="ctr1" id="f0">6</td><td class="ctr2" id="g0">12</td><td class="ctr1" id="h2">0</td><td class="ctr2" id="i0">28</td><td class="ctr1" id="j2">0</td><td class="ctr2" id="k1">1</td></tr><tr><td id="a0"><a href="GT4500.java.html#L25" class="el_method">fireLaser(FiringMode)</a></td><td class="bar" id="b2"><img src="../jacoco-resources/redbar.gif" width="2" height="10" title="2" alt="2"/></td><td class="ctr2" id="c3">0%</td><td class="bar" id="d2"/><td class="ctr2" id="e2">n/a</td><td class="ctr1" id="f2">1</td><td class="ctr2" id="g2">1</td><td class="ctr1" id="h1">1</td><td class="ctr2" id="i3">1</td><td class="ctr1" id="j1">1</td><td class="ctr2" id="k2">1</td></tr><tr><td id="a3"><a href="GT4500.java.html#L11" class="el_method">GT4500(TorpedoStore, TorpedoStore)</a></td><td class="bar" id="b3"><img src="../jacoco-resources/greenbar.gif" width="14" height="10" title="12" alt="12"/></td><td class="ctr2" id="c0">100%</td><td class="bar" id="d3"/><td class="ctr2" id="e3">n/a</td><td class="ctr1" id="f3">0</td><td class="ctr2" id="g3">1</td><td class="ctr1" id="h3">0</td><td class="ctr2" id="i2">5</td><td class="ctr1" id="j3">0</td><td class="ctr2" id="k3">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html>
Loading

0 comments on commit 424d274

Please sign in to comment.