diff --git a/tests/TestCubicSurfaceExtractor.cpp b/tests/TestCubicSurfaceExtractor.cpp index 88e9b746..df821f30 100644 --- a/tests/TestCubicSurfaceExtractor.cpp +++ b/tests/TestCubicSurfaceExtractor.cpp @@ -67,7 +67,6 @@ VolumeType* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, typename Vol // Set up a random number generator std::mt19937 rng; - std::uniform_int_distribution dist(minValue, maxValue); //Fill the volume with data for (int32_t z = 0; z < iVolumeSideLength; z++) @@ -84,7 +83,9 @@ VolumeType* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, typename Vol else { // Otherwise we write random voxel values between zero and the requested maximum - typename VolumeType::VoxelType voxelValue = static_cast(dist(rng)); + // We can't use std distributions because they vary between platforms (breaking tests). + int voxelValue = (rng() % (maxValue - minValue + 1)) + minValue; // +1 for inclusive bounds + volData->setVoxelAt(x, y, z, static_cast(voxelValue)); } } diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index 2848b552..6be9aa2d 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -128,15 +128,6 @@ VolumeType* createAndFillVolume(void) return volData; } -// From http://stackoverflow.com/a/5289624 -float randomFloat(float a, float b) -{ - float random = ((float)rand()) / (float)RAND_MAX; - float diff = b - a; - float r = random * diff; - return a + r; -} - template VolumeType* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, float minValue, float maxValue) { @@ -147,7 +138,6 @@ VolumeType* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, float minVal // Set up a random number generator std::mt19937 rng; - std::uniform_real_distribution dist(minValue, maxValue); // Fill for (int32_t z = 0; z < iVolumeSideLength; z++) @@ -156,7 +146,10 @@ VolumeType* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, float minVal { for (int32_t x = 0; x < iVolumeSideLength; x++) { - float voxelValue = dist(rng); + // We can't use std distributions because they vary between platforms (breaking tests) + float voxelValue = static_cast(rng()) / static_cast(std::numeric_limits::max()); // Float in range 0.0 to 1.0 + voxelValue = voxelValue * (maxValue - minValue) + minValue; // Float in range minValue to maxValue + volData->setVoxelAt(x, y, z, voxelValue); } } @@ -233,7 +226,7 @@ void TestSurfaceExtractor::testNoiseVolumePerformance() auto noiseVol = createAndFillVolumeWithNoise< PagedVolume >(128, -1.0f, 1.0f); Mesh< MarchingCubesVertex< float >, uint16_t > noiseMesh; QBENCHMARK{ extractMarchingCubesMeshCustom(noiseVol, Region(32, 32, 32, 63, 63, 63), &noiseMesh); } - QCOMPARE(noiseMesh.getNoOfVertices(), uint16_t(48704)); + QCOMPARE(noiseMesh.getNoOfVertices(), uint16_t(36755)); } QTEST_MAIN(TestSurfaceExtractor)