### Question:
DifficultyCalculator { public Difficulty getNextJobDifficulty(Miner miner) { if (miner.getValidSharesSubmitted() < wait) { return new Difficulty(startDiff); } BigInteger hashrate = miner.getHashesSubmitted().divide(BigInteger.valueOf(miner.getConnectionPeriod())); BigInteger difficulty = hashrate.multiply(shareTargetTime); return new Difficulty(difficulty.max(minDiff)); } DifficultyCalculator(@Value("${varDiff.shareTargetTime}") long shareTargetTime,
                                @Value("${varDiff.minimum}") long minDiff,
                                @Value("${varDiff.start}") long startDiff,
                                @Value("${varDiff.wait}") int wait); Difficulty getNextJobDifficulty(Miner miner);  }### Answer:
@Test void testGetDifficultyUsesMin() { final BigInteger minDiff = BigInteger.valueOf(20_000); final DifficultyCalculator difficultyCalculator = new DifficultyCalculator(30, 20_000, 1, 0); for (int hashrate : List.of(10, 100, 500)) { Miner miner = new Miner(); miner.setConnectedAt(Instant.now().minusSeconds(120)); miner.setHashesSubmitted(BigInteger.valueOf(hashrate * 120)); miner.setValidSharesSubmitted(4L); Assertions.assertEquals(minDiff, difficultyCalculator.getNextJobDifficulty(miner).getDifficulty()); } }
@Test void testGetDifficultyUsesStart() { final BigInteger startDiff = BigInteger.valueOf(5000); final DifficultyCalculator difficultyCalculator = new DifficultyCalculator(1, 1, 5000L, 5); for (int i = 0; i < 5; i++) { final Miner miner = new Miner(); miner.setValidSharesSubmitted((long) i); miner.setHashesSubmitted(BigInteger.valueOf(100)); Assertions.assertEquals(startDiff, difficultyCalculator.getNextJobDifficulty(miner).getDifficulty()); } }