Skip to content

Instantly share code, notes, and snippets.

@kings13y
Created May 28, 2012 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kings13y/2818378 to your computer and use it in GitHub Desktop.
Save kings13y/2818378 to your computer and use it in GitHub Desktop.
FizzBuzz test case in Specs2
package org.scalabound.scatdd.specs2
import org.scalabound.scatdd.FizzBuzz
import org.junit.runner.RunWith
import org.specs2.runner.JUnitRunner
// package unitTest { |> Scala IDE will not pick the class up as runnable if I sub-package it like this :-(
@RunWith(classOf[JUnitRunner])
class FizzBuzzJUnitSpec extends org.specs2.mutable.Specification {
"Multiples of both three and five" should {
"print 'FizzBuzz'" in { FizzBuzz.eval(15) must_== "FizzBuzz" }
}
"Multiples of three only" should {
"print 'Fizz'" in { FizzBuzz.eval(12) must_== "Fizz" }
}
"Multiples of five only" should {
"print 'Buzz'" in { FizzBuzz.eval(10) must_== "Buzz" }
}
"Non multiples of five or three" should {
"print the number back" in { FizzBuzz.eval(11) must_== "11" }
}
}
// package acceptanceTest { |> Scala IDE will not pick the class up as runnable if I sub-package it like this :-(
@RunWith(classOf[JUnitRunner])
class FizzBuzzUATSpec extends org.specs2.Specification { def is =
"This specification is to check the FizzBuzz evaluator" ^
p^
"The FizzBuzz evaluator should" ^
"process a multiple of both three and five to return FizzBuzz" ! e1^
"process a multiple of three only to return Fizz" ! e2^
"process a multiple of five only to return Buzz" ! e3^
"process a non multiple of three or five to return the input" ! e4^
end
def e1 = FizzBuzz.eval(15) must_== "FizzBuzz"
def e2 = FizzBuzz.eval(12) must_== "Fizz"
def e3 = FizzBuzz.eval(10) must_== "Buzz"
def e4 = FizzBuzz.eval(11) must_== "11"
}
@RunWith(classOf[JUnitRunner])
class FizzBuzzDataTableSpec extends org.specs2.Specification with org.specs2.matcher.DataTables { def is =
"Fizz Buzz testing with DataTables" ! e1
def e1 = // Weirdly I cannot switch columns a and b as Specs tells me there is no implicit conversion from Int => Result !
"input val" | "spec name " | "expected output" |
15 ! "Mulitple of both three and five" ! "FizzBuzz" |
12 ! "Multiple of three only" ! "Fizz" |
10 ! "Multiple of five only" ! "Buzz" |
11 ! "Non multiple of five or three" ! "11" |> {
(a, b, c) => FizzBuzz.eval(a) must_== c // (a, b, c) is a structural match on the table
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment