Skip to content

Instantly share code, notes, and snippets.

Download Scala at: http://bit.ly/a5LOj
Download ScalaTest at: http://bit.ly/gH5X0s
Download SBT at: http://bit.ly/cNBQ14
import org.scalatest.Spec
import org.scalatest.matchers.ShouldMatchers
class BowlingGameSpecs extends Spec with ShouldMatchers {
describe("Playing a game") {
it("should have a score of zero for a game with all zero rolls") {
val game = new BowlingGame(List(0,0,0,0,0,0,0,0,0,0)
game.score should equal(0)
}
fsc *.scala -classpath scalatest-1.3.jar
scala -cp scalatest-1.3.jar org.scalatest.tools.Runner -p . -o -s BowlingGameSpecs
import scala.collection.mutable._
class BowlingGame(val reverseRolls: List[Int]) {
def roll(pins: Int) = {
if(pins == 10)
new BowlingGame(0 :: pins :: reverseRolls)
else
new BowlingGame(pins :: reverseRolls)
}
class BowlingGame
def initialize
@all_rolls = []
end
def roll(pins)
@all_rolls << pins
end
import scala.collection.mutable._
class BowlingGame {
val allRolls = new ListBuffer[Int]()
def roll(pins: Int) = allRolls.append(pins)
def score() = buildFrameScores(allRolls.toList).slice(0,10).sum
def buildFrameScores(rolls: List[Int]):List[Int] = {
if(rolls.isEmpty) {
import org.scalatest.Spec
import org.scalatest.matchers.ShouldMatchers
class BowlingGameSpecs extends Spec with ShouldMatchers {
describe("Playing a game") {
it("should have a score of zero for a game with all zero rolls") {
val game = new BowlingGame()
(1 to 20).map(i => 0).foreach(game.roll)
game.score should equal(0)
}
package com.foo.bar;
import android.os.AsyncTask;
import android.util.Log;
public abstract class SimpleTask extends AsyncTask<Void, Void, Boolean> {
private final AsyncTask waitTask;
public SimpleTask(AsyncTask waitTask) {
package com.foo.bar;
import android.os.AsyncTask;
public class LoadDrawingContentTask extends SimpleTask {
private final Location location;
public LoadDrawingContentTask(Location myLocation) {
this.location = myLocation;
rgb_values = "ffaaffaabbccdd3322fa352fda2"
decimal_values = []
rgb_values.each_slice(2) do |pair|
decimal_values << pair.join("").hex
end
File.open('test.jpg', 'wb') do |file|
file.print(decimal_values.pack("c*"))
end