View gist:5302877
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BoardSuite extends FunSuite with BeforeAndAfter { | |
var board : Board = _ | |
before { | |
board = new Board | |
} | |
test("A board is initialized to blank") { | |
board.moves.foreach(row => row.foreach(box => assert(box === Player.B))) | |
} | |
View gist:5309993
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns oobook-lein.core) | |
(defn hello-world [] | |
(println "Hello world")) |
View gist:5317208
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def second (fn [list] ( nth list 1 ) )) | |
(def secondMkTwo (fn [list] ( first (rest list) ) )) |
View gist:5317239
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
listOfStrings.foldLeft(0)((sum, value) => sum + value.length) |
View gist:5317253
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Censor { | |
var alternatives = Map("Shoot" -> "Pucky", "Darn" -> "Beans") | |
def censor(input : String) : String = { | |
var toReturn = input | |
alternatives.foreach( entry => toReturn = toReturn.replace(entry._1, entry._2)) | |
toReturn | |
} | |
} |
View gist:5317264
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.io.Source._ | |
trait CensorFromFile extends Censor { | |
val curses = | |
fromFile("day2/curses") | |
.getLines() | |
.map(_.split("=")) | |
.map(fields => fields(0) -> fields(1)).toList | |
alternatives = Map(curses : _*) |
View Java mock iterable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <T> void mockIterable(Iterable<T> iterable, T... values) { | |
Iterator<T> mockIterator = mock(Iterator.class); | |
when(iterable.iterator()).thenReturn(mockIterator); | |
if (values.length == 0) { | |
when(mockIterator.hasNext()).thenReturn(false); | |
return; | |
} else if (values.length == 1) { | |
when(mockIterator.hasNext()).thenReturn(true, false); | |
when(mockIterator.next()).thenReturn(values[0]); |
View mergesort.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MergeSort(object): | |
@staticmethod | |
def sort(array): | |
if len(array) <= 1: | |
return array | |
else: | |
middle = len(array)/2 | |
left_half = MergeSort.sort(array[:middle]) | |
right_half = MergeSort.sort(array[middle:]) |
View mergesort_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from mergesort import MergeSort | |
class MergeSortTest(unittest.TestCase): | |
def setUp(self): | |
self.under_test = MergeSort() | |
def test_empty_array(self): | |
array_to_sort = [] |
View Service.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Service { | |
private Datastore datastore | |
Service(Datastore datastore) { | |
// ... | |
} | |
def processEntry(Map<String, String> someStuffToStore) { | |
// ... |
OlderNewer