This file contains hidden or 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))) | |
} | |
This file contains hidden or 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")) |
This file contains hidden or 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) ) )) |
This file contains hidden or 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) |
This file contains hidden or 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 | |
} | |
} |
This file contains hidden or 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 : _*) |
This file contains hidden or 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]); |
This file contains hidden or 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:]) |
This file contains hidden or 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 = [] |
This file contains hidden or 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