Skip to content

Commit

Permalink
Working on AboutMethods
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Korab committed Feb 22, 2012
1 parent d809572 commit 4d3d489
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/test/scala/org/scalakoans/AboutMethods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,36 @@ import support.KoanSuite
class AboutMethods extends KoanSuite {

koan ("method declaration") {
// a method can be defined within other methods
def add2(i: Int): Int = {
return i + 2
}

add2(2) should __
add2(2) should be(4)

meditate
// define add3
// add3(2) should be(5)
// meditate
def add3(i : Int) : Int = {
i + 3
}
add3(2) should be(5)
}

koan ("return not always necssary") {
def add2(i: Int): Int = {
i + 2
}

add2(3) should __
add2(3) should be(5)
}

koan ("return type necessity") {
def add2(i: Int) = {
i + 2
}

add2(4) should __
val returned = add2(4)
returned should be(6)
returned.isInstanceOf[Int] should be(true)
}

koan ("nested methods") {
Expand All @@ -42,10 +47,13 @@ class AboutMethods extends KoanSuite {
add(2, i)
}

add2(5) should __
add2(5) should be (7)

meditate
// add3(2) should be(5)
//meditate
def add3(i : Int) = {
3 + i
}
add3(2) should be(5)
}

koan ("method without a return") {
Expand All @@ -56,25 +64,32 @@ class AboutMethods extends KoanSuite {

add2ToX()

x should __
x should be (4)
}

koan ("brackets around the method body aren't always necessary for simple expressions") {
def add2(i: Int) = i + 2

add2(2) should __
add2(2) should be (4)
}

koan ("named arguments") {
def add2(i: Int) = i + 2

add2(i=5) should __
add2(i=5) should be (7)

// MERGE
// arguments can therefore be used out of order
def addToWordCount(word : String, i : Int) = {
i + word.length()
}
addToWordCount(i = 3, word = "foo") should be (6)
}

koan ("default arguments") {
def addNumbers(first: Int, second: Int = 2) = first + second

addNumbers(3) should __
addNumbers(3) should be (5)

meditate
// def addNumbers2(first: Int = 2, second: Int) = first + second
Expand Down

0 comments on commit 4d3d489

Please sign in to comment.