Created
October 24, 2012 19:32
-
-
Save jonatasemidio/3948286 to your computer and use it in GitHub Desktop.
FizzBuzz para Dojo Groovy! Caso fuja da memoria...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Segue outros asserts que tambem podem ser utilizados nos testes unitarios do groovy. | |
void assertArrayEquals(Object[]expected, Object[] value) //Compares the contents and length of each array void assertLength(int length, char[] array) Convenience method for asserting the length of an array | |
void assertLength(int length,int[] array) //Convenience method for asserting the length of an array | |
void assertLength(int length,Object[] array) //Convenience method for asserting the length of an array | |
void assertContains(char expected,char[] array) //Verifies that a given array of chars contains an expected value | |
void assertContains(int expected,int[] array) //Verifies that a given array of ints contains an expected value | |
void assertToString(Object value,String expected) //Invokes the toString method on the provided object and compares the result with the expected string | |
void assertInspect(Object value,String expected) //Similar to the assertToString method, except that it calls the inspect method | |
void assertScript(final String script)// Attempts to run the provided script | |
void shouldFail(Closure code)// Verifies that the closure provided fails | |
void shouldFail(Class clazz,Closure code) //Verifies that the closure provided throws an exception of type clazz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FizzBuzz{ | |
def exec(n){ | |
return n%15==0 ? 'fizzbuzz' : n%3 == 0 ? 'fizz' : n%5 == 0 ? 'buzz' : 'Sem FizzBuzz' | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SimpleUnitTest extends GroovyTestCase{ | |
private fizzbuzz | |
void setUp(){ | |
fizzbuzz = new FizzBuzz() | |
} | |
void testFizz(){ | |
assertEquals("Nao multiplo de tres!", "fizz", fizzbuzz.exec(3)) | |
} | |
void testBuzz(){ | |
assertEquals("Nao multiplo de tres!", "buzz", fizzbuzz.exec(5)) | |
} | |
void testFizzBuzz(){ | |
assertEquals("Nao multiplo de tres!", "fizzbuzz", fizzbuzz.exec(15)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment