Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,27 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies><!-- https://mvnrepository.com/artifact/org.testng/testng -->
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.16.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>


</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import homeWork_19.filtrowanieIPrzetwarzanie.java.Book;
import homeWork_19.filtrowanieIPrzetwarzanie.java.FilteringMachine;
import org.testng.annotations.Test;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.*;

public class FilteringMachineTest {

Expand All @@ -33,9 +31,9 @@ public void shouldFilterOutNotEvenNumbers() {
List<Integer> filteredList = machine.filterOutNotEvenNumbers(numberList);

// then
assertThat(filteredList.size(), is(2));
assertThat(filteredList, hasItem(12));
assertThat(filteredList, hasItem(124));
assertThat(filteredList.size()).isEqualTo(2);
assertThat(filteredList).contains(12);
assertThat(filteredList.contains(124));
}

@Test
Expand All @@ -56,11 +54,11 @@ public void shouldFilterOutNumberLowerThan20() {
List<Integer> filteredList = machine.filterOutLowerNumbersThan20(numberList);

// then
assertThat(filteredList.size(), is(4));
assertThat(filteredList, hasItem(123));
assertThat(filteredList, hasItem(124));
assertThat(filteredList, hasItem(21));
assertThat(filteredList, hasItem(71));
assertThat(filteredList.size()).isEqualTo(24);
assertThat(filteredList.contains(123));
assertThat(filteredList.contains(124));
assertThat(filteredList.contains(21));
assertThat(filteredList).contains(27);
}

@Test
Expand All @@ -77,12 +75,12 @@ public void shouldConvertTitlesToBooks() {
List<Book> books = machine.convertToBooks(titles);

// then
assertThat(books.size(), is(5));
assertThat(books, hasItem(new Book("Gra o tron")));
assertThat(books, hasItem(new Book("Dzieci z Bullerbyn")));
assertThat(books, hasItem(new Book("Robinson Cruzoe")));
assertThat(books, hasItem(new Book("Cyfrowa twierdza")));
assertThat(books, hasItem(new Book("Gra o życie")));
assertThat(books.size()).isEqualTo(4);
assertThat(books.contains(new Book("Gra o tron")));
assertThat(books.contains(new Book("Dzieci z Bullerbyn")));
assertThat(books.contains(new Book("Robinson Cruzoe")));
assertThat(books.contains(new Book("Cyfrowa twierdza")));
assertThat(books.contains(new Book("Gra o życie")));
}

@Test
Expand All @@ -99,9 +97,9 @@ public void shouldConvertTitlesToBooksAndFilterOutStartingWithGra() {
List<Book> books = machine.convertToBooksAndReturnOnlyStartingWithGra(titles);

// then
assertThat(books.size(), is(2));
assertThat(books, hasItem(new Book("Gra o tron")));
assertThat(books, hasItem(new Book("Gra o życie")));
assertThat(books.size()).isEqualTo(2);
assertThat(books.contains(new Book("Gra o tron")));
assertThat(books.contains(new Book("Gra o życie")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
import homeWork_19.filtrowanieIPrzetwarzanie.java.FilteringMachineTwo;
import homeWork_19.filtrowanieIPrzetwarzanie.java.Person;
import homeWork_19.filtrowanieIPrzetwarzanie.java.User;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;


public class FilteringMachineTwoTest {

private FilteringMachineTwo machine = new FilteringMachineTwo();
private List<Person> people;

@BeforeTest
@Before
public void init() {
people = new ArrayList<>();
people.add(new Person("Tomek", 2));
Expand All @@ -34,9 +33,9 @@ public void shouldReturnKidNames() {
List<String> kids = machine.findKidNames(people);

// then
assertThat(kids.size(), is(2));
assertThat(kids, hasItem("Tomek"));
assertThat(kids, hasItem("Sebastian"));
Assertions.assertThat(kids.size()).isEqualTo(2);
Assertions.assertThat(kids.contains("Tomek"));
Assertions.assertThat(kids.contains("Sebastian"));
}

@Test
Expand All @@ -45,12 +44,12 @@ public void shouldConvertPeopleToUser() {
List<User> users = machine.convertPeopleToUsers(people);

// then
assertThat(users.size(), is(5));
assertThat(users, hasItem(new User("Tomek", 2, "Tomek_2")));
assertThat(users, hasItem(new User("Ania", 18, "Ania_18")));
assertThat(users, hasItem(new User("Konrad", 44, "Konrad_44")));
assertThat(users, hasItem(new User("Janusz", 52, "Janusz_52")));
assertThat(users, hasItem(new User("Sebastian", 16, "Sebastian_16")));
Assertions.assertThat(users.size()).isEqualTo(5);
Assertions.assertThat(users.contains(new User("Tomek", 2, "Tomek_2")));
Assertions.assertThat(users.contains(new User("Ania", 18, "Ania_18")));
Assertions.assertThat(users.contains(new User("Konrad", 44, "Konrad_44")));
Assertions.assertThat(users.contains(new User("Janusz", 52, "Janusz_52")));
Assertions.assertThat(users.contains(new User("Sebastian", 16, "Sebastian_16")));
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package homeWork_19.liczbyZeStrumieni;



import org.testng.annotations.Test;
import org.junit.Test;

import java.util.stream.Stream;

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/homeWork_20/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package homeWork_20;

import org.assertj.core.api.Assertions;

import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Calculator {

public static int sumOfNaturalNumbers(int limit) {
return IntStream.range(1,limit)
.filter(number -> number % 3 == 0 || number % 5 == 0)
.sum();
}

public static int fibonacciSequence(int limit) {
return Stream.iterate(new int[]{1, 1}, n -> new int[]{n[1], n[0] + n[1]})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Liczby fibonacciego jest to jedna z rzeczy które lepiej wyglądają jak są zaimplementowane na for while niż na streamach :)

.limit(limit)
.map(n -> n[0])
.filter(n -> n % 2 == 0)
.mapToInt(n -> n)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taka funkcja nazywa się identity i można jej implementację znaleźć w Function.identity()

.sum();
}

}
51 changes: 51 additions & 0 deletions src/main/test/homeWork_20_Tests/SumOfEvenFibonacciNumbersTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package homeWork_20_Tests;


import org.assertj.core.api.Assertions;
import org.junit.Test;

import static homeWork_20.Calculator.fibonacciSequence;
import static org.assertj.core.api.Assertions.*;

public class SumOfEvenFibonacciNumbersTest {

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O jeden enter za dużo

@Test
public void shouldReturn10WhenAddingSumOfEvenFibonacciAndNumbers() {
//given
int numberOfLimit = 7;

//when
int sumOfEvenNumbers = fibonacciSequence(numberOfLimit);

//then
int expectedNumber = 10;
assertThat(sumOfEvenNumbers).isEqualTo(expectedNumber);
}

@Test
public void shouldReturn44WhenAddingSumOfEvenFibonacciAndNumbers() {
//given
int numberOfLimit = 10;

//when
int sumOfEvenNumbers = fibonacciSequence(numberOfLimit);

//then
int expectedNumber = 44;
assertThat(sumOfEvenNumbers).isEqualTo(expectedNumber);

}

@Test
public void shouldReturn188WhenAddingSumOfEvenFibonacciAndNumbers() {
//given
int numberOfLimit = 12;

//when
int sumOfEvenNumbers = fibonacciSequence(numberOfLimit);

//then
int expectedNumber = 188;
assertThat(sumOfEvenNumbers).isEqualTo(expectedNumber);
}
}
75 changes: 75 additions & 0 deletions src/main/test/homeWork_20_Tests/SumOfMutlipliers5or3Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package homeWork_20_Tests;

import org.assertj.core.api.Assertions;
import org.junit.Test;

import static homeWork_20.Calculator.*;
import static org.assertj.core.api.Assertions.*;

public class SumOfMutlipliers5or3Test {

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

za dużo o jeden enter

@Test
public void shouldReturn23WhenAddingSumOfMutliplies5or3ofNumber10() {
//given
int initialNumber = 10;

//when
int sumOfMultipliers = sumOfNaturalNumbers(initialNumber);

//then
int expectedNumber = 23;
assertThat(sumOfMultipliers).isEqualTo(expectedNumber);
}

@Test
public void shouldReturn33WhenAddingSumOfMutliplies5or3ofNumber11() {
//given
int initialNumber = 11;

//when
int sumOfMultipliers = sumOfNaturalNumbers(initialNumber);

//then
int expectedNumber = 33;
assertThat(sumOfMultipliers).isEqualTo(expectedNumber);
}

@Test
public void shouldReturn33WhenAddingSumOfMutliplies5or3ofNumber12() {
//given
int initialNumber = 12;

//when
int sumOfMultipliers = sumOfNaturalNumbers(initialNumber);

//then
int expectedNumber = 33;
assertThat(sumOfMultipliers).isEqualTo(expectedNumber);
}

@Test
public void shouldReturn45WhenAddingSumOfMutliplies5or3ofNumber13() {
//given
int initialNumber = 13;

//when
int sumOfMultipliers = sumOfNaturalNumbers(initialNumber);

//then
int expectedNumber = 45;
assertThat(sumOfMultipliers).isEqualTo(expectedNumber);
}

@Test
public void shouldReturn60WhenAddingSumOfMutliplies5or3ofNumber16() {
//given
int initialNumber = 16;

//when
int sumOfMultipliers = sumOfNaturalNumbers(initialNumber);

//then
int expectedNumber = 60;
assertThat(sumOfMultipliers).isEqualTo(expectedNumber);
}
}