CyberArmy University | Open Source Institute | CyberArmy Intelligence & Security | CyberArmy Services & Projects

The 2005 CyberArmy Pig Latin Contest! ;)


[Replies] [Reply] [View by Thread] [Help]
[Back To SNEAK Development Forum]

Posted by CinC snarkles On 2005-04-05 15:57:41

CinC
CinC snarkles


I'm in the process of doing this one myself but it's looking pretty sketchy really fast. ;) So I figured I'd post this here as a little "challenge" for folks, in case someone can do it faster/cleaner than I can (which is a very distinct possibility ;)).

YOUR MISSION, should you choose to accept it, is to make the PigLatinCipher class. (Wtf is Pig Latin?) Here, I'll even give you a template to get you started:
package net.cyberarmy.sneak.algorithm;

import net.cyberarmy.sneak.algorithm.template.AlgorithmException;
import net.cyberarmy.sneak.algorithm.template.Cipher;

/**
 * An implementation of <code>Cipher</code> that translates input
 * to Pig Latin (see: http://en.wikipedia.org/wiki/Pig_latin)
 * <br><br>
 * <i>foobar</i> becomes <i>oobarfay</i><br>
 * <i>onion</i> becomes <i>onionway</i><br>
 * <i>strawberry</i> becomes <i>awberrystray</i>
 *
 * @author yournamehere
 * @since 05.04.2005
 */
public class PigLatinCipher extends Cipher {
    /**
     * Translates given input data to Pig Latin.
     *
     * @param input The input data to translate.
     * @return The translated input data.
     */
    public String execute(String input) throws AlgorithmException {
        if (input == null) {
            throw new AlgorithmException("The input may not be null!",
                new IllegalArgumentException());
        }

        // YOUR CODE HERE

    }

    /**
     * Translates given input data from Pig Latin.
     *
     * @param input The input data to translate.
     * @return The translated input data.
     */
    public String reverse(String input) throws AlgorithmException {
        if (input == null) {
            throw new AlgorithmException("The input may not be null!",
                new IllegalArgumentException());
        }

       // YOUR CODE HERE

    }
}
The catch??

All of these unit tests must pass! Mwahahahahahahaaa!
package net.cyberarmy.sneak.junit.tests;

import junit.framework.TestCase;
import net.cyberarmy.sneak.algorithm.PigLatinCipher;

/**
 * Pig Latin test cases
 *
 * @author snarkles
 * @since 05.04.2005
 */
public class PigLatinCipherTest extends TestCase {
	private PigLatinCipher pigLatin;
	
	public PigLatinCipherTest(String name) {
            super(name);
        }
	
	protected void setUp() {
		pigLatin = new PigLatinCipher();
	}
	
	// Execute method
	public void testSimple() throws Exception {
	    assertEquals("allbay", pigLatin.execute("ball"));
	}

	public void testStartsWithVowel() throws Exception {
	    assertEquals("isway", pigLatin.execute("is"));
	}

	public void testStartsWithConsonants() throws Exception {
	    assertEquals("eethray", pigLatin.execute("three"));
	}
	
	public void testStartsWithQu() throws Exception {
		assertEquals("estionquay", pigLatin.execute("question"));
	}
	
	public void testInitialWeirdVowel() throws Exception {
		assertEquals("ylophonexay", pigLatin.execute("xylophone"));
	}
	
	public void testStartsWithCapitalQu() throws Exception {
		assertEquals("estionquay", pigLatin.execute("QUestion"));
	}

	public void testInitialCaps() throws Exception {
		assertEquals("Igpay Atinlay", pigLatin.execute("Pig Latin"));		
	}
	
	public void testAllCaps() throws Exception {
		assertEquals("IGPAY ATINLAY", pigLatin.execute("PIG LATIN"));
	}
	
	public void testHyphenated() throws Exception {
		assertEquals("outhsay-estway", pigLatin.execute("south-west"));
	}
	
	public void testContraction() throws Exception {
		assertEquals("on'tday", pigLatin.execute("don't"));
	}
	
	public void testInvalid() throws Exception {
		assertEquals("*&^@#45", pigLatin.execute("*&^@#45"));
	}
	
	// Reverse method
	public void testReverseSimple() throws Exception {
	    assertEquals("ball", pigLatin.reverse("allbay"));
	}

	public void testReverseStartsWithVowel() throws Exception {
	    assertEquals("is", pigLatin.reverse("isway"));
	}

	public void testReverseStartsWithConsonants() throws Exception {
	    assertEquals("three", pigLatin.reverse("eethray"));
	}
	
	public void testReverseStartsWithQu() throws Exception {
		assertEquals("question", pigLatin.reverse("estionquay"));
	}
	
	public void testReverseInitialWeirdVowel() throws Exception {
		assertEquals("xylophone", pigLatin.reverse("ylophonexay"));
	}
	
	public void testReverseInitialCaps() throws Exception {
		assertEquals("Pig Latin", pigLatin.reverse("Igpay Atinlay"));		
	}
	
	public void testReverseAllCaps() throws Exception {
		assertEquals("PIG LATIN", pigLatin.reverse("IGPAY ATINLAY"));
	}
	
	public void testReverseHyphenated() throws Exception {
		assertEquals("south-west", pigLatin.reverse("outhsay-estway"));
	}
	
	public void testReverseContraction() throws Exception {
		assertEquals("don't", pigLatin.reverse("on'tday"));
	}
	
	public void testReverseInvalid() throws Exception {
		assertEquals("*&^@#45", pigLatin.reverse("*&^@#45"));
	}
}
...and any other random ones that people can think of. ;P

How to get started?

If you have troubles with any of the below, check out the Developer's Guide, or post back here with any questions.

1. First of all, use Subversion checkout the source.

2. Save the above two chunks of code as:

#1: PigLatinCipher.java in (wherever the source was checked out)/trunk/desktop/src/java/net/cyberarmy/sneak/algorithm/

#2: PigLatinCipherTest.java in (wherever the source was checked out)/trunk/desktop/src/junit.tests/net/cyberarmy/sneak/junit/tests/

3. Code away until all of the unit tests in PigLatinCipherTest pass! (aka the Ant build runs properly)

Regexes will likely be your friend here: see the docs on java.util.regex

Post submissions as a reply to this thread. Winners will be based on:
  1. How easy is your code to understand?
  2. How well does it perform?
  3. Random "mysterious" criteria that may be revealed to you... in time... Ooooo...
This challenge is mostly for the challenge, so no rank perks, privileges or anything like that... but if you win, I'll make you a goofy picture you can use in your sig or something. :P

Note too that these should be original code submissions, and that any submissions here may be crufted together to use in the final version for SNEAK (with proper credit given, of course). So make sure you're comfortable with your code being released under the GPL.

I'll arbitrarily set a contest end date of May 01, 2005, which gives folks about a month to participate.

Avehay Unfay! ;)



Replies:


Guest:
Subject:
Message:
Signature:
Optional Image Link:
http://

CyberArmy::Forum v0.6
Generated In 0.01351 seconds


About Us | Privacy Policy | Mission Statement | Help