statisticalruletest.java
来自「检查Java程序漏洞」· Java 代码 · 共 756 行 · 第 1/2 页
JAVA
756 行
int topScore = randomTopScore(expectedSigma(sigma)); verifyResults(sigma, NO_MINIMUM, topScore, expectedTopScore(topScore), 0); } } public void testST1() throws Throwable { testST(); } public void testST2() throws Throwable { testST(); } public void testST3() throws Throwable { testST(); } public void testST4() throws Throwable { testST(); } public void testST5() throws Throwable { testST(); } public void testTS() throws Throwable { verifyResults(MAX_SIGMA, NO_MINIMUM, randomTopScore(), 0, 0); for (int i = 0; i < NUM_TESTS; i++) { int topScore = randomTopScore(); double sigma = randomSigma(expectedTopScore(topScore)); verifyResults(sigma, -1.0, topScore, expectedSigma(sigma), 2); } } public void testTS1() throws Throwable { testTS(); } public void testTS2() throws Throwable { testTS(); } public void testTS3() throws Throwable { testTS(); } public void testTS4() throws Throwable { testTS(); } public void testTS5() throws Throwable { testTS(); } public void testSM() throws Throwable { verifyResults(randomSigma(), MAX_MINIMUM, NO_TOPSCORE, 0, 0); for (int i = 0; i < NUM_TESTS; i++) { double sigma = randomSigma(); double minimum = randomMinimum(expectedSigma(sigma)); verifyResults(sigma, minimum, -1, expectedMinimum(minimum), 0); } } public void testSM1() throws Throwable { testSM(); } public void testSM2() throws Throwable { testSM(); } public void testSM3() throws Throwable { testSM(); } public void testSM4() throws Throwable { testSM(); } public void testSM5() throws Throwable { testSM(); } public void testMS() throws Throwable { verifyResults(MAX_SIGMA, randomMinimum(), NO_TOPSCORE, 0, 0); for (int i = 0; i < NUM_TESTS; i++) { double minimum = randomMinimum(); double sigma = randomSigma(expectedMinimum(minimum)); verifyResults(sigma, minimum, -1, expectedSigma(sigma), 2); } } public void testMS1() throws Throwable { testMS(); } public void testMS2() throws Throwable { testMS(); } public void testMS3() throws Throwable { testMS(); } public void testMS4() throws Throwable { testMS(); } public void testMS5() throws Throwable { testMS(); } public void testTM() throws Throwable { verifyResults(NO_SIGMA, MAX_MINIMUM, randomTopScore(), 0, 0); for (int i = 0; i < NUM_TESTS; i++) { int topScore = randomTopScore(); double minimum = randomMinimum(expectedTopScore(topScore)); verifyResults(NO_SIGMA, minimum, topScore, expectedMinimum(minimum), 0); } } public void testTM1() throws Throwable { testTM(); } public void testTM2() throws Throwable { testTM(); } public void testTM3() throws Throwable { testTM(); } public void testTM4() throws Throwable { testTM(); } public void testTM5() throws Throwable { testTM(); } public void testMT() throws Throwable { verifyResults(NO_SIGMA, randomMinimum(), MIN_TOPSCORE, 0, 0); for (int i = 0; i < NUM_TESTS; i++) { double minimum = randomMinimum(); int topScore = randomTopScore(expectedMinimum(minimum)); verifyResults(NO_SIGMA, minimum, topScore, expectedTopScore(topScore), 0); } } public void testMT1() throws Throwable { testMT(); } public void testMT2() throws Throwable { testMT(); } public void testMT3() throws Throwable { testMT(); } public void testMT4() throws Throwable { testMT(); } public void testMT5() throws Throwable { testMT(); } public void testSTM() throws Throwable { double sigma = randomSigma(); verifyResults(sigma, MAX_MINIMUM, randomTopScore(expectedSigma(sigma)), 0, 0); for (int i = 0; i < NUM_TESTS; i++) { sigma = randomSigma(); int topScore = randomTopScore(expectedSigma(sigma)); double minimum = randomMinimum(expectedTopScore(topScore)); verifyResults(sigma, minimum, topScore, expectedMinimum(minimum), 0); } } public void testSTM1() throws Throwable { testSTM(); } public void testSTM2() throws Throwable { testSTM(); } public void testSTM3() throws Throwable { testSTM(); } public void testSTM4() throws Throwable { testSTM(); } public void testSTM5() throws Throwable { testSTM(); } public void testSMT() throws Throwable { double sigma = randomSigma(); verifyResults(sigma, randomMinimum(expectedSigma(sigma)), MIN_TOPSCORE, 0, 0); for (int i = 0; i < NUM_TESTS; i++) { sigma = randomSigma(); double minimum = randomMinimum(expectedSigma(sigma)); int topScore = randomTopScore(expectedMinimum(minimum)); verifyResults(sigma, minimum, topScore, expectedTopScore(topScore), 0); } } public void testSMT1() throws Throwable { testSMT(); } public void testSMT2() throws Throwable { testSMT(); } public void testSMT3() throws Throwable { testSMT(); } public void testSMT4() throws Throwable { testSMT(); } public void testSMT5() throws Throwable { testSMT(); } public void testTSM() throws Throwable { int topScore = randomTopScore(); verifyResults(randomSigma(expectedTopScore(topScore)), MAX_MINIMUM, topScore, 0, 0); for (int i = 0; i < NUM_TESTS; i++) { topScore = randomTopScore(); double sigma = randomSigma(expectedTopScore(topScore)); double minimum = randomMinimum(expectedSigma(sigma)); verifyResults(sigma, minimum, topScore, expectedMinimum(minimum), 0); } } public void testTSM1() throws Throwable { testTSM(); } public void testTSM2() throws Throwable { testTSM(); } public void testTSM3() throws Throwable { testTSM(); } public void testTSM4() throws Throwable { testTSM(); } public void testTSM5() throws Throwable { testTSM(); } public void testTMS() throws Throwable { int topScore = randomTopScore(); verifyResults(MAX_SIGMA, randomMinimum(expectedTopScore(topScore)), topScore, 0, 0); for (int i = 0; i < NUM_TESTS; i++) { topScore = randomTopScore(); double minimum = randomMinimum(expectedTopScore(topScore)); double sigma = randomSigma(expectedMinimum(minimum)); verifyResults(sigma, minimum, topScore, expectedSigma(sigma), 2); } } public void testTMS1() throws Throwable { testTMS(); } public void testTMS2() throws Throwable { testTMS(); } public void testTMS3() throws Throwable { testTMS(); } public void testTMS4() throws Throwable { testTMS(); } public void testTMS5() throws Throwable { testTMS(); } /** * Verifies what happens when you pass these parameters * into the thing. DELTA is the amount of error allowed. * Usually DELTA is only used for Sigma, as we really can't * calculate it exactly. */ public void verifyResults(double sigma, double minimum, int topScore, int expected, int delta) { try { setUp(); if (sigma >= 0) { IUT.addProperty("sigma", Double.toString(sigma)); } if (minimum >= 0) { IUT.addProperty("minimum", Double.toString(minimum)); } if (topScore >= 0) { IUT.addProperty("topscore", Integer.toString(topScore)); } Report report = makeReport(IUT); if (delta == 0) { assertEquals("Unexpected number of results: sigma= " + Double.toString(sigma) + " min= " + Double.toString(minimum) + " topscore= " + Integer.toString(topScore), expected, report.size()); } else { String assertStr = "Unexpected number of results: sigma= " + Double.toString(sigma) + " min= " + Double.toString(minimum) + " topscore= " + Integer.toString(topScore) + " expected= " + Integer.toString(expected) + " +/- " + Integer.toString(delta) + " actual-result= " + report.size(); assertTrue(assertStr, report.size() >= (expected - delta)); assertTrue(assertStr, report.size() <= (expected + delta)); } } catch (AssertionFailedError afe) { System.err.println("******** " + testName + " ***********"); if (sigma != NO_SIGMA) { System.err.println("SIGMA: " + Double.toString(sigma) + " EXPECT: " + Integer.toString(expectedSigma(sigma))); } if (minimum != NO_MINIMUM) { System.err.println("MIN: " + Double.toString(minimum) + " EXPECT: " + Integer.toString(expectedMinimum(minimum))); } if (topScore != NO_TOPSCORE) { System.err.println("TOP: " + Integer.toString(topScore) + " EXPECT: " + Integer.toString(expectedTopScore(topScore))); } throw afe; } } public Report makeReport(Rule IUT) { List list = new ArrayList(); Report report = new Report(); RuleContext ctx = new RuleContext(); ctx.setReport(report); ctx.setSourceCodeFilename(testName); IUT.apply(list, ctx); return report; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?