コード例 #1
0
 /**
  * Test the method, returns the sum of all differences between the required and obtained excange
  * amount. One exception counts as 1000 on the error score.
  */
 public int test() {
   int s = 0;
   int e;
   for (int amount = 20; amount < 100; amount++) {
     try {
       if (REPORT_ENABLED) {
         System.out.println("EXCHANGING " + amount + " ");
       }
       // Do not solve cases without solutions
       if (EXISTING_SOLUTIONS_ONLY) {
         if (!Force.solve(amount)) {
           continue;
         }
       }
       // Need to reset the configuration because it needs to be changed each
       // time when looping.
       // -------------------------------------------------------------------
       DefaultConfiguration.reset();
       e = makeChangeForAmount(amount);
       if (REPORT_ENABLED) {
         System.out.println(" err " + e);
         System.out.println("---------------");
       }
       s = s + e;
     } catch (Exception ex) {
       ex.printStackTrace();
       s += 1000;
     }
   }
   if (REPORT_ENABLED) {
     System.out.println("Sum of errors " + s);
   }
   return s;
 }
コード例 #2
0
  @Test
  public void testAcceptableTokens() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class);
    checkConfig.addAttribute("tokens", "VARIABLE_DEF, ENUM_DEF, CLASS_DEF, METHOD_DEF," + "IMPORT");
    final String[] expected = {};

    try {
      verify(checkConfig, getPath("InputHiddenField.java"), expected);
      Assert.fail();
    } catch (CheckstyleException e) {
      String errorMsg = e.getMessage();
      Assert.assertTrue(
          errorMsg.contains(
              "cannot initialize module"
                  + " com.puppycrawl.tools.checkstyle.TreeWalker - Token \"IMPORT\""
                  + " was not found in Acceptable tokens list in check"
                  + " com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheck"));
    }
  }
コード例 #3
0
 public Configuration detachedConfiguration(Dependency... dependencies) {
   DetachedConfigurationsProvider detachedConfigurationsProvider =
       new DetachedConfigurationsProvider();
   String name = DETACHED_CONFIGURATION_DEFAULT_NAME + detachedConfigurationDefaultNameCounter++;
   DefaultConfiguration detachedConfiguration =
       new DefaultConfiguration(
           name,
           name,
           detachedConfigurationsProvider,
           dependencyResolver,
           listenerManager,
           dependencyMetaDataProvider,
           new DefaultResolutionStrategy());
   DomainObjectSet<Dependency> detachedDependencies = detachedConfiguration.getDependencies();
   for (Dependency dependency : dependencies) {
     detachedDependencies.add(dependency.copy());
   }
   detachedConfigurationsProvider.setTheOnlyConfiguration(detachedConfiguration);
   return detachedConfiguration;
 }
コード例 #4
0
  @Test
  public void testCacheFile() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class);

    final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class);
    treeWalkerConfig.addAttribute("cacheFile", temporaryFolder.newFile().getPath());
    treeWalkerConfig.addChild(checkConfig);

    final DefaultConfiguration checkerConfig = new DefaultConfiguration("configuration");
    checkerConfig.addAttribute("charset", "UTF-8");
    checkerConfig.addChild(treeWalkerConfig);

    final Checker checker = new Checker();
    final Locale locale = Locale.ROOT;
    checker.setLocaleCountry(locale.getCountry());
    checker.setLocaleLanguage(locale.getLanguage());
    checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    checker.configure(checkerConfig);
    checker.addListener(new BriefLogger(stream));

    final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath();
    final String[] expected = {};

    verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
    // one more time to reuse cache
    verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
  }
コード例 #5
0
ファイル: TreeWalkerTest.java プロジェクト: sabaka/checkstyle
  @Test
  public void testAcceptableTokens() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class);
    checkConfig.addAttribute("tokens", "VARIABLE_DEF, ENUM_DEF, CLASS_DEF, METHOD_DEF," + "IMPORT");
    try {
      final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
      verify(checkConfig, getPath("InputMain.java"), expected);
      fail("CheckstyleException is expected");
    } catch (CheckstyleException ex) {
      final String errorMsg = ex.getMessage();
      final Pattern expected =
          Pattern.compile(
              Pattern.quote(
                      "cannot initialize module"
                          + " com.puppycrawl.tools.checkstyle.TreeWalker - Token ")
                  + "\"(ENUM_DEF|CLASS_DEF|METHOD_DEF|IMPORT)\""
                  + Pattern.quote(
                      " was not found in Acceptable tokens list in check"
                          + " com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheck"));

      final Matcher errorMsgMatcher = expected.matcher(errorMsg);
      assertTrue("Failure for: " + errorMsg, errorMsgMatcher.matches());
    }
  }
コード例 #6
0
 @Test
 public void testRemoveChild() {
   DefaultConfiguration config = new DefaultConfiguration("MyConfig");
   DefaultConfiguration configChild = new DefaultConfiguration("childConfig");
   assertEquals(0, config.getChildren().length);
   config.addChild(configChild);
   assertEquals(1, config.getChildren().length);
   config.removeChild(configChild);
   assertEquals(0, config.getChildren().length);
 }
コード例 #7
0
  protected void setUp() throws Exception {

    super.setUp();
    configuration = DefaultConfiguration.getConfiguration();
  }
コード例 #8
0
 public static synchronized DefaultConfiguration getDefaultConfiguration() {
   return DefaultConfiguration.getInstance();
 }