Skip to content

Commit

Permalink
task_1 solved
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrstasiak06 committed Apr 7, 2024
1 parent f46b05f commit 98a18e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions zadania/src/main/java/org/tasks/task1/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public int substract(int a, int b){

public int multiply(int a, int b) {
int result = 0;
for (int i = 1; i < a; i++) {
for (int i = 1; i <= a; i++) {
result += b;
}
return result;
Expand All @@ -32,7 +32,7 @@ public int divide(int a, int b){
public int power(int base, int exponent){
int result = 1;
for (int i = 0; i<exponent; i++){
result *= base^2;
result = result * base;
}
return result;
}
Expand All @@ -45,7 +45,7 @@ public int factorial(int n) {
return 1;
}
int result = 1;
for (int i = 1; i <= n; i++) {
for (int i = 1; i < n; i++) {
result *= i + 1;
}
return result;
Expand Down
16 changes: 14 additions & 2 deletions zadania/src/test/java/org/tasks/task1/CalculatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class CalculatorTest {

Expand All @@ -12,7 +13,7 @@ public void testadd(){
}

@Test
public void substract(){
public void testSubstract(){
Calculator calculator = new Calculator();
assertEquals(3, calculator.substract(5,2));
}
Expand All @@ -23,7 +24,18 @@ public void testMultiply() {
assertEquals(6, calculator.multiply(2, 3));
assertEquals(0, calculator.multiply(0, 10));
}
//

@Test
public void testFactorial() {
Calculator calculator = new Calculator();
assertEquals(24, calculator.factorial(4));
}

@Test
public void testDivide() {
Calculator calculator = new Calculator();
assertThrows(IllegalArgumentException.class,() -> calculator.divide(10,0));
}

@Test
public void testPower() {
Expand Down

0 comments on commit 98a18e7

Please sign in to comment.