Version Control - Subversion Project Work

Passing

Submit SVN-project and Git project work work by 18.10.2009 23:59.

Help! I'm stuck!

SVN

Read the instructions carefully, try creating a new repository and starting again.

Git

Git is considerably harder to pass, and it is not required. However, you should write short e-mail to matti.paksula@cs.helsinki.fi (finnish/english) with following content:

See results: results (updated every 10 minutes). If your student number is not on the list, please contact matti.paksula@cs.helsinki.fi


Steps

  1. Create a repository with Create-A-Repo. Checkout your working copy. If you want to start again, you can just create a new repository.
  2. Add these new files to the trunk/ directory in your working copy:
    src/main/java/longcat/CliArgumentParser.java
    src/main/java/longcat/LengthUnit.java
    src/main/java/longcat/LongcatFactoryImpl.java
    src/test/java/longcat/CliArgumentParserTest.java

    Make following changes in the following (already existing) files:
    src/main/java/longcat/LongcatFactory.java

    --- a/src/main/java/longcat/LongcatFactory.java
    +++ b/src/main/java/longcat/LongcatFactory.java
    @@ -1,8 +1,8 @@
     package longcat;
     
    -public class LongcatFactory {
    +public interface LongcatFactory {
     
    -    public Longcat createLongcat(int bodySize) {
    -        return new Longcat(bodySize);
    -    }
    +    Longcat createLongcat(int bodySize);
    +
    +    Longcat createLongcat(int length, LengthUnit unit);
     }
    

    src/test/java/longcat/LongcatFactoryTest.java
    --- a/src/test/java/longcat/LongcatFactoryTest.java
    +++ b/src/test/java/longcat/LongcatFactoryTest.java
    @@ -4,7 +4,7 @@ import junit.framework.TestCase;
     
     public class LongcatFactoryTest extends TestCase {
     
    -    private LongcatFactory factory = new LongcatFactory();
    +    private LongcatFactory factory = new LongcatFactoryImpl();
     
         public void test__Longcat_with_body_size_0() {
             Longcat longcat = factory.createLongcat(0);
    

    Commit the added and modified files with the following comment: "Command line argument parsing"

  3. If everything was correct, the Robot will make a commit after yours with the message: "Command line interface".

    Update your working copy to be up-to-date with the Robot.

  4. Add this file to your working copy:
    src/test/java/longcat/LengthUnitTest.java

    Make these changes:
    src/main/java/longcat/LengthUnit.java

    --- a/src/main/java/longcat/LengthUnit.java
    +++ b/src/main/java/longcat/LengthUnit.java
    @@ -2,12 +2,14 @@ package longcat;
     
     public enum LengthUnit {
     
    -    METERS("m"), FEET("ft"), PETRONAS("petronas");
    +    METERS("m", 1.0), FEET("ft", 0.3048), PETRONAS("petronas", 451.9);
     
         private final String name;
    +    private final double lengthInMeters;
     
    -    private LengthUnit(String name) {
    +    private LengthUnit(String name, double lengthInMeters) {
             this.name = name;
    +        this.lengthInMeters = lengthInMeters;
         }
     
         public static LengthUnit parse(String name) {
    @@ -18,4 +20,8 @@ public enum LengthUnit {
             }
             throw new IllegalArgumentException("No such unit of length: " + name);
         }
    +
    +    public int from(int length, LengthUnit unit) {
    +        return (int) (length * unit.lengthInMeters / this.lengthInMeters);
    +    }
     }
    
  5. Commit the changes with the following comment: "Length unit conversions"

    Commit will fail because the Robot made two commits just before yours: "Optimized: use StringBuilder to construct the longcat body, as it can be very loooooooooong" and "Refactored: renamed constants".

    Update your working copy to match our new (and improved) StringBuilder implementation.

    Commit again with the same commit message: "Length unit conversions"

    Everything should be okay now.

  6. It should be possible to specify the Longcat length with natural length units, such as Petronas Towers. Make the following changes to trunk:
    src/main/java/longcat/LengthUnit.java
    --- a/src/main/java/longcat/LengthUnit.java
    +++ b/src/main/java/longcat/LengthUnit.java
    @@ -2,7 +2,7 @@ package longcat;
     
     public enum LengthUnit {
     
    -    METERS("m", 1.0), FEET("ft", 0.3048), PETRONAS("petronas", 451.9);
    +    METERS("m", 1.0), FEET("ft", 0.3048), PETRONAS("petronas", 451.9), LINES("lines", 0.009);
     
         private final String name;
         private final double lengthInMeters;
    

    src/main/java/longcat/Longcat.java
    --- a/src/main/java/longcat/Longcat.java
    +++ b/src/main/java/longcat/Longcat.java
    @@ -27,11 +27,14 @@ public class Longcat {
         private final int bodySize;
     
         public Longcat(int bodySize) {
    +        if (bodySize < 0) {
    +            throw new IllegalArgumentException("Longcat can not be that short!");
    +        }
             this.bodySize = bodySize;
         }
     
         public String getBody() {
    -        StringBuilder body = new StringBuilder();
    +        StringBuilder body = new StringBuilder(bodySize * BODY_LINE.length());
             for (int i = 0; i < bodySize; i++) {
                 body.append(BODY_LINE);
             }
    

    src/main/java/longcat/LongcatFactoryImpl.java
    --- a/src/main/java/longcat/LongcatFactoryImpl.java
    +++ b/src/main/java/longcat/LongcatFactoryImpl.java
    @@ -7,6 +7,19 @@ public class LongcatFactoryImpl implements LongcatFactory {
         }
     
         public Longcat createLongcat(int length, LengthUnit unit) {
    -        return null;
    +        int totalLines = LengthUnit.LINES.from(length, unit);
    +        int nonBodyLines = lineCount(Longcat.HEAD_LINES + Longcat.FEET_LINES);
    +        return new Longcat(totalLines - nonBodyLines);
    +    }
    +
    +    static int lineCount(String s) {
    +        int lines = 0;
    +        for (int i = 0; i < s.length(); i++) {
    +            char c = s.charAt(i);
    +            if (c == '\n') {
    +                lines++;
    +            }
    +        }
    +        return lines;
         }
     }
    

    src/test/java/longcat/LongcatFactoryTest.java
    --- a/src/test/java/longcat/LongcatFactoryTest.java
    +++ b/src/test/java/longcat/LongcatFactoryTest.java
    @@ -25,4 +25,19 @@ public class LongcatFactoryTest extends TestCase {
             Longcat longcat = factory.createLongcat(2);
             assertEquals(Longcat.HEAD_LINES + longcat.getBody() + Longcat.FEET_LINES, longcat.toString());
         }
    +
    +    public void test__Longcat_length_specified_in_meters() {
    +        Longcat longcat = factory.createLongcat(1, LengthUnit.METERS);
    +        int lines = LongcatFactoryImpl.lineCount(longcat.toString());
    +        assertEquals(LengthUnit.LINES.from(1, LengthUnit.METERS), lines);
    +    }
    +
    +    public void test__Too_short_longcat() {
    +        try {
    +            factory.createLongcat(0, LengthUnit.METERS);
    +            fail();
    +        } catch (IllegalArgumentException e) {
    +            assertEquals("Longcat can not be that short!", e.getMessage());
    +        }
    +    }
     }
    
  7. Commit the changes with message: "Specifying Longcat length with natural length units"

    Sadly, the commit will fail. The Robot decided to add one more useful length unit just before your commit. Update your working copy. You'll see that it gets even worse, because the changes in your working copy conflict with that addition.

    Resolve all conflicts and remember to mark everything resolved.

    Commit the new merged and conflict free changeset to the repository with the same commit message: "Specifying Longcat length with natural length units"

    If everything went right, the Robot will do after you a series of commits, of which the last one is "Release 1.0". You can verify this by updating your working copy and using the svn log command to see the latest commit:

    	------------------------------------------------------------------------
    	r14 | robottiruttunen | 2009-09-29 14:43:55 +0300 (Ti, 29 Syy 2009) | 1 line
    
    	Release 1.0
    

    If you got this far, you have finished the project work and you may spend the rest of the evening relaxing by listening to music. :-) Also remember to do the Git project work.