Skip to content

Commit

Permalink
11b - unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioBenov committed Dec 3, 2024
1 parent a7d087e commit 1210600
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 0 deletions.
29 changes: 29 additions & 0 deletions materials/2024-2025/11b/12-02-unit-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
3 changes: 3 additions & 0 deletions materials/2024-2025/11b/12-02-unit-tests/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions materials/2024-2025/11b/12-02-unit-tests/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions materials/2024-2025/11b/12-02-unit-tests/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions materials/2024-2025/11b/12-02-unit-tests/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions materials/2024-2025/11b/12-02-unit-tests/12-02-unit-tests.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
12 changes: 12 additions & 0 deletions materials/2024-2025/11b/12-02-unit-tests/src/ChessGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class ChessGame {
public Object[] board = {
new Object()
};

public Object getAt(String pos) {
if(pos.length() != 2)
throw new IllegalArgumentException("Invalid position");

return board[0];
}
}
47 changes: 47 additions & 0 deletions materials/2024-2025/11b/12-02-unit-tests/src/ChessGameTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

class ChessGameTest {

ChessGame cg;

@BeforeEach
void setUp() {
cg = new ChessGame();
}

@AfterEach
void tearDown() {
}

@Test
void getAtWithValidPosition() {
Object res = cg.getAt("A1");
assertEquals(cg.board[0], res,
"getAt should return the first object in board"
);

// assertEquals(new Figure("white", "K", "A1"), res);
}

@Test
void getAtWIthInvalidPosition() {
// Object res = cg.getAt("aaaaaa");
// assertEquals(cg.board[0], res,
// "getAt should throw an Exception"
// );
// try {
// cg.getAt("aaaaaa");
// } catch(Exception err) {
// assertEquals(...);
// }
assertThrows(
IllegalArgumentException.class,
() -> cg.getAt("A2"),
"getAt should throw an Exception"
);
}
}
6 changes: 6 additions & 0 deletions materials/2024-2025/11b/12-02-unit-tests/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class Main {
public static void main(String[] args) {

System.out.println("Hello world!");
}
}

0 comments on commit 1210600

Please sign in to comment.