BAEL-5970 Working with MathFlux (#15116)

* Working with MathFlux.

* revert change to readme.

* merge codes in unit test.

* merge codes in unit test.

---------

Co-authored-by: rezaganjis <Ganji@tosan.com>
This commit is contained in:
Reza Ganji 2023-11-03 07:57:27 +03:30 committed by GitHub
parent 6f618f5cf9
commit b11ba77937
2 changed files with 54 additions and 1 deletions

View File

@ -26,6 +26,11 @@
<version>${reactor.version}</version> <version>${reactor.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>io.projectreactor.addons</groupId>
<artifactId>reactor-extra</artifactId>
<version>${reactor.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
@ -35,7 +40,7 @@
</dependencies> </dependencies>
<properties> <properties>
<reactor.version>3.4.17</reactor.version> <reactor.version>3.5.1</reactor.version>
</properties> </properties>
</project> </project>

View File

@ -0,0 +1,48 @@
package com.baeldung.math;
import org.junit.Test;
import reactor.math.MathFlux;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
public class MathFluxOperationsUnitTest {
@Test
public void givenFluxOfNumbers_whenCalculatingSum_thenExpectCorrectResult() {
Flux<Integer> numbers = Flux.just(1, 2, 3, 4, 5);
Mono<Integer> sumMono = MathFlux.sumInt(numbers);
StepVerifier.create(sumMono)
.expectNext(15)
.verifyComplete();
}
@Test
public void givenFluxOfNumbers_whenCalculatingAverage_thenExpectCorrectResult() {
Flux<Integer> numbers = Flux.just(1, 2, 3, 4, 5);
Mono<Double> averageMono = MathFlux.averageDouble(numbers);
StepVerifier.create(averageMono)
.expectNext(3.0)
.verifyComplete();
}
@Test
public void givenFluxOfNumbers_whenFindingMinElement_thenExpectCorrectResult() {
Flux<Integer> numbers = Flux.just(3, 1, 5, 2, 4);
Mono<Integer> minMono = MathFlux.min(numbers);
StepVerifier.create(minMono)
.expectNext(1)
.verifyComplete();
}
@Test
public void givenFluxOfNumbers_whenFindingMaxElement_thenExpectCorrectResult() {
Flux<Integer> numbers = Flux.just(3, 1, 5, 2, 4);
Mono<Integer> maxMono = MathFlux.max(numbers);
StepVerifier.create(maxMono)
.expectNext(5)
.verifyComplete();
}
}