From c0831688bab852b5d1b047c9ca5fbd096bc30aa8 Mon Sep 17 00:00:00 2001 From: "J. Neugebauer" Date: Thu, 14 Jul 2022 17:59:48 +0200 Subject: [PATCH] =?UTF-8?q?Test=20f=C3=BCr=20Noise-Klasse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/schule/ngb/zm/ConstantsTest.java | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/test/java/schule/ngb/zm/ConstantsTest.java b/src/test/java/schule/ngb/zm/ConstantsTest.java index 3270a19..529a696 100644 --- a/src/test/java/schule/ngb/zm/ConstantsTest.java +++ b/src/test/java/schule/ngb/zm/ConstantsTest.java @@ -71,7 +71,7 @@ class ConstantsTest { } @Test - void b() { + void asBool() { assertTrue(Constants.asBool(true)); assertFalse(Constants.asBool(false)); assertTrue(Constants.asBool(1)); @@ -128,4 +128,45 @@ class ConstantsTest { assertEquals(.8f, Math.abs(t/(t+f)), .01f); } + @Test + void noise() { + double lastNoise = -1.0; + for( int i = 0; i < 100; i++ ) { + double thisNoise = Constants.noise(i * 0.005); + + assertInRange(thisNoise); + assertNotEquals(lastNoise, thisNoise); + assertEquals(thisNoise, Constants.noise(i * 0.005), 0.0001); + + lastNoise = thisNoise; + } + + lastNoise = -1.0; + for( int i = 0; i < 100; i++ ) { + double thisNoise = Constants.noise(i * 0.005, 0.1); + + assertInRange(thisNoise); + assertNotEquals(lastNoise, thisNoise); + assertEquals(thisNoise, Constants.noise(i * 0.005, 0.1), 0.0001); + + lastNoise = thisNoise; + } + + lastNoise = -1.0; + for( int i = 0; i < 100; i++ ) { + double thisNoise = Constants.noise(i * 0.005, 5.5, 100.0/(i+1)); + + assertInRange(thisNoise); + assertNotEquals(lastNoise, thisNoise); + assertEquals(thisNoise, Constants.noise(i * 0.005, 5.5, 100.0/(i+1)), 0.0001); + + lastNoise = thisNoise; + } + } + + private void assertInRange( double d ) { + assertFalse(Double.isNaN(d), "Noise value can't be NaN."); + assertTrue(0.0 <= d && 1.0 >= d, "Noise should be in Range 0 to 1. Was <" + d + ">."); + } + }