commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jua...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jrcs/src/test/org/apache/commons/jrcs/diff DiffTest.java
Date Mon, 04 Aug 2003 00:04:50 GMT
juanco      2003/08/03 17:04:50

  Modified:    jrcs/src/java/org/apache/commons/jrcs/diff Diff.java
               jrcs/src/test/org/apache/commons/jrcs/diff DiffTest.java
  Log:
  BUG: Diff crashed with two empty sequences as input. Fixed, with test cases added.
  
  Revision  Changes    Path
  1.15      +5 -2      jakarta-commons-sandbox/jrcs/src/java/org/apache/commons/jrcs/diff/Diff.java
  
  Index: Diff.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jrcs/src/java/org/apache/commons/jrcs/diff/Diff.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Diff.java	10 May 2003 18:55:10 -0000	1.14
  +++ Diff.java	4 Aug 2003 00:04:50 -0000	1.15
  @@ -194,7 +194,10 @@
       public Revision diff(Object[] rev)
           throws DifferentiationFailedException
       {
  -        return algorithm.diff(orig, rev);
  +        if (orig.length == 0 && rev.length == 0)
  +            return new Revision();
  +        else
  +            return algorithm.diff(orig, rev);
       }
   
       /**
  
  
  
  1.12      +33 -1     jakarta-commons-sandbox/jrcs/src/test/org/apache/commons/jrcs/diff/DiffTest.java
  
  Index: DiffTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jrcs/src/test/org/apache/commons/jrcs/diff/DiffTest.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DiffTest.java	26 May 2003 18:14:49 -0000	1.11
  +++ DiffTest.java	4 Aug 2003 00:04:50 -0000	1.12
  @@ -62,7 +62,7 @@
   public abstract class DiffTest
       extends TestCase
   {
  -    static final int LARGE=4*1024;
  +    static final int LARGE=2*1024;
   
       protected DiffAlgorithm algorithm;
   
  @@ -122,6 +122,38 @@
           assertTrue(!Diff.compare(empty, original));
           assertTrue(Diff.compare(empty, empty));
           assertTrue(Diff.compare(original, original));
  +    }
  +
  +    public void testEmptySequences()
  +        throws DifferentiationFailedException
  +    {
  +        String[] emptyOrig = {};
  +        String[] emptyRev = {};
  +        Revision revision = Diff.diff(emptyOrig, emptyRev, algorithm);
  +
  +        assertEquals("revision size is not zero", 0, revision.size());
  +    }
  +
  +    public void testOriginalEmpty()
  +        throws DifferentiationFailedException
  +    {
  +        String[] emptyOrig = {};
  +        String[] rev = {"1", "2", "3"};
  +        Revision revision = Diff.diff(emptyOrig, rev, algorithm);
  +
  +        assertEquals("revision size should be one", 1, revision.size());
  +        assertTrue(revision.getDelta(0) instanceof AddDelta);
  +    }
  +
  +    public void testRevisedEmpty()
  +        throws DifferentiationFailedException
  +    {
  +        String[] orig = {"1", "2", "3"};
  +        String[] emptyRev = {};
  +        Revision revision = Diff.diff(orig, emptyRev, algorithm);
  +
  +        assertEquals("revision size should be one", 1, revision.size());
  +        assertTrue(revision.getDelta(0) instanceof DeleteDelta);
       }
   
       public void testDeleteAll()
  
  
  

Mime
View raw message