Skip to content
Snippets Groups Projects
Commit 17261ca6 authored by Alexander Andriyuk's avatar Alexander Andriyuk
Browse files

lab4

parent e4c12e1f
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings" defaultProject="true" />
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -22,6 +22,14 @@
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-params -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>
......
package org.example.lab1;
package org.example;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
......
package org.example;
public class Main {
void main(String[] args) {
}
}
package org.example.lab3;
public class Foo {
private int num = 0;
public int returnNumber() {
return 5;
}
public int getNum() {
return num;
}
public void increment() {
num++;
}
public void exceptionThrown() throws Exception {
throw new Exception("Ocekavana vyjimka");
}
public boolean isTrue(boolean booleanValue){
if(booleanValue){
return true;
}
return false;
}
}
import org.example.lab1.Factorial;
import org.example.Factorial;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class FactorialTest {
@Test
public void factorialTest(){
public void Factorial0Returns1(){
Assertions.assertEquals(1, new Factorial().factorial(0));
}
@Test
public void Factorial2Returns2(){
Assertions.assertEquals(2, new Factorial().factorial(2));
}
@Test
public void failingTest(){
Assertions.assertEquals(3, new Factorial().factorial(5));
public void Factorial3Returns6(){
Assertions.assertEquals(6, new Factorial().factorial(3));
}
@Test
public void Factorial5Returns120(){
Assertions.assertEquals(120, new Factorial().factorial(5));
}
}
package lab3;
import org.example.lab3.Foo;
import org.junit.jupiter.api.*;
public class FooTest {
Foo foo;
@BeforeAll
public static void bfSetup() {
System.out.println("Bezim pred prvnim testem");
}
@BeforeEach
public void setup(){
foo = new Foo();
}
@Test
@DisplayName("Foo returnNumber vraci int 5")
// @Order(1)
public void returnNumberReturns5(){
int result = foo.returnNumber(); //ACT
Assertions.assertEquals(5, result); //ASSERT
}
@Test
public void isTrueReturnsTrue(){
boolean testBoolean = true;
boolean result = foo.isTrue(testBoolean);
Assertions.assertTrue(result);
}
@Test
public void isTrueReturnsFalse(){
boolean testBoolean = false;
boolean result = foo.isTrue(testBoolean);
Assertions.assertFalse(result);
}
@Test
public void getNumReturns0(){
int result = foo.getNum();
Assertions.assertEquals(0, result);
}
@Test
public void incrementReturns1(){
foo.increment();
int result = foo.getNum();
Assertions.assertEquals(1, result);
}
@Test
public void exceptionThrownThrowsException(){
Assertions.assertThrows(Exception.class, () -> {foo.exceptionThrown();});
}
@Test
public void exceptionThrownHaveTest(){
Exception e = Assertions.assertThrows(Exception.class, () -> {foo.exceptionThrown();});
Assertions.assertEquals("Ocekavana vyjimka", e.getMessage());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment