private static int testUnityULPCases() { int failures = 0; for (float sign : new float[] {-1, 1}) { for (float v1 : new float[] {1 << 23, 1 << 24}) { for (int k = -5; k <= 5; k++) { float value = (v1 + k) * sign; float actual = Math.round(value); failures += Tests.test("Math.round", value, actual, value); } } } if (failures != 0) { System.out.println(); } for (double sign : new double[] {-1, 1}) { for (double v1 : new double[] {1L << 52, 1L << 53}) { for (int k = -5; k <= 5; k++) { double value = (v1 + k) * sign; double actual = Math.round(value); failures += Tests.test("Math.round", value, actual, value); } } } return failures; }
@Test public void testRandom() { List<String> data = Tests.generateData(10000, 100); String[] arr = data.toArray(new String[data.size()]); DualPivotQuicksort.sort(arr); assertTrue(Tests.isSorted(arr)); }
private static int testNearHalfCases(float input, float expected) { int failures = 0; failures += Tests.test("Math.round", input, Math.round(input), expected); failures += Tests.test("StrictMath.round", input, StrictMath.round(input), expected); return failures; }
@Test public void testDictCalls() { try { List<String> data = Tests.loadData("dictcalls.gz", true); String[] arr = data.toArray(new String[data.size()]); DualPivotQuicksort.sort(arr); assertTrue(Tests.isSorted(arr)); } catch (IOException ioe) { fail(ioe.toString()); } }
@Test public void testSorted() { try { List<String> data = Tests.loadData(); Collections.sort(data); String[] arr = data.toArray(new String[data.size()]); DualPivotQuicksort.sort(arr); assertTrue(Tests.isSorted(arr)); } catch (IOException ioe) { fail(ioe.toString()); } }
public static void run() { LTMemory ltm = null; Object o = null; Tests.increment(); try { int initial = 1000; int maximum = 2000; ltm = new LTMemory(initial, maximum); if (!(ltm instanceof LTMemory && ltm instanceof ScopedMemory)) throw new Exception(); } catch (Exception e) { Tests.fail("LTMemoryTest"); } }
@Test // SONARJS-301 public void print_log_for_not_found_resource() throws InterruptedException { SonarRunner build = Tests.createSonarRunnerBuild() .setProjectDir(TestUtils.projectDir("lcov")) .setProjectKey("project") .setProjectName("project") .setProjectVersion("1.0") .setSourceDirs(".") .setProperty( "sonar.javascript.lcov.reportPath", TestUtils.file("projects/lcov/coverage-wrong-file-name.lcov").getAbsolutePath()) .setDebugLogs(true); BuildResult result = orchestrator.executeBuild(build); // Check that a log is printed String logs = result.getLogs(); assertThat(Pattern.compile("Analysing .*coverage-wrong-file-name\\.lcov").matcher(logs).find()) .isTrue(); assertThat( Pattern.compile("Default value of zero will be saved for file: .*file\\.js") .matcher(logs) .find()) .isTrue(); assertThat( Pattern.compile( "INFO.*Could not resolve 1 file paths in coverage-wrong-file-name\\.lcov, " + "first unresolved path: \\./wrong/fileName\\.js") .matcher(logs) .find()) .isTrue(); }
private void openAndWait(VirtualFile file, @Nullable String relativePath) throws InterruptedException, IOException { semaphore.down(); DesignerApplicationManager.getInstance() .renderDocument(myModule, Tests.virtualToPsi(myProject, file)); await(); }
@Test public void testRepeated() { String[] arr = new String[10000]; final String STR = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; Arrays.fill(arr, STR); DualPivotQuicksort.sort(arr); assertTrue(Tests.isRepeated(arr, STR)); }
public static void main(String args[]) { int arg = 0; ArrayList<String> inFile = new ArrayList<String>(); System.out.printf( "FIT Test Tool %d.%d.%d.%d\n", Fit.PROTOCOL_VERSION_MAJOR, Fit.PROTOCOL_VERSION_MINOR, Fit.PROFILE_VERSION_MAJOR, Fit.PROFILE_VERSION_MINOR); while (arg < args.length) { if (args[arg].equals("-d")) { Fit.debug = true; } else { String in = args[arg]; inFile.add(in); } arg++; } if (inFile.size() == 0) { printUsage(); return; } for (int i = 0; i < inFile.size(); i++) { Object stList[] = inFile.toArray(); System.out.println("Input file: " + ((String) stList[i])); try { if (!Decode.checkIntegrity((InputStream) new FileInputStream(((String) stList[i])))) throw new RuntimeException("FIT file integrity failure."); } catch (java.io.IOException e) { throw new RuntimeException(e); } Tests tests = new Tests(); System.out.println("Running FIT file verification tests..."); if (tests.run(((String) stList[i]))) System.out.println("Passed FIT file verification."); else System.out.println("Failed FIT file verification."); } }
@Test public void force_zero_coverage() { SonarRunner build = Tests.createSonarRunnerBuild() .setProjectDir(TestUtils.projectDir("lcov")) .setProjectKey("project") .setProjectKey("project") .setProjectName("project") .setProjectVersion("1.0") .setSourceDirs(".") .setProperty("sonar.javascript.forceZeroCoverage", "true"); orchestrator.executeBuild(build); assertThat(getProjectMeasure("lines_to_cover").getValue()).isEqualTo(4); assertThat(getProjectMeasure("uncovered_lines").getValue()).isEqualTo(4); if (Tests.is_strictly_after_plugin("2.4")) { assertThat(getFileMeasure("coverage_line_hits_data").getData()).isEqualTo("3=0;4=0;5=0;7=0"); } assertThat(getProjectMeasure("conditions_to_cover")).isNull(); assertThat(getProjectMeasure("uncovered_conditions")).isNull(); }
@Test public void LCOV_it_coverage() { if (Tests.is_strictly_after_plugin("2.5")) { SonarRunner build = Tests.createSonarRunnerBuild() .setProjectDir(TestUtils.projectDir("lcov")) .setProjectKey("project") .setProjectName("project") .setProjectVersion("1.0") .setSourceDirs(".") .setProperty( "sonar.javascript.lcov.itReportPath", TestUtils.file("projects/lcov/coverage.lcov").getAbsolutePath()); orchestrator.executeBuild(build); assertThat(getProjectMeasure("it_lines_to_cover").getValue()).isEqualTo(4); assertThat(getProjectMeasure("it_uncovered_lines").getValue()).isEqualTo(1); assertThat(getProjectMeasure("it_conditions_to_cover").getValue()).isEqualTo(4); assertThat(getProjectMeasure("it_uncovered_conditions").getValue()).isEqualTo(2); } }
@DontRepeat @Test public void testNotNull() throws Exception { AlchemyAssertion<Object> instance = notNull(); assertThat(instance, notNullValue()); Tests.checkForNullCase(instance); Object mock = mock(Object.class); instance.check(mock); verifyZeroInteractions(mock); }
public static void run() { MarkAndSweepCollectorExample mc = null; Object o = null; Tests.increment(); try { mc = new MarkAndSweepCollectorExample(); if (!(mc instanceof MarkAndSweepCollectorExample && mc instanceof GarbageCollector)) throw new Exception(); } catch (Exception e) { Tests.fail("MarkAndSweepCollectorExampleTest"); } Tests.increment(); try { o = mc.getPreemptionLatency(); if (!(o instanceof RelativeTime)) throw new Exception(); } catch (Exception e) { Tests.fail("MarkAndSweepCollectorExampleTest"); } }
@Test public void testArguments() { DualPivotQuicksort.sort((String[]) null); DualPivotQuicksort.sort(new String[0]); String[] arr = new String[] {"a"}; DualPivotQuicksort.sort(arr); arr = new String[] {"b", "a"}; DualPivotQuicksort.sort(arr); assertTrue(Tests.isSorted(arr)); arr = new String[] {"c", "b", "a"}; DualPivotQuicksort.sort(arr); assertTrue(Tests.isSorted(arr)); // test with all empty input arr = new String[] {"", "", "", "", "", "", "", "", "", ""}; DualPivotQuicksort.sort(arr); for (String s : arr) { assertEquals("", s); } // test with peculiar input arr = new String[] {"z", "m", "", "a", "d", "tt", "tt", "tt", "foo", "bar"}; DualPivotQuicksort.sort(arr); assertTrue("peculiar input not sorted", Tests.isSorted(arr)); }
@Test public void no_coverage_information_saved() { SonarRunner build = Tests.createSonarRunnerBuild() .setProjectDir(TestUtils.projectDir("lcov")) .setProjectKey("project") .setProjectName("project") .setProjectVersion("1.0") .setSourceDirs("."); orchestrator.executeBuild(build); assertThat(getProjectMeasure("lines_to_cover")).isNull(); assertThat(getProjectMeasure("uncovered_lines")).isNull(); assertThat(getProjectMeasure("conditions_to_cover")).isNull(); assertThat(getProjectMeasure("uncovered_conditions")).isNull(); }
private void renderAndWait(VirtualFile file) throws InterruptedException { semaphore.down(); AsyncResult<DocumentInfo> result = DesignerApplicationManager.getInstance() .renderDocument(myModule, Tests.virtualToPsi(myProject, file)); result.doWhenProcessed( new Runnable() { @Override public void run() { semaphore.up(); } }); await(); }
@Test public void testRepeatedCycle() { String[] strs = new String[100]; String seed = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; for (int i = 0, l = 1; i < strs.length; i++, l++) { strs[i] = seed.substring(0, l); } List<String> list = new ArrayList<String>(); for (int c = 10000, i = 0; c > 0; i++, c--) { list.add(strs[i % strs.length]); } String[] arr = list.toArray(new String[list.size()]); DualPivotQuicksort.sort(arr); assertTrue(Tests.isSorted(arr)); }
@Test public void LCOV_path_can_be_relative() throws Exception { SonarRunner build = Tests.createSonarRunnerBuild() .setProjectDir(TestUtils.projectDir("lcov")) .setProjectKey("project") .setProjectName("project") .setProjectVersion("1.0") .setSourceDirs(".") .setProperty("sonar.javascript.lcov.reportPath", "coverage.lcov"); orchestrator.executeBuild(build); assertThat(getProjectMeasure("lines_to_cover").getValue()).isEqualTo(4); assertThat(getProjectMeasure("uncovered_lines").getValue()).isEqualTo(1); assertThat(getProjectMeasure("conditions_to_cover").getValue()).isEqualTo(4); assertThat(getProjectMeasure("uncovered_conditions").getValue()).isEqualTo(2); }
@Override protected void changeServicesImplementation() { Tests.changeDesignerServiceImplementation(SocketInputHandler.class, MySocketInputHandler.class); Tests.changeDesignerServiceImplementation(Client.class, TestClient.class); }
@org.junit.Test public void test() throws Exception { Map<String, Test> tests = Tests.getAll("/META-INF/my_sample_tests.xml"); // TODO: complete this }
private static int testSpecialCases() { int failures = 0; failures += Tests.test("Math.round", Float.NaN, Math.round(Float.NaN), 0.0F); failures += Tests.test( "Math.round", Float.POSITIVE_INFINITY, Math.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE); failures += Tests.test( "Math.round", Float.NEGATIVE_INFINITY, Math.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE); failures += Tests.test( "Math.round", -(float) Integer.MIN_VALUE, Math.round(-(float) Integer.MIN_VALUE), Integer.MAX_VALUE); failures += Tests.test( "Math.round", (float) Integer.MIN_VALUE, Math.round((float) Integer.MIN_VALUE), Integer.MIN_VALUE); failures += Tests.test("Math.round", 0F, Math.round(0F), 0.0F); failures += Tests.test("Math.round", Float.MIN_VALUE, Math.round(Float.MIN_VALUE), 0.0F); failures += Tests.test("Math.round", -Float.MIN_VALUE, Math.round(-Float.MIN_VALUE), 0.0F); failures += Tests.test("Math.round", Double.NaN, Math.round(Double.NaN), 0.0); failures += Tests.test( "Math.round", Double.POSITIVE_INFINITY, Math.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE); failures += Tests.test( "Math.round", Double.NEGATIVE_INFINITY, Math.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE); failures += Tests.test( "Math.round", -(double) Long.MIN_VALUE, Math.round(-(double) Long.MIN_VALUE), Long.MAX_VALUE); failures += Tests.test( "Math.round", (double) Long.MIN_VALUE, Math.round((double) Long.MIN_VALUE), Long.MIN_VALUE); failures += Tests.test("Math.round", 0, Math.round(0), 0.0); failures += Tests.test("Math.round", Double.MIN_VALUE, Math.round(Double.MIN_VALUE), 0.0); failures += Tests.test("Math.round", -Double.MIN_VALUE, Math.round(-Double.MIN_VALUE), 0.0); return failures; }
public static void run() { RawMemoryFloatAccess rmfa = null; Object o = null; long base = BASEADDR; // constructors protected Tests.newTest("RawMemoryFloatAccessTest"); Object type = new Object(); DefaultPhysicalMemoryFilter filter = null; /* SETUP for PhysicalMemoryManager */ try { filter = new DefaultPhysicalMemoryFilter(BASEADDR, SIZE); PhysicalMemoryManager.registerFilter(type, filter); } catch (Exception e) { System.out.println("An exception occurred while trying ton register filter"); e.printStackTrace(); Tests.fail("RawMemoryFloatAccessTest"); return; } /* Subtest 1 ** Constructor "public RawMemoryFloatAccess(Object type, long size) */ Tests.increment(); try { System.out.println("RawMemoryFloatAccessTest: createFloatAccess(" + "Object,long)"); long size = 4096; o = new RawMemoryFloatAccess(type, size); base += size; if (!(o instanceof RawMemoryFloatAccess)) throw new Exception("Return object is not instanceof " + "RawMemoryFloatAccess"); } catch (Exception e) { System.out.println("RawMemoryFloatAccessTest: createFloatAccess(" + "Object,long) failed"); Tests.fail("RawMemoryFloatAccess.createFloatAccess()", e); } /* Subtest 2 ** Constructor "public RawMemoryFloatAccess(Object type, ** long base, long size)" */ Tests.increment(); try { System.out.println("RawMemoryFloatAccessTest: createFloatAccess(" + "Object,long,long)"); long size = 4096; o = new RawMemoryFloatAccess(type, base, size); base += size; if (!(o instanceof RawMemoryFloatAccess)) throw new Exception("Return object is not instanceof " + "RawMemoryFloatAccess"); } catch (Exception e) { System.out.println( "RawMemoryFloatAccessTest: createFloatAccess(" + "Object,long,long) failed"); Tests.fail("RawMemoryFloatAccess.createFloatAccess()", e); } /* Subtest 3 ** Methods "public void setDouble( long offset, double value)" and ** "public double getDouble( long offset)" */ Tests.increment(); try { System.out.println("RawMemoryFloatAccessTest: setDouble(long," + "double), getDouble(long)"); long size = 4096; rmfa = new RawMemoryFloatAccess(type, base, size); base += size; rmfa.setDouble(0L, (double) 112.5); if (rmfa.getDouble(0L) != 112.5) throw new Exception("Double not set properly"); } catch (Exception e) { System.out.println( "RawMemoryFloatAccessTest: setDouble(long," + "double), getDouble(long) failed"); Tests.fail("rmfa.setDouble() and rmfa.getDouble()", e); } /* Subtest 4 ** Methods "public void setDoubles( long offset, double[] doubles, ** int low, int number)" and ** "public void getDoubles( long offset, double[] doubles, ** int low, int number))" */ Tests.increment(); try { System.out.println( "RawMemoryFloatAccessTest: setDoubles(long," + "double[],int,int), getDoubles(long,double[]," + "int,int)"); double[] doubles = new double[4]; doubles[0] = 1; doubles[1] = 2; rmfa.setDoubles(5L, doubles, 0, 2); rmfa.getDoubles(5L, doubles, 2, 2); if (!(doubles[0] == doubles[2] && doubles[1] == doubles[3])) throw new Exception("Doubles were not set properly"); } catch (Exception e) { System.out.println( "RawMemoryFloatAccessTest: setDoubles(long," + "double[],int,int), getDoubles(long,double[]," + "int,int) failed"); Tests.fail("rmfa.setDoubles() and rmfa.getDoubles()", e); } /* Subtest 5 ** Methods "public void setFloat( long offset, float value)" and ** "public float getFloat( long offset)" */ Tests.increment(); try { System.out.println("RawMemoryFloatAccessTest: setFloat(long," + "float), getFloat(long)"); rmfa.setFloat(0L, (float) 124.5); if (rmfa.getFloat(0L) != 124.5) throw new Exception("Float not set properly"); } catch (Exception e) { System.out.println( "RawMemoryFloatAccessTest: setFloat(long," + "float), getFloat(long) failed"); Tests.fail("rmfa.setFloat() and rmfa.getFloat()", e); } /* Subtest 6 ** Methods "public void setFloats( long offset, float[] floats, int ** low, int number)" and ** "public void getFloats( long offset, float[] floats, int ** low, int number))" */ Tests.increment(); try { System.out.println( "RawMemoryFloatAccessTest: setFloats(long," + "float[],int,int), getFloats(long,float[],int," + "int)"); float[] floats = new float[4]; floats[0] = 100; floats[1] = 200; rmfa.setFloats(5L, floats, 0, 2); rmfa.getFloats(5L, floats, 2, 2); System.out.println("floats[0]=" + floats[0]); System.out.println("floats[1]=" + floats[1]); System.out.println("floats[2]=" + floats[2]); System.out.println("floats[3]=" + floats[3]); if (!(floats[0] == floats[2] && floats[1] == floats[3])) throw new Exception("Floats were not set properly"); } catch (Exception e) { System.out.println( "RawMemoryFloatAccessTest: setFloats(long," + "float[],int,int), getFloats(long,float[],int," + "int) failed"); Tests.fail("rmfa.setFloats() and rmfa.getFloats()", e); } Tests.printSubTestReportTotals("RawMemoryFloatAccessTest"); }
public static void main(java.lang.String[] args) { Tests.init(); run(); Tests.conclude(); }