diff --git a/materials/2024-2025/11b/12-02-unit-tests/.gitignore b/materials/2024-2025/11b/12-02-unit-tests/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/materials/2024-2025/11b/12-02-unit-tests/.gitignore @@ -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 \ No newline at end of file diff --git a/materials/2024-2025/11b/12-02-unit-tests/.idea/.gitignore b/materials/2024-2025/11b/12-02-unit-tests/.idea/.gitignore new file mode 100644 index 0000000..eaf91e2 --- /dev/null +++ b/materials/2024-2025/11b/12-02-unit-tests/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/materials/2024-2025/11b/12-02-unit-tests/.idea/misc.xml b/materials/2024-2025/11b/12-02-unit-tests/.idea/misc.xml new file mode 100644 index 0000000..396b409 --- /dev/null +++ b/materials/2024-2025/11b/12-02-unit-tests/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/materials/2024-2025/11b/12-02-unit-tests/.idea/modules.xml b/materials/2024-2025/11b/12-02-unit-tests/.idea/modules.xml new file mode 100644 index 0000000..01d832e --- /dev/null +++ b/materials/2024-2025/11b/12-02-unit-tests/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/materials/2024-2025/11b/12-02-unit-tests/.idea/vcs.xml b/materials/2024-2025/11b/12-02-unit-tests/.idea/vcs.xml new file mode 100644 index 0000000..15b5e29 --- /dev/null +++ b/materials/2024-2025/11b/12-02-unit-tests/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/materials/2024-2025/11b/12-02-unit-tests/12-02-unit-tests.iml b/materials/2024-2025/11b/12-02-unit-tests/12-02-unit-tests.iml new file mode 100644 index 0000000..4057de1 --- /dev/null +++ b/materials/2024-2025/11b/12-02-unit-tests/12-02-unit-tests.iml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/materials/2024-2025/11b/12-02-unit-tests/src/ChessGame.java b/materials/2024-2025/11b/12-02-unit-tests/src/ChessGame.java new file mode 100644 index 0000000..49021da --- /dev/null +++ b/materials/2024-2025/11b/12-02-unit-tests/src/ChessGame.java @@ -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]; + } +} diff --git a/materials/2024-2025/11b/12-02-unit-tests/src/ChessGameTest.java b/materials/2024-2025/11b/12-02-unit-tests/src/ChessGameTest.java new file mode 100644 index 0000000..86cfd12 --- /dev/null +++ b/materials/2024-2025/11b/12-02-unit-tests/src/ChessGameTest.java @@ -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" + ); + } +} \ No newline at end of file diff --git a/materials/2024-2025/11b/12-02-unit-tests/src/Main.java b/materials/2024-2025/11b/12-02-unit-tests/src/Main.java new file mode 100644 index 0000000..f1f2792 --- /dev/null +++ b/materials/2024-2025/11b/12-02-unit-tests/src/Main.java @@ -0,0 +1,6 @@ +public class Main { + public static void main(String[] args) { + + System.out.println("Hello world!"); + } +} \ No newline at end of file