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
| package monopoly.game; | |
| import static org.hamcrest.CoreMatchers.allOf; | |
| import static org.hamcrest.CoreMatchers.equalTo; | |
| import static org.hamcrest.Matchers.greaterThanOrEqualTo; | |
| import static org.hamcrest.Matchers.lessThanOrEqualTo; | |
| import static org.junit.Assert.assertThat; | |
| import java.util.HashSet; | |
| import java.util.Set; |
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
| package monopoly.game; | |
| import static org.hamcrest.CoreMatchers.allOf; | |
| import static org.hamcrest.CoreMatchers.equalTo; | |
| import static org.hamcrest.Matchers.greaterThanOrEqualTo; | |
| import static org.hamcrest.Matchers.lessThanOrEqualTo; | |
| import static org.junit.Assert.assertThat; | |
| import java.util.HashSet; | |
| import java.util.Set; |
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
| describe 'Perfect Numbers' | |
| it 'should find 6 in a range between 2 and 10' | |
| findPerfectNumbersInRange(2,10, function(result){ | |
| result.should.eql [6] | |
| }); | |
| end | |
| it 'should return 28 in a range between 20 and 30' | |
| findPerfectNumbersInRange(20, 30, function(result){ | |
| result.should.eql [28] |
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 sbt._ | |
| class Configuration(info: ProjectInfo) extends DefaultProject(info){ | |
| val scalatest = "org.scala-tools.testing" % "scalatest" % "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
| import org.specs._ | |
| object TriangleWordIdentifierSpec extends Specification{ | |
| "letter to number converter" should { | |
| "convert A to 1" in { | |
| convertLetterToNumber('A') must be(1) | |
| } | |
| "convert a to 1" in { | |
| convertLetterToNumber('a') must be(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
| object isTriangleWord extends (String => Boolean){ | |
| override def apply(word:String) = { | |
| val wordVal = wordValue(word) | |
| var result = false | |
| var i = 1 | |
| while(triangleNumberFor(i) <= wordVal){ | |
| if(triangleNumberFor(i) == wordVal){ | |
| result = true | |
| } | |
| i += 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
| object Polynomial extends (Int => Int){ | |
| override def apply(n:Int) = { | |
| n * (if(n > 1) apply(n-1) else 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
| FactorialSpec.scala: | |
| import org.specs._ | |
| class FactorialSpec extends Specification{ | |
| "polynomial" should { | |
| "return 1 for n = 1" in { | |
| Factorial(1) must be (1) | |
| } | |
| "return 2 for n = 2" in { |
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
| Works: | |
| class Marker private (val color:String){ | |
| override def toString():String = "marker color " + color | |
| } | |
| object Marker { | |
| private val markers = Map( | |
| "red" -> new Marker("red"), | |
| "blue" -> new Marker("blue"), |
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
| solving 6 | |
| object IsPerfectNumber extends (Int => Boolean) { | |
| def apply(n:Int) = { | |
| if(n % 2 == 0) (1 to n / 2).foldLeft(0)(_+_) == n else false | |
| } | |
| } |