CompressionRatio { private CompressionRatio() { directory = SystemFileFactory.INSTANCE.getFile( FilePathUtils.regularizePath(CONFIG.getSystemDir()) + COMPRESSION_RATIO_DIR); restore(); } private  CompressionRatio(); synchronized void updateRatio(double currentCompressionRatio); double getRatio(); double getCompressionRatioSum(); static CompressionRatio getInstance();  }
@Test public void testCompressionRatio() throws IOException { double compressionRatioSum = 0; int calcuTimes = 0; if (new File(directory, String.format(Locale.ENGLISH, CompressionRatio.RATIO_FILE_PATH_FORMAT, compressionRatioSum , calcuTimes)).exists()) { fail(); } double compressionRatio = 10; for(int i = 0; i < 500 ; i+= compressionRatio){ this.compressionRatio.updateRatio(compressionRatio); if (new File(directory, String.format(Locale.ENGLISH, CompressionRatio.RATIO_FILE_PATH_FORMAT, compressionRatioSum , calcuTimes)).exists()) { fail(); } calcuTimes++; compressionRatioSum += compressionRatio; if (!new File(directory, String.format(Locale.ENGLISH, CompressionRatio.RATIO_FILE_PATH_FORMAT, compressionRatioSum , calcuTimes)).exists()) { fail(); } assertEquals(0, Double .compare(compressionRatioSum / calcuTimes, this.compressionRatio.getRatio())); } }