Permalink
Browse files

First commit with tests

  • Loading branch information...
1 parent c844459 commit 32bb3d0a3602fed07b33d372a9281e35563e5b1f @fanf committed Jul 5, 2011
Showing with 18 additions and 8 deletions.
  1. +2 −1 src/main/scala/psug/dojos/P009.scala
  2. +16 −7 src/test/scala/psug/dojos/TestP009.scala
@@ -1,4 +1,5 @@
package psug.dojos
+import org.scalacheck.Prop
object P009 {
@@ -143,7 +144,7 @@ object P009 {
l <- Gen.listOf(genListSameSymbol)
} yield l.flatten
- def propFlattenPackIsIdentity[T](pack : List[Symbol] => List[List[Symbol]]) = {
+ def propFlattenPackIsIdentity[T](pack : List[Symbol] => List[List[Symbol]]) : Prop = {
forAll(genListOfSuiteSameSymbol) { (l1: List[Symbol]) =>
pack(l1).flatten == l1
}
@@ -4,12 +4,14 @@ package psug.dojos
import org.specs2.mutable._
import org.specs2.runner._
import org.junit.runner.RunWith
-
import psug.dojos.P009._
import psug.dojos.Utils._
+import org.specs2.ScalaCheck
+import org.scalacheck.Prop
+import org.specs2.execute.Result
@RunWith(classOf[JUnitRunner])
-class TestP009 extends Specification {
+class TestP009 extends Specification with ScalaCheck {
val solutions = List[(String, List[Symbol] => List[List[Symbol]])](
( "BenjaminLerman (1)" , BenjaminLerman.pack[Symbol])
@@ -32,16 +34,23 @@ class TestP009 extends Specification {
"All possible solutions" should {
-// "pass DavidBernard.propFlattenPackIsIdentity" in {
-// DavidBernard.propFlattenPackIsIdentity(s._2).check
-// }
-
"at least pass the problem example" in {
val expected = List(List('a, 'a, 'a, 'a), List('b), List('c, 'c), List('a, 'a), List('d), List('e, 'e, 'e, 'e))
( (x:(String,List[List[Symbol]])) => (x._1,x._2) === (x._1,expected) ).foreach(
solutions.map {case(name, f) => (name,f(List('a, 'a, 'a, 'a, 'b, 'c, 'c, 'a, 'a, 'd, 'e, 'e, 'e, 'e))) }
)
- }
+ }
}
+
+
+// don't seem to work... I don't know how to compose examples.
+// solutions.foreach { case (name, pack) =>
+// this.addExample {
+// name + " pass DavidBernard.propFlattenPackIsIdentity" in {
+// check(DavidBernard.propFlattenPackIsIdentity( pack ) )
+// }
+// }
+// }
+
}

0 comments on commit 32bb3d0

Please sign in to comment.