This file contains hidden or 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
| // spec | |
| import org.specs._ | |
| object PerfectNumbersSpec extends Specification{ | |
| "Perfect Numbers" should{ | |
| "5 is not a perfect number" in { | |
| IsPerfectNumber(5) must be(false) | |
| } | |
| "6 is a perfect number" in { | |
| IsPerfectNumber(6) must be(true) |
This file contains hidden or 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 AwesomeInt(n:Int){ | |
| def !() = (1 to n).foldRight(1)(_*_) | |
| implicit def intToAwesomeInt(n:Int) = new AwesomeInt(n) | |
| } |
This file contains hidden or 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 AwesomeInt(n:Int){ | |
| def !() = (1 to n).foldRight(1)(_*_) | |
| } | |
| object Converter{ | |
| implicit def intToAwesomeInt(n:Int) = new AwesomeInt(n) | |
| } | |
| //------------ | |
| import org.specs._ | |
| import Converter._ |
This file contains hidden or 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
| import org.specs._ | |
| object PascalsTriangleSpec extends Specification{ | |
| "Pascals Triangle Generator" should{ | |
| val generator = new PascalTriangleGenerator | |
| "return a List with List(1) for 1" in { | |
| val result = generator.generate(1) | |
| result must be equalTo(List(List(1))) | |
| } |
This file contains hidden or 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
| import org.specs._ | |
| object PascalsTriangleSpec extends Specification{ | |
| "Pascals Triangle Generator" should{ | |
| val generator = new PascalTriangleGenerator | |
| "return a List with List(1) for 1" in { | |
| val result = generator.generate(1) | |
| result must be equalTo(List(List(1))) | |
| } |
This file contains hidden or 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
| @Test | |
| public void shouldBeAbleToSelectOrdersWithPriceOverCertainThreshold(){ | |
| orders.add(new Order(1, "Mallrats DVD", 9.99)); | |
| orders.add(new Order(2, "Blue Ray Player", 199.99)); | |
| orders.add(new Order(3, "Playstation 3", 299.99)); | |
| Collection<Order> expensiveOrders = orders.getOrdersAbovePrice(100.00); | |
| assertThat(expensiveOrders, hasItems( | |
| hasProperty("name", equalTo("Blue Ray Player")), |
This file contains hidden or 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
| apply plugin: 'java' | |
| apply plugin: 'eclipse' | |
| repositories{ | |
| mavenCentral() | |
| flatDir name: 'localRepository', dirs: 'lib' | |
| } | |
| dependencies{ | |
| compile 'com.google.collections:google-collections:1.0' |
This file contains hidden or 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 KeyStream(deck:Deck){ | |
| def nextChar() = 'A' | |
| } | |
| // spec | |
| describe ("Encrypting a string of text"){ | |
| val keyStream = mock[KeyStream] | |
| it("should encrypt to the expected message for 'Code in ruby, live longer!'"){ |
This file contains hidden or 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
| private def generateKeyFor(sourceMessage:String, keyStream:KeyStream) = { | |
| sourceMessage.toList.map(c => if(c == ' ') c else keyStream.nextChar()).mkString | |
| } | |
| // given a string like "ABSCD WURJD" it should read in 10 chars from the keyStream | |
| // and return them as a string with a space after each fifth char except the last |
This file contains hidden or 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 DeckSpec extends Spec with ShouldMatchers{ | |
| describe("FreshDeck"){ | |
| val deck = new Deck() | |
| it ("should have cards 1, 2, 3 as it's first cards") { | |
| deck.cardAt(0) should be(1) | |
| deck.cardAt(1) should be(2) | |
| deck.cardAt(2) should be(3) | |
| } |