JAVA_IIBRARY Telegram 1407
Ты создаёшь Java-класс для генерации 128-битных токенов, поэтому пишешь следующий тест:

Random random = new SecureRandom();
Tokens tokens = new Tokens(random);
Token result = tokens.next();
assertEquals(result.high(), ???);
assertEquals(result.low(), ???);


Что мы должны написать в проверках (assert)? Мы могли бы использовать обычный экземпляр Random с заданным сидом.
Другой вариант — заменить тип Random на интерфейс RandomGenerator:

RandomGenerator generator = fixedGenerator(1L, 2L);
Tokens tokens = new Tokens(generator);
Token result = tokens.next();
assertEquals(result.high(), 1L);
assertEquals(result.low(), 2L);


Где fixedGenerator выглядит следующим образом:

private RandomGenerator fixedGenerator(long... longs) {
return new RandomGenerator() {
private final long[] values = longs.clone();
private int index;

@Override
public final long nextLong() {
int currentIndex = index++;
if (index == values.length) {
index = 0;
}
return values[currentIndex];
}
};
}


Интерфейс java.util.random.RandomGenerator был добавлен в JDK 17 и реализуется классом java.util.Random

🔥всё верно
👍 если пост оказался полезным

👉 Java Portal
Please open Telegram to view this post
VIEW IN TELEGRAM



tgoop.com/Java_Iibrary/1407
Create:
Last Update:

Ты создаёшь Java-класс для генерации 128-битных токенов, поэтому пишешь следующий тест:

Random random = new SecureRandom();
Tokens tokens = new Tokens(random);
Token result = tokens.next();
assertEquals(result.high(), ???);
assertEquals(result.low(), ???);


Что мы должны написать в проверках (assert)? Мы могли бы использовать обычный экземпляр Random с заданным сидом.
Другой вариант — заменить тип Random на интерфейс RandomGenerator:

RandomGenerator generator = fixedGenerator(1L, 2L);
Tokens tokens = new Tokens(generator);
Token result = tokens.next();
assertEquals(result.high(), 1L);
assertEquals(result.low(), 2L);


Где fixedGenerator выглядит следующим образом:

private RandomGenerator fixedGenerator(long... longs) {
return new RandomGenerator() {
private final long[] values = longs.clone();
private int index;

@Override
public final long nextLong() {
int currentIndex = index++;
if (index == values.length) {
index = 0;
}
return values[currentIndex];
}
};
}


Интерфейс java.util.random.RandomGenerator был добавлен в JDK 17 и реализуется классом java.util.Random

🔥всё верно
👍 если пост оказался полезным

👉 Java Portal

BY Java Portal | Программирование


Share with your friend now:
tgoop.com/Java_Iibrary/1407

View MORE
Open in Telegram


Telegram News

Date: |

A vandalised bank during the 2019 protest. File photo: May James/HKFP. To edit your name or bio, click the Menu icon and select “Manage Channel.” Among the requests, the Brazilian electoral Court wanted to know if they could obtain data on the origins of malicious content posted on the platform. According to the TSE, this would enable the authorities to track false content and identify the user responsible for publishing it in the first place. For crypto enthusiasts, there was the “gm” app, a self-described “meme app” which only allowed users to greet each other with “gm,” or “good morning,” a common acronym thrown around on Crypto Twitter and Discord. But the gm app was shut down back in September after a hacker reportedly gained access to user data. So far, more than a dozen different members have contributed to the group, posting voice notes of themselves screaming, yelling, groaning, and wailing in various pitches and rhythms.
from us


Telegram Java Portal | Программирование
FROM American