maven compiles all tests independetly of which tests are run

This commit is contained in:
2026-03-03 01:02:23 +01:00
parent f2db063e5c
commit 86a691b044
76 changed files with 321 additions and 38 deletions

View File

@@ -0,0 +1,57 @@
package oving1;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public class UpOrDownCounterTest {
@Test
@DisplayName("Count up")
public void testCountUp() {
UpOrDownCounter counter = new UpOrDownCounter(1, 5);
assertEquals(1, counter.getCounter(),
"Counter value should be equal to starting value when created");
for (int i = 2; i < 5; i++) {
boolean result = counter.count();
assertEquals(i, counter.getCounter(), "Wrong counter value");
assertTrue(result, "#count() should return true while within legal values");
}
boolean result = counter.count();
assertEquals(5, counter.getCounter(), "Wrong counter value");
assertFalse(result, "#count() should return false when we cannot count further");
result = counter.count();
assertEquals(5, counter.getCounter(),
"Counter value should not change when counting beyond legal values");
assertFalse(result, "#count() should return false when we cannot count further");
}
@Test
@DisplayName("Count down")
public void testCountDown() {
UpOrDownCounter counter = new UpOrDownCounter(1, -5);
assertEquals(1, counter.getCounter(),
"Counter value should be equal to starting value when created");
for (int i = 0; i > -5; i--) {
boolean result = counter.count();
assertEquals(i, counter.getCounter(), "Wrong counter value");
assertTrue(result, "#count() should return true while within legal values");
}
boolean result = counter.count();
assertEquals(-5, counter.getCounter(), "Wrong counter value");
assertFalse(result, "#count() should return false when we cannot count further");
result = counter.count();
assertEquals(-5, counter.getCounter(),
"Counter value should not change when counting beyond legal values");
assertFalse(result, "#count() should return false when we cannot count further");
}
}