commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject cvs commit: jakarta-commons-sandbox/graph2/src/test/org/apache/commons/graph/domain/dependency DependencyTest.java
Date Wed, 08 May 2002 18:15:21 GMT
ddp         02/05/08 11:15:21

  Added:       graph2/src/test/org/apache/commons/graph/domain/dependency
                        DependencyTest.java
  Log:
  Changing struture to match the source.
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/graph2/src/test/org/apache/commons/graph/domain/dependency/DependencyTest.java
  
  Index: DependencyTest.java
  ===================================================================
  package org.apache.commons.graph.domain.dependency;
  
  import java.util.Set;
  import java.util.List;
  import java.util.HashSet;
  
  import org.apache.commons.graph.*;
  import org.apache.commons.graph.dependency.exception.*;
  
  /**
   * Description of the Class
   */
  public class DependencyTest
       extends GraphTest
  {
      private DependencyGraph IUT = null;
  
      /**
       * Constructor for the DependencyTest object
       *
       * @param name
       */
      public DependencyTest(String name)
      {
          super(name);
      }
  
      /**
       * The JUnit setup method
       */
      public void setUp()
      {
          IUT = new DependencyGraph();
      }
  
      /**
       * Description of the Class
       */
      private class Task
      {
          private String name;
  
          /**
           * Constructor for the Task object
           *
           * @param name
           */
          public Task(String name)
          {
              this.name = name;
          }
  
          /**
           * Description of the Method
           */
          public String toString()
          {
              return name;
          }
      }
  
      /**
       * Description of the Field
       */
      public Task T1 = new Task("T1");
      /**
       * Description of the Field
       */
      public Task T2 = new Task("T2");
      /**
       * Description of the Field
       */
      public Task T3 = new Task("T3");
      /**
       * Description of the Field
       */
      public Task T4 = new Task("T4");
      /**
       * Description of the Field
       */
      public Task T5 = new Task("T5");
  
      /**
       * A unit test for JUnit
       */
      public void testNoDeps()
          throws Throwable
      {
          Set deps = new HashSet();
  
          IUT.addDependencies(T1, deps);
      }
  
      /**
       * A unit test for JUnit
       */
      public void testTwoTasksNoDeps()
          throws Throwable
      {
          Set deps = new HashSet();
          IUT.addDependencies(T1, deps);
          IUT.addDependencies(T2, deps);
      }
  
      /**
       * A unit test for JUnit
       */
      public void testSelfDep()
          throws Throwable
      {
          Set deps = new HashSet();
          deps.add(T1);
  
          try
          {
              IUT.addDependencies(T1, deps);
              fail("Self Dependency added without exception.");
          }
          catch (CircularDependencyException ex)
          {}
      }
  
      /**
       * A unit test for JUnit
       */
      public void testTwoCyclicDeps()
          throws Throwable
      {
          Set t1Deps = new HashSet();
          t1Deps.add(T2);
  
          Set t2Deps = new HashSet();
          t2Deps.add(T1);
  
          IUT.addDependencies(T1, t1Deps);
          try
          {
              IUT.addDependencies(T2, t2Deps);
              fail("No CircularDependencyException thrown.");
          }
          catch (CircularDependencyException ex)
          {}
      }
  
      /**
       * A unit test for JUnit
       */
      public void testThreeCyclicDeps()
          throws Throwable
      {
          Set t1Deps = new HashSet();
          t1Deps.add(T2);
  
          Set t2Deps = new HashSet();
          t2Deps.add(T3);
  
          Set t3Deps = new HashSet();
          t3Deps.add(T1);
  
          IUT.addDependencies(T1, t1Deps);
          IUT.addDependencies(T2, t2Deps);
  
          try
          {
              IUT.addDependencies(T3, t3Deps);
              fail("No CircularDependencyException Thrown.");
          }
          catch (CircularDependencyException ex)
          {}
      }
  
      /**
       * A unit test for JUnit
       */
      public void testSortedDepsEasy()
          throws Throwable
      {
          Set t1Deps = new HashSet();
          t1Deps.add(T2);
  
          Set t2Deps = new HashSet();
          t2Deps.add(T3);
  
          IUT.addDependencies(T1, t1Deps);
          IUT.addDependencies(T2, t2Deps);
          IUT.addDependencies(T3, new HashSet());
  
          // T3
          List t3SDeps =
              IUT.getSortedDependencies(T3);
          assertEquals("T3: Wrong number of Deps for T3",
              1, t3SDeps.size());
  
          assertEquals("T3: Wrong thing at pos 0",
              T3, t3SDeps.get(0));
  
          // T2
          List t2SDeps =
              IUT.getSortedDependencies(T2);
          assertEquals("T2: Wrong number of Deps for T2",
              2, t2SDeps.size());
  
          try
          {
              assertEquals("T2: Wrong thing at pos 0",
                  T3, t2SDeps.get(0));
              assertEquals("T2: Wrong thing at pos 1",
                  T2, t2SDeps.get(1));
          }
          catch (Throwable ex)
          {
              System.err.println(t2SDeps);
              throw ex;
          }
  
          // T1
          List t1SDeps =
              IUT.getSortedDependencies(T1);
          assertEquals("T1: Wrong number of Deps for T1",
              3, t1SDeps.size());
  
          assertEquals("T1: Wrong thing at pos 0",
              T3, t1SDeps.get(0));
          assertEquals("T1: Wrong thing at pos 1",
              T2, t1SDeps.get(1));
          assertEquals("T1: Wrong thing at pos 2",
              T1, t1SDeps.get(2));
  
      }
  
      /**
       * A unit test for JUnit
       */
      public void testSortedDepsHard()
      {
          Set t1Deps = new HashSet();
          t1Deps.add(T2);
          t1Deps.add(T3);
          t1Deps.add(T5);
  
          Set t2Deps = new HashSet();
          t2Deps.add(T4);
          t2Deps.add(T5);
  
          IUT.addDependencies(T1, t1Deps);
          IUT.addDependencies(T2, t2Deps);
  
          List t1SDeps = IUT.getSortedDependencies(T1);
          assertEquals("T1: Wrong number of dependents.",
              5, t1SDeps.size());
  
          List t2SDeps = IUT.getSortedDependencies(T2);
          assertEquals("T2: Wrong number of dependents.",
              3, t2SDeps.size());
  
          List t3SDeps = IUT.getSortedDependencies(T3);
          assertEquals("T1: Wrong number of dependents.",
              1, t3SDeps.size());
  
          List t4SDeps = IUT.getSortedDependencies(T4);
          assertEquals("T4: Wrong number of dependents.",
              1, t4SDeps.size());
  
          List t5SDeps = IUT.getSortedDependencies(T5);
          assertEquals("T5: Wrong number of dependents.",
              1, t5SDeps.size());
  
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message