Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 6db461de1a00f97ef7ebd078b88e740dfe706abe @fwielstra committed Dec 6, 2011
Showing with 3,418 additions and 0 deletions.
  1. +15 −0 .gitignore
  2. +9 −0 README-scala.txt
  3. +9 −0 build.sbt
  4. +1 −0 sbt
  5. BIN sbt-launch.jar
  6. +2 −0 sbt.bat
  7. +9 −0 src/main/scala/org/functionalkoans/App.scala
  8. +197 −0 src/test/scala/org/functionalkoans/forscala/AboutAccessModifiers.scala
  9. +30 −0 src/test/scala/org/functionalkoans/forscala/AboutAsserts.scala
  10. +130 −0 src/test/scala/org/functionalkoans/forscala/AboutCaseClasses.scala
  11. +41 −0 src/test/scala/org/functionalkoans/forscala/AboutClasses.scala
  12. +30 −0 src/test/scala/org/functionalkoans/forscala/AboutConstructors.scala
  13. +65 −0 src/test/scala/org/functionalkoans/forscala/AboutEmptyValues.scala
  14. +132 −0 src/test/scala/org/functionalkoans/forscala/AboutEnumerations.scala
  15. +38 −0 src/test/scala/org/functionalkoans/forscala/AboutForExpressions.scala
  16. +82 −0 src/test/scala/org/functionalkoans/forscala/AboutHigherOrderFunctions.scala
  17. +96 −0 src/test/scala/org/functionalkoans/forscala/AboutImplicits.scala
  18. +156 −0 src/test/scala/org/functionalkoans/forscala/AboutImportsAndPackages.scala
  19. +62 −0 src/test/scala/org/functionalkoans/forscala/AboutInfixPrefixAndPostfixOperators.scala
  20. +54 −0 src/test/scala/org/functionalkoans/forscala/AboutInfixTypes.scala
  21. +58 −0 src/test/scala/org/functionalkoans/forscala/AboutLazySequences.scala
  22. +125 −0 src/test/scala/org/functionalkoans/forscala/AboutLists.scala
  23. +23 −0 src/test/scala/org/functionalkoans/forscala/AboutLiteralBooleans.scala
  24. +89 −0 src/test/scala/org/functionalkoans/forscala/AboutLiteralNumbers.scala
  25. +70 −0 src/test/scala/org/functionalkoans/forscala/AboutLiteralStrings.scala
  26. +139 −0 src/test/scala/org/functionalkoans/forscala/AboutLiterals.scala
  27. +35 −0 src/test/scala/org/functionalkoans/forscala/AboutManifests.scala
  28. +135 −0 src/test/scala/org/functionalkoans/forscala/AboutMaps.scala
  29. +56 −0 src/test/scala/org/functionalkoans/forscala/AboutMutableMaps.scala
  30. +55 −0 src/test/scala/org/functionalkoans/forscala/AboutMutableSets.scala
  31. +82 −0 src/test/scala/org/functionalkoans/forscala/AboutNamedAndDefaultArguments.scala
  32. +130 −0 src/test/scala/org/functionalkoans/forscala/AboutOptions.scala
  33. +42 −0 src/test/scala/org/functionalkoans/forscala/AboutParentClasses.scala
  34. +88 −0 src/test/scala/org/functionalkoans/forscala/AboutPartialFunctions.scala
  35. +22 −0 src/test/scala/org/functionalkoans/forscala/AboutPartiallyAppliedFunctions.scala
  36. +80 −0 src/test/scala/org/functionalkoans/forscala/AboutPatternMatching.scala
  37. +26 −0 src/test/scala/org/functionalkoans/forscala/AboutPreconditions.scala
  38. +32 −0 src/test/scala/org/functionalkoans/forscala/AboutRange.scala
  39. +51 −0 src/test/scala/org/functionalkoans/forscala/AboutSequencesAndArrays.scala
  40. +125 −0 src/test/scala/org/functionalkoans/forscala/AboutSets.scala
  41. +222 −0 src/test/scala/org/functionalkoans/forscala/AboutTraits.scala
  42. +28 −0 src/test/scala/org/functionalkoans/forscala/AboutTuples.scala
  43. +103 −0 src/test/scala/org/functionalkoans/forscala/AboutTypeSignatures.scala
  44. +233 −0 src/test/scala/org/functionalkoans/forscala/AboutTypeVariance.scala
  45. +52 −0 src/test/scala/org/functionalkoans/forscala/AboutUniformAccessPrinciple.scala
  46. +25 −0 src/test/scala/org/functionalkoans/forscala/AboutValAndVar.scala
  47. +50 −0 src/test/scala/org/functionalkoans/forscala/Koans.scala
  48. +55 −0 src/test/scala/org/functionalkoans/forscala/support/KoanSuite.scala
  49. +29 −0 src/test/scala/org/functionalkoans/forscala/support/Master.scala
@@ -0,0 +1,15 @@
+lib_managed
+project/boot
+project/build/target
+scalakoansexercises.iws
+scalakoansexercises.ipr
+scalakoansexercises.iml
+target
+.*\.DS_Store
+.*\.zip
+scala-koans.iml
+scala-koans.ipr
+scala-koans.iws
+.idea*
+.classpath
+.project
@@ -0,0 +1,9 @@
+This is the "exercises" version. The working koans are
+at http://bitbucket.org/dickwall/scala-koans/wiki/Home for more details and answers on scala-koans
+
+To run:
+chmod +x ./sbt
+sbt
+~test-only org.functionalkoans.forscala.Koans
+
+then start with AboutAsserts
@@ -0,0 +1,9 @@
+name := "Scala Koans"
+
+version := "1.0"
+
+scalaVersion := "2.9.0-1"
+
+traceLevel := -1
+
+retrieveManaged := true
@@ -0,0 +1 @@
+java -Dfile.encoding=UTF8 -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -jar `dirname $0`/sbt-launch.jar "$@"
Binary file not shown.
@@ -0,0 +1,2 @@
+set SCRIPT_DIR=%~dp0
+java -Xmx512M -jar "%SCRIPT_DIR%sbt-launch.jar" %*
@@ -0,0 +1,9 @@
+package org.functionalkoans
+
+/**
+ * Hello world!
+ *
+ */
+object App extends Application {
+ println( "Hello World!" )
+}
@@ -0,0 +1,197 @@
+package org.functionalkoans.forscala
+
+import support.KoanSuite
+
+package harkonnen {
+
+class AlphaBase extends KoanSuite {
+ private val melange = 1
+ private[this] val oregano = 2
+ private[AlphaBase] val tarragon = 3
+ private[harkonnen] val rosemary = 4
+
+ val parsley = 5
+ // public val ginger = 6 //does not exist, in case you were wondering
+ // public[this] val lemongrass = 7 //does not exist, in case you were wondering
+ // public[AlphaBase] val carob = 8 //does not exist, in case you were wondering
+ // public[har] val celerySeed = 9 //does not exist, in case you were wondering
+
+ protected val sage = 10
+ protected[this] val paprika = 11
+ protected[AlphaBase] val saffron = 12
+ protected[harkonnen] val thyme = 13
+}
+
+
+class BetaBase extends AlphaBase with KoanSuite {
+ val param: AlphaBase = new AlphaBase
+
+ koan("With private keywords: Only private[packagename] members can be accessed via inheritance") {
+ //melange should be(1) //not accessible
+ //oregano should be (2) //not accessible
+ //tarragon should be (3) //not accessible
+ rosemary should be(__)
+ }
+
+ koan("With private keywords: Only private[packagename] members can be accessed via parameter") {
+ //param.melange should be (1) //not accessible
+ //param.oregano should be (2) //not accessible
+ //param.tarragon should be (3) //not accessible
+ param.rosemary should be(__)
+ }
+
+ koan("With public keywords: All members can be accessed through inheritance") {
+ parsley should be(__)
+ }
+
+ koan("With public keywords: All members can be accessed can be accessed via parameter") {
+ param.parsley should be(__)
+ }
+
+ koan("With protected keywords: All members can be accessed via inheritance") {
+ sage should be(__)
+ paprika should be(__) //not accessible
+ saffron should be(__) //not accessible
+ thyme should be(__)
+ }
+
+ koan("With protected keywords: Only private[packagename] members can be accessed via parameter") {
+ //param.sage should be (10) //not accessible
+ //param.paprika should be (11) //not accessible
+ //param.saffron should be (12) //not accessible
+ param.thyme should be(__)
+ }
+}
+
+class GammaBase extends KoanSuite {
+
+ val param: AlphaBase = new AlphaBase
+
+ koan("With private keywords: No members can be accessed via inheritance") {
+ //melange should be(1) //not accessible
+ //oregano should be (2) //not accessible
+ //tarragon should be (3) //not accessible
+ //rosemary should be(4) //not accessible
+ }
+
+ koan("With private keywords: Only private[packagename] members can be accessed via parameter") {
+ //param.melange should be (1) //not accessible
+ //param.oregano should be (2) //not accessible
+ //param.tarragon should be (3) //not accessible
+ param.rosemary should be(__)
+ }
+
+ koan("With public keywords: All members can be accessed through inheritance") {
+ //parsley should be(5) //not accessible
+ }
+
+ koan("With public keywords: All members can be accessed can be accessed via parameter") {
+ param.parsley should be(__)
+ }
+
+ koan("With protected keywords: All members can be accessed via inheritance") {
+ //sage should be (10)
+ //paprika should be (11) //not accessible
+ //saffron should be (12) //not accessible
+ //thyme should be (13)
+ }
+
+ koan("With protected keywords: Only private[packagename] members can be accessed via parameter") {
+ // param.sage should be (10) //not accessible
+ // param.paprika should be (11) //not accessible
+ // param.saffron should be (12) //not accessible
+ param.thyme should be(__)
+ }
+}
+
+}
+
+package atreides {
+
+import org.functionalkoans.forscala.harkonnen.AlphaBase
+
+class DeltaBase extends AlphaBase with KoanSuite {
+ val param: AlphaBase = new AlphaBase
+
+ koan("With private keywords: Only private and private[packagename] members can be accessed via inheritance") {
+ //melange should be (1)
+ //oregano should be (2) //not accessible
+ //tarragon should be (3) //not accessible
+ //rosemary should be (4)
+ }
+
+ koan("With private keywords: Only private[packagename] members can be accessed via parameter") {
+ // param.melange should be (1) //not accessible
+ // param.oregano should be (2) //not accessible
+ // param.tarragon should be (3) //not accessible
+ // param.rosemary should be(4) //not accessible
+ }
+
+ koan("With public keywords: All members can be accessed through inheritance") {
+ parsley should be(__)
+ }
+
+ koan("With public keywords: All members can be accessed can be accessed via parameter") {
+ param.parsley should be(__)
+ }
+
+ koan("With protected keywords: All members can be accessed via inheritance") {
+ sage should be(__)
+ paprika should be(__) //not accessible
+ saffron should be(__) //not accessible
+ thyme should be(__)
+ }
+
+ koan("With protected keywords: Only private[packagename] members can be accessed via parameter") {
+ //param.sage should be (10) //not accessible
+ //param.paprika should be (11) //not accessible
+ //param.saffron should be (12) //not accessible
+ //param.thyme should be (13)
+ }
+}
+
+class EpsilonBase extends KoanSuite {
+ val param: AlphaBase = new AlphaBase
+
+ koan("With private keywords: Only private and private[packagename] members can be accessed via inheritance") {
+ // melange should be (1) //not accessible
+ // oregano should be (2) //not accessible
+ // tarragon should be (3) //not accessible
+ // rosemary should be (4) //not accessible
+ }
+
+ koan("With private keywords: Only private[packagename] members can be accessed via parameter") {
+ // param.melange should be (1) //not accessible
+ // param.oregano should be (2) //not accessible
+ // param.tarragon should be (3) //not accessible
+ // param.rosemary should be(4) //not accessible
+ }
+
+ koan("With public keywords: All members can be accessed through inheritance") {
+ // parsley should be(5)
+ }
+
+ koan("With public keywords: All members can be accessed can be accessed via parameter") {
+ param.parsley should be(__)
+ }
+
+ koan("With protected keywords: All members can be accessed via inheritance") {
+ // sage should be (10)
+ // paprika should be (11) //not accessible
+ // saffron should be (12) //not accessible
+ // thyme should be (13)
+ }
+
+ koan("With protected keywords: Only private[packagename] members can be accessed via parameter") {
+ // param.sage should be (10) //not accessible
+ // param.paprika should be (11) //not accessible
+ // param.saffron should be (12) //not accessible
+ // param.thyme should be (13)
+ }
+}
+
+}
+
+class AboutAccessModifiers extends KoanSuite {
+
+}
@@ -0,0 +1,30 @@
+package org.functionalkoans.forscala
+
+import org.scalatest.matchers.ShouldMatchers
+import support.KoanSuite
+
+// meditate on AboutAsserts to see how the Scala Koans work
+class AboutAsserts extends KoanSuite with ShouldMatchers {
+
+ koan("asserts can take a boolean argument") {
+ assert(false) // should be true
+ }
+
+ koan("asserts can include a message") {
+ assert(false, "This should be true")
+ }
+
+ koan("true and false values can be compared with should matchers") {
+ true should be(__) // should be true
+ }
+
+ koan("booleans in asserts can test equality") {
+ val v1 = 4
+ val v2 = 4
+ assert(v1 === __)
+ }
+
+ koan("sometimes we expect you to fill in the values") {
+ assert(__ == 1 + 1)
+ }
+}
Oops, something went wrong.

0 comments on commit 6db461d

Please sign in to comment.