add lab3 tests
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import org.junit.jupiter.api.Test;
|
||||
import ru.lionarius.IntegralCalculator;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@@ -50,4 +52,44 @@ class IntegralCalculatorTests {
|
||||
assertIntegral(-0.5, calculator, function, upperBound, lowerBound);
|
||||
assertIntegral(0.0, calculator, function, lowerBound, lowerBound);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProgressCallbackDifferentBounds() {
|
||||
final var currentStep = new AtomicLong();
|
||||
final var totalSteps = new AtomicLong();
|
||||
final var callbackCount = new AtomicLong(0);
|
||||
|
||||
final BiConsumer<Long, Long> progressCallback = (current, total) -> {
|
||||
currentStep.set(current);
|
||||
totalSteps.set(total);
|
||||
callbackCount.incrementAndGet();
|
||||
};
|
||||
|
||||
final var calculator = new IntegralCalculator(0.01, progressCallback);
|
||||
|
||||
calculator.calculate(x -> x, 0, 1);
|
||||
|
||||
assertTrue(callbackCount.get() >= 2, "Callback should be called at least twice");
|
||||
assertEquals(totalSteps.get(), currentStep.get(), "Final progress should be equal to total steps");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProgressCallbackSameBounds() {
|
||||
var currentStep = new AtomicLong();
|
||||
var totalSteps = new AtomicLong();
|
||||
var callbackCount = new AtomicLong(0);
|
||||
|
||||
BiConsumer<Long, Long> progressCallback = (current, total) -> {
|
||||
currentStep.set(current);
|
||||
totalSteps.set(total);
|
||||
callbackCount.incrementAndGet();
|
||||
};
|
||||
|
||||
var calculator = new IntegralCalculator(0.01, progressCallback);
|
||||
|
||||
calculator.calculate(x -> x, 0, 0);
|
||||
|
||||
assertTrue(callbackCount.get() >= 2, "Callback should be called at least twice");
|
||||
assertEquals(totalSteps.get(), currentStep.get(), "Final progress should be equal to total steps");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user