From 41370497fdd5188a192a0f8a23c038473603aecb Mon Sep 17 00:00:00 2001 From: "@hangga" Date: Sat, 20 Jan 2024 08:48:38 +0700 Subject: [PATCH] assert that positive --- .../SecureRandomPositiveLongUnitTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 core-java-modules/core-java-numbers-7/src/test/java/com/baeldung/securerandompositivelong/SecureRandomPositiveLongUnitTest.java diff --git a/core-java-modules/core-java-numbers-7/src/test/java/com/baeldung/securerandompositivelong/SecureRandomPositiveLongUnitTest.java b/core-java-modules/core-java-numbers-7/src/test/java/com/baeldung/securerandompositivelong/SecureRandomPositiveLongUnitTest.java new file mode 100644 index 0000000000..b476a95d99 --- /dev/null +++ b/core-java-modules/core-java-numbers-7/src/test/java/com/baeldung/securerandompositivelong/SecureRandomPositiveLongUnitTest.java @@ -0,0 +1,24 @@ +package com.baeldung.securerandompositivelong; + +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; +import java.security.SecureRandom; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SecureRandomPositiveLongUnitTest { + + @Test + void whenGenerateRecureRandom_thenGetExpectedValue() { + SecureRandom secureRandom = new SecureRandom(); + long randomPositiveLong = Math.abs(secureRandom.nextLong()); + + assertThat(randomPositiveLong).isPositive(); + + Double pc = 1.0 / Math.pow(2, 63); + System.out.printf("%.40f", pc); + + assertThat(pc).isLessThan(0.00000000000000001); + } +}