Skip to content

homeWork20 done#2

Open
DominikCzerski wants to merge 2 commits intomasterfrom
homeWork20
Open

homeWork20 done#2
DominikCzerski wants to merge 2 commits intomasterfrom
homeWork20

Conversation

@DominikCzerski
Copy link
Owner

No description provided.

public class Calculator {

public static int sumOfNaturalNumbers(int limit) {
return Stream.iterate(1, n -> n < limit, n -> n + 1)
Copy link

Choose a reason for hiding this comment

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

Alternatywnie możesz tutaj użyć IntStream.range()

}

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 :)

return Stream.iterate(new int[]{1, 1}, n -> new int[]{n[1], n[0] + n[1]})
.limit(limit)
.map(n -> n[0])
.filter(n -> (n % 2 == 0))
Copy link

Choose a reason for hiding this comment

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

Nawiasy nie są potrzebne

.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()

import static homeWork_20.Calculator.fibonacciSequence;

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


//then
int expectedNumber = 10;
Assertions.assertThat(sumOfEvenNumbers).isEqualTo(expectedNumber);
Copy link

Choose a reason for hiding this comment

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

Stosuj statyczne importy - dodają czytelności testom

import static homeWork_20.Calculator.*;

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

Assertions.assertThat(sumOfMultipliers).isEqualTo(expectedNumber);
}


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 dwa entery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant