Esempio n. 1
0
 public static void main(String[] args) {
   Test t = new Test();
   try {
     t.test();
   } catch (Throwable e) {
     if (t.l != 5) {
       System.out.println("Fails: " + t.l + " != 5");
     }
   }
 }
Esempio n. 2
0
 public static void main(String args[]) {
   try {
     Test t = new Test();
     t.init();
     t.test();
     System.out.println("Passed");
   } catch (Exception e) {
     e.printStackTrace();
     System.out.println("Failed");
   }
 }
Esempio n. 3
0
  /**
   * Runs all currently added Tests and returns result
   *
   * @param subject Object to test
   * @return test result
   */
  public boolean test(T subject) {

    boolean allPassed = true;

    for (Test<T> tester : this.tests) {
      if (!tester.test(subject)) {
        allPassed = false;
      }
    }

    return allPassed;
  }
Esempio n. 4
0
 // Run the tests for this container:
 public void timedTest() {
   displayHeader();
   for (TestParam param : paramList) {
     System.out.format(sizeField, param.size);
     for (Test<C> test : tests) {
       C kontainer = initialize(param.size);
       long start = System.nanoTime();
       // Call the overriden method:
       int reps = test.test(kontainer, param);
       long duration = System.nanoTime() - start;
       long timePerRep = duration / reps; // Nanoseconds
       System.out.format(numberField(), timePerRep);
     }
     System.out.println();
   }
 }
  protected void doTest(final Test test) {
    assert myFile != null : "configure first";

    final VirtualFile vFile = myFile.getVirtualFile();
    assert vFile != null : "no virtual file for " + myFile;

    final FileEditor fileEditor =
        FileEditorManager.getInstance(getProject()).getSelectedEditor(vFile);
    assert fileEditor != null : "editor not opened for " + vFile;

    final StructureViewBuilder builder =
        LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(myFile);
    assert builder != null : "no builder for " + myFile;

    StructureViewComponent component = null;
    try {
      component = (StructureViewComponent) builder.createStructureView(fileEditor, myProject);
      test.test(component);
    } finally {
      if (component != null) Disposer.dispose(component);
    }
  }
Esempio n. 6
0
File: Test.java Progetto: schuay/oop
  /**
   * Main entry point of the testing suite.
   *
   * @param args command line arguments
   */
  public static void main(String[] args) throws Exception {

    try {

      VerschenknixAG v;
      TestResult testresult;
      VerschenknixAG.Config config;

      config = new VerschenknixAG.Config();
      testresult = new TestResult(5, 25, 25, 24, 0, 0, 1, 24);
      v = new VerschenknixAG(config);
      test(
          "Testing standard configuration, expecting one tree left in quarry",
          true,
          testSimulation(v, testresult));

      v = new VerschenknixAG(config);
      test("Testing if same result with same configuration", true, testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.hunter1Count = 3;
      testresult = new TestResult(6, 30, 30, 30, 0, 0, 0, 30);
      v = new VerschenknixAG(config);
      test("Testing configuration, all trees delivered", true, testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.hunter1Count = 1;
      config.hunter2Count = 1;
      v = new VerschenknixAG(config);
      testresult = new TestResult(2, 10, 10, 10, 0, 0, 0, 10);
      test("Testing with 1 hunt per hunter", true, testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.coldStorageCapacity = 1;
      testresult = new TestResult(5, 25, 25, 24, 0, 0, 1, 24);
      v = new VerschenknixAG(config);
      test(
          "Testing configuration with cold storage capacity 1",
          true,
          testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.lumberjack1Duration = 5;
      config.lumberjack2Duration = 5;
      config.lumberjack3Duration = 5;
      config.lumberjack4Duration = 5;
      config.lumberjack5Duration = 5;
      testresult = new TestResult(5, 25, 25, 24, 0, 0, 1, 24);
      v = new VerschenknixAG(config);
      test(
          "Testing configuration with all Lumberjacks needing the same time",
          true,
          testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.lumberjack1Duration = 1;
      config.lumberjack2Duration = 1;
      config.lumberjack3Duration = 1;
      config.lumberjack4Duration = 1;
      config.lumberjack5Duration = 1;
      config.cookDuration = 1;
      config.logistician1Duration = 1;
      config.logistician2Duration = 1;
      config.hunter1Duration = 1;
      config.hunter2Duration = 1;
      testresult = new TestResult(5, 25, 25, 24, 0, 0, 1, 24);
      v = new VerschenknixAG(config);
      test(
          "Testing configuration with all workers needing the minimum time",
          true,
          testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.lumberjack1Duration = 1;
      config.lumberjack2Duration = 1;
      config.lumberjack3Duration = 1;
      config.lumberjack4Duration = 1;
      config.lumberjack5Duration = 1;
      config.cookDuration = 1;
      config.logistician1Duration = 1;
      config.logistician2Duration = 1;
      config.hunter1Duration = 50;
      config.hunter2Duration = 50;
      testresult = new TestResult(5, 25, 25, 24, 0, 0, 1, 24);
      v = new VerschenknixAG(config);
      test(
          "Testing configuration with slow hunters and fast other workers",
          true,
          testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.lumberjack1Duration = 1;
      config.lumberjack2Duration = 1;
      config.lumberjack3Duration = 1;
      config.lumberjack4Duration = 1;
      config.lumberjack5Duration = 1;
      config.cookDuration = 50;
      config.logistician1Duration = 1;
      config.logistician2Duration = 1;
      config.hunter1Duration = 1;
      config.hunter2Duration = 1;
      testresult = new TestResult(5, 25, 25, 24, 0, 0, 1, 24);
      v = new VerschenknixAG(config);
      test("Testing configuration with slow cook", true, testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.coldStorageCapacity = 50;
      config.quarryCapacity = 50;
      config.tableCapacity = 50;
      testresult = new TestResult(5, 25, 25, 24, 0, 0, 1, 24);
      v = new VerschenknixAG(config);
      test(
          "Testing configuration with large storage capacity", true, testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.logistician1Duration = 50;
      config.logistician2Duration = 50;
      config.quarryCapacity = 2;
      testresult = new TestResult(5, 25, 25, 24, 0, 0, 1, 24);
      v = new VerschenknixAG(config);
      test(
          "Testing configuration with small quarry capacity and slow logisticians",
          true,
          testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.logistician1Duration = 1;
      config.logistician2Duration = 1;
      config.quarryCapacity = 2;
      testresult = new TestResult(5, 25, 25, 24, 0, 0, 1, 24);
      v = new VerschenknixAG(config);
      test(
          "Testing configuration with small quarry capacity and fast logisticians",
          true,
          testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.cookDuration = 40;
      config.hunter1Duration = 1;
      config.hunter2Duration = 1;
      testresult = new TestResult(5, 25, 25, 24, 0, 0, 1, 24);
      v = new VerschenknixAG(config);
      test(
          "Testing configuration with fast hunters and slow cook",
          true,
          testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.cookDuration = 40;
      config.hunter1Duration = 1;
      config.hunter2Duration = 1;
      config.coldStorageCapacity = 1;
      testresult = new TestResult(5, 25, 25, 24, 0, 0, 1, 24);
      v = new VerschenknixAG(config);
      test(
          "Testing configuration with fast hunters and slow cook and small cold storage capacity",
          true,
          testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.cookDuration = 1;
      config.hunter1Duration = 40;
      config.hunter2Duration = 40;
      testresult = new TestResult(5, 25, 25, 24, 0, 0, 1, 24);
      v = new VerschenknixAG(config);
      test(
          "Testing configuration with slow hunters and fast cook",
          true,
          testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.hunter1Count = 20;
      config.hunter2Count = 30;
      config.hunter1Duration = 3;
      config.hunter2Duration = 4;
      config.cookDuration = 4;
      config.lumberjack1Duration = 3;
      config.lumberjack2Duration = 4;
      config.lumberjack3Duration = 5;
      config.lumberjack4Duration = 6;
      config.lumberjack5Duration = 7;
      config.logistician1Duration = 3;
      config.logistician2Duration = 4;
      config.coldStorageCapacity = 1;
      config.tableCapacity = 5;
      config.quarryCapacity = 2;
      testresult = new TestResult(50, 250, 250, 250, 0, 0, 0, 250);
      v = new VerschenknixAG(config);
      test(
          "Testing configuration with rather fast workers, low capacity and lots of work",
          true,
          testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.hunter1Count = 20;
      config.hunter2Count = 30;
      config.hunter1Duration = 3;
      config.hunter2Duration = 4;
      config.cookDuration = 4;
      config.lumberjack1Duration = 3;
      config.lumberjack2Duration = 4;
      config.lumberjack3Duration = 5;
      config.lumberjack4Duration = 6;
      config.lumberjack5Duration = 7;
      config.logistician1Duration = 3;
      config.logistician2Duration = 4;
      config.coldStorageCapacity = 30;
      config.tableCapacity = 30;
      config.quarryCapacity = 30;
      testresult = new TestResult(50, 250, 250, 250, 0, 0, 0, 250);
      v = new VerschenknixAG(config);
      test(
          "Testing configuration with rather fast workers, high capacity and lots of work",
          true,
          testSimulation(v, testresult));

      config = new VerschenknixAG.Config();
      config.hunter1Duration = 100;
      config.hunter2Duration = 100;
      v = new VerschenknixAG(config);
      test("Testing abort before hunters can finish", true, testAbort(v));

      config = new VerschenknixAG.Config();
      config.hunter1Count = 1;
      config.hunter2Count = 1;
      config.hunter1Duration = 1;
      config.hunter2Duration = 1;
      config.cookDuration = 100;
      v = new VerschenknixAG(config);
      test("Testing abort before cook can finish", true, testAbort(v));

      config = new VerschenknixAG.Config();
      config.hunter1Duration = 1;
      config.hunter2Duration = 1;
      config.hunter1Count = 1;
      config.hunter2Count = 1;
      config.cookDuration = 1;
      config.lumberjack1Duration = 100;
      config.lumberjack2Duration = 100;
      config.lumberjack3Duration = 100;
      config.lumberjack4Duration = 100;
      config.lumberjack5Duration = 100;
      config.coldStorageCapacity = 50;
      config.tableCapacity = 50;
      config.quarryCapacity = 50;
      v = new VerschenknixAG(config);
      test("Testing abort before lumberjacks can finish", true, testAbort(v));

      config = new VerschenknixAG.Config();
      config.hunter1Duration = 1;
      config.hunter2Duration = 1;
      config.cookDuration = 1;
      config.hunter1Count = 1;
      config.hunter2Count = 1;
      config.lumberjack1Duration = 1;
      config.lumberjack2Duration = 1;
      config.lumberjack3Duration = 1;
      config.lumberjack4Duration = 1;
      config.lumberjack5Duration = 1;
      config.coldStorageCapacity = 50;
      config.tableCapacity = 50;
      config.quarryCapacity = 50;
      config.logistician1Duration = 100;
      config.logistician2Duration = 100;
      v = new VerschenknixAG(config);
      test("Testing abort before logisticians can finish", true, testAbort(v));

      printSummary();
    } catch (Exception e) {
      e.printStackTrace();
      System.out.printf(
          "%n%nUnexpected exception thrown after %d tests; testing aborted!%n", testCount);
    }
  }