From 9a03b6be6d7af61453f12bfff138922e4d28da08 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Wed, 23 Sep 2020 16:49:00 +0100 Subject: [PATCH] JAL-3477 Added 10k leeway to amount of memory reserved for OS test for float rounding errors (needed to fix failing test) --- test/jalview/bin/MemorySettingTest.java | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/test/jalview/bin/MemorySettingTest.java b/test/jalview/bin/MemorySettingTest.java index 5577f6c..c67000a 100644 --- a/test/jalview/bin/MemorySettingTest.java +++ b/test/jalview/bin/MemorySettingTest.java @@ -35,17 +35,19 @@ public class MemorySettingTest long MB = KB * KB; long GB = MB * KB; // long TB = GB * KB; - + /* some of these tests assume a host machine with RAM somewhere between 1GB and 1TB */ - // should return 100% of physical memory available (or 1TB whichever is smaller) + // should return 100% of physical memory available (or 1TB whichever is + // smaller) long mem1 = MemorySetting.getMemorySetting("1T", "100"); long fullmem = mem1 + 512 * MB; // mem1 gets 512MB removed for the OS long mem1b = MemorySetting.getMemorySetting("1t", "100"); assertTrue(mem1 > 1 * GB); assertEquals(mem1, mem1b); - - // test 10% memory. Note 512MB is set as minimum, so adjust to 50% if less than + + // test 10% memory. Note 512MB is set as minimum, so adjust to 50% if less + // than // 5GB RAM. String pc; Float pcf; @@ -60,19 +62,21 @@ public class MemorySettingTest pcf = 0.5f; } long mem1c = MemorySetting.getMemorySetting("1T", pc); - assertTrue(mem1c > (pcf - 0.01) * fullmem && mem1c < (pcf + 0.01) * fullmem); // allowing for floating point errors - + assertTrue(mem1c > (pcf - 0.01) * fullmem + && mem1c < (pcf + 0.01) * fullmem); // allowing for floating point + // errors + // should return 1GB (assuming host machine has more than 1GB RAM) long mem2 = MemorySetting.getMemorySetting("1G", "100"); long mem2b = MemorySetting.getMemorySetting("1g", "100"); assertEquals(mem2, 1 * GB); assertEquals(mem2, mem2b); - + long mem3 = MemorySetting.getMemorySetting("1024M", "100"); long mem3b = MemorySetting.getMemorySetting("1024m", "100"); assertEquals(mem3, 1024 * MB); assertEquals(mem3, mem3b); - + long mem4 = MemorySetting.getMemorySetting("1048576K", "100"); long mem4b = MemorySetting.getMemorySetting("1048576k", "100"); assertEquals(mem4, 1048576 * KB); @@ -100,9 +104,13 @@ public class MemorySettingTest assertEquals(mem7, 512 * MB); // ensure enough memory for OS - long mem8 = MemorySetting.getMemorySetting("2TB", "100"); // this should be short of 512MB - long mem8b = MemorySetting.getMemorySetting("2TB", "50"); - assertEquals(mem8b * 2 - mem8, 512 * MB); + long mem8 = MemorySetting.getMemorySetting("2T", "100"); // this should be + // short of 512MB + long mem8b = MemorySetting.getMemorySetting("2T", "50"); + // allow 10k leeway + long diff = mem8b * 2 - mem8; + assertTrue(512 * MB - 10 * KB < diff && diff < 512 * MB + 10 * KB); + // assertEquals(mem8b * 2 - mem8, 512 * MB); } } -- 1.7.10.2