Complete the code to make the test deterministic by fixing the seed.
Random random = new Random([1]); int value = random.nextInt(100); assertEquals(42, value);
Using a fixed seed like 0 ensures the random values are the same every run, making the test deterministic.
Complete the code to assert the expected value in a deterministic test.
@Test
public void testRandomValue() {
Random random = new Random(0);
int value = random.nextInt(100);
assertEquals([1], value);
}The fixed seed 0 produces 42 as the first random integer less than 100.
Fix the error in the test to make it deterministic by replacing the non-deterministic call.
@Test
public void testTimestamp() {
long fixedTimestamp = 1234567890L;
long timestamp = [1];
assertEquals(fixedTimestamp, timestamp);
}Using a fixed long value like 1234567890L ensures the test is deterministic and passes consistently.
Fill both blanks to create a deterministic test that checks a fixed random value.
@Test
public void testFixedRandom() {
Random random = new Random([1]);
int value = random.nextInt([2]);
assertEquals(42, value);
}Using seed 0 and nextInt(100) produces a deterministic value 42.
Fill all three blanks to create a deterministic test that asserts a fixed string length.
@Test
public void testStringLength() {
String text = "hello";
int length = text.[1]();
assertEquals([2], length);
assertTrue(length [3] 0);
}Using length() gets the string length, which is 5 for "hello". The assertion checks length > 0.