mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-06 17:29:31 +08:00
Format code with prettier (#3375)
This commit is contained in:
@ -25,28 +25,31 @@ public class FibonacciJavaStreams {
|
||||
return Optional.of(BigDecimal.ONE);
|
||||
}
|
||||
|
||||
final List<BigDecimal> results = Stream.iterate(
|
||||
final List<BigDecimal> results = Stream
|
||||
.iterate(
|
||||
index,
|
||||
x -> x.compareTo(BigDecimal.ZERO) > 0,
|
||||
x -> x.subtract(BigDecimal.ONE)
|
||||
)
|
||||
.reduce(
|
||||
List.of(),
|
||||
(list, current)
|
||||
-> list.isEmpty() || list.size() < 2
|
||||
)
|
||||
.reduce(
|
||||
List.of(),
|
||||
(list, current) ->
|
||||
list.isEmpty() || list.size() < 2
|
||||
? List.of(BigDecimal.ZERO, BigDecimal.ONE)
|
||||
: List.of(list.get(1), list.get(0).add(list.get(1))),
|
||||
(list1, list2) -> list1
|
||||
);
|
||||
(list1, list2) -> list1
|
||||
);
|
||||
|
||||
return results.isEmpty()
|
||||
? Optional.empty()
|
||||
: Optional.of(results.get(results.size() - 1));
|
||||
? Optional.empty()
|
||||
: Optional.of(results.get(results.size() - 1));
|
||||
}
|
||||
|
||||
public static void assertThat(final Object actual, final Object expected) {
|
||||
if (!Objects.equals(actual, expected)) {
|
||||
throw new AssertionError(String.format("expected=%s but was actual=%s", expected, actual));
|
||||
throw new AssertionError(
|
||||
String.format("expected=%s but was actual=%s", expected, actual)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,27 +91,39 @@ public class FibonacciJavaStreams {
|
||||
{
|
||||
final Optional<BigDecimal> result = calculate(new BigDecimal(30));
|
||||
assertThat(result.isPresent(), true);
|
||||
result.ifPresent(value -> assertThat(value, new BigDecimal(832040)));
|
||||
result.ifPresent(value -> assertThat(value, new BigDecimal(832040))
|
||||
);
|
||||
}
|
||||
{
|
||||
final Optional<BigDecimal> result = calculate(new BigDecimal(40));
|
||||
assertThat(result.isPresent(), true);
|
||||
result.ifPresent(value -> assertThat(value, new BigDecimal(102334155)));
|
||||
result.ifPresent(value ->
|
||||
assertThat(value, new BigDecimal(102334155))
|
||||
);
|
||||
}
|
||||
{
|
||||
final Optional<BigDecimal> result = calculate(new BigDecimal(50));
|
||||
assertThat(result.isPresent(), true);
|
||||
result.ifPresent(value -> assertThat(value, new BigDecimal(12586269025L)));
|
||||
result.ifPresent(value ->
|
||||
assertThat(value, new BigDecimal(12586269025L))
|
||||
);
|
||||
}
|
||||
{
|
||||
final Optional<BigDecimal> result = calculate(new BigDecimal(100));
|
||||
assertThat(result.isPresent(), true);
|
||||
result.ifPresent(value -> assertThat(value, new BigDecimal("354224848179261915075")));
|
||||
result.ifPresent(value ->
|
||||
assertThat(value, new BigDecimal("354224848179261915075"))
|
||||
);
|
||||
}
|
||||
{
|
||||
final Optional<BigDecimal> result = calculate(new BigDecimal(200));
|
||||
assertThat(result.isPresent(), true);
|
||||
result.ifPresent(value -> assertThat(value, new BigDecimal("280571172992510140037611932413038677189525")));
|
||||
result.ifPresent(value ->
|
||||
assertThat(
|
||||
value,
|
||||
new BigDecimal("280571172992510140037611932413038677189525")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user