Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/phoenixst/plexus/examples/CompleteBipartiteGraphTest.java


1   /*
2    *  $Id: CompleteBipartiteGraphTest.java,v 1.8 2003/10/10 21:45:28 rconner Exp $
3    *
4    *  Copyright (C) 1994-2003 by Phoenix Software Technologists,
5    *  Inc. and others.  All rights reserved.
6    *
7    *  THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE
8    *  COMMON PUBLIC LICENSE ("AGREEMENT") WHICH ACCOMPANIES IT.  ANY
9    *  USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
10   *  RECIPIENT'S ACCEPTANCE OF THE AGREEMENT.
11   *
12   *  The license text can also be found at
13   *    http://opensource.org/licenses/cpl.php
14   */
15  
16  package com.phoenixst.plexus.examples;
17  
18  import junit.framework.*;
19  
20  import org.apache.commons.collections.Predicate;
21  
22  import com.phoenixst.plexus.*;
23  
24  
25  /**
26   *  A {@link CompleteBipartiteGraph} tester.
27   *
28   *  @version    $Revision: 1.8 $
29   *  @author     Ray A. Conner
30   *
31   *  @since      1.0
32   */
33  public class CompleteBipartiteGraphTest extends GraphTest
34  {
35  
36      private static class TestPredicate
37          implements Predicate
38      {
39          int m;
40          int n;
41  
42          public TestPredicate( int m, int n )
43          {
44              this.m = m;
45              this.n = n;
46          }
47  
48          public boolean evaluate( Object object )
49          {
50              Graph.Edge edge = (Graph.Edge) object;
51              int tail = ((Integer) edge.getTail()).intValue();
52              int head = ((Integer) edge.getHead()).intValue();
53              return (tail < m && m <= head)
54                  || (head < m && m <= tail);
55          }
56      }
57  
58  
59      private int m;
60      private int n;
61  
62  
63      public CompleteBipartiteGraphTest( int m, int n )
64      {
65          this.m = m;
66          this.n = n;
67      }
68  
69  
70      protected void setUp()
71      {
72          setUp( new CompleteBipartiteGraph( m, n ) );
73          createPresentNodeRanges( m + n );
74          createEdgeArrays( m + n, new TestPredicate( m, n ) );
75      }
76  
77  
78      private static Test suite( int m, int n )
79      {
80          return new CompleteBipartiteGraphTest( m, n ).getInstanceSuite( "Bipartite[" + m + "," + n + "]" );
81      }
82  
83  
84      public static Test suite()
85      {
86          TestSuite suite = new TestSuite( "CompleteBipartiteGraph Tests" );
87          suite.addTest( suite( 0, 0 ) );
88          suite.addTest( suite( 0, 1 ) );
89          suite.addTest( suite( 1, 0 ) );
90          suite.addTest( suite( 0, 5 ) );
91          suite.addTest( suite( 5, 0 ) );
92          suite.addTest( suite( 1, 5 ) );
93          suite.addTest( suite( 5, 1 ) );
94          suite.addTest( suite( 2, 3 ) );
95          return suite;
96      }
97  
98  
99      public static void main( String[] args )
100     {
101         junit.textui.TestRunner.run( suite() );
102     }
103 
104 }