Skip to content

Commit

Permalink
Added koans for structural types
Browse files Browse the repository at this point in the history
  • Loading branch information
lamdor committed Sep 14, 2010
1 parent d6f3643 commit de06bdb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/test/scala/org/scalakoans/AboutStructuralTypes.scala
@@ -0,0 +1,33 @@
package org.scalakoans

import support.KoanSuite

class AboutStructuralTypes extends KoanSuite {

koan ("stuctural types") {
def sayHello(person: {def name: String}) = "Hello, " + person.name

case class Person(name: String)

val p = new Person("Lou")

sayHello(p) should be(__)

case class Person2
val p2 = new Person2
meditate
//sayHello(p2) should be(__)
}

koan ("defined structural type") {
type HasName = {def name: String}

def sayHello(person: HasName) = "Hello, " + person.name

case class Person(name: String)

val p = new Person("Lou")
sayHello(p) should be(__)
}

}
3 changes: 2 additions & 1 deletion src/test/scala/org/scalakoans/Koans.scala
Expand Up @@ -12,6 +12,7 @@ class Koans extends Suite {
new AboutClasses,
new AboutObjects,
new AboutPackages,
new AboutAbstractClasses
new AboutAbstractClasses,
new AboutStructuralTypes
)
}

0 comments on commit de06bdb

Please sign in to comment.