[Know about it][Understanding][Clear understanding]
xxx
Immutable Dataxxx
Second-Order Functionsxxx
Constructing & Destructuringxxx
Function Compositionxxx
First-Class Functions & Lambdas
module A200 where | |
import Data.List.Split (splitOn) | |
data Symbol = Rock | Paper | Scissors | |
data Strategy = Win | Lose | Draw | |
data Match = Match { opponent :: Symbol, player :: Symbol } | |
strategy :: Symbol -> Strategy -> Match | |
strategy o s = Match o (case s of | |
Win -> case o of |
diff --git a/spec/unit/pluginmanager_spec.rb b/spec/unit/pluginmanager_spec.rb | |
index be531c8..d99fba0 100755 | |
--- a/spec/unit/pluginmanager_spec.rb | |
+++ b/spec/unit/pluginmanager_spec.rb | |
@@ -6,7 +6,7 @@ module MCollective | |
describe PluginManager do | |
before do | |
class MCollective::Foo; end | |
- | |
+ @config = mock |
from psycopg2 import connect | |
from Levenshtein import * | |
conn = connect("dbname=education user=Jwyer host=localhost") | |
id_look_up = {} | |
candidates = [] | |
cursor = conn.cursor() | |
cursor.execute("select id, name from school") | |
for row in cursor.fetchall(): |
import codecs | |
import requests | |
import multiprocessing | |
def process_url(page): | |
print page | |
url = "http://www.southafricaschools.co.za/schools2?page=%ld&tid=13&tid_1=All&tid_2=All&title=" % (page) | |
r = requests.get(url) | |
out = codecs.open('eastern-cape/page-%ld' % (page), 'w', 'utf-8') | |
out.write(r.text) |
- (void)testShouldKnowCardsCanBeAddedToDeck { | |
Deck *deck = [Deck new]; | |
Card *card = [[Card alloc] initWithContents:@"Test Card"]; | |
id cardsMock = [OCMockObject mockForClass:[NSMutableArray class]]; | |
[[cardsMock expect] addObject:card]; | |
deck.cards = cardsMock; | |
[deck addCard:card atTop:NO]; |
- (int)match:(NSArray *)cards { | |
return [cards containsObject:self]; | |
} |
// FIRST TEST | |
- (void)testShouldKnowCardsWithSameContentsAreEqual { | |
Card *card = [[Card alloc] initWithContents:@"Test Card"]; | |
Card *equalCard = [[Card alloc] initWithContents:@"Test Card"]; | |
STAssertEqualObjects(card, equalCard, @"Cards with the same content should be equal"); | |
} | |
// RED isEqual is not yet overriden | |
// GREEN returns YES | |
- (BOOL)isEqual:(id)other { |
@implementation Card { | |
} | |
- (int)match:(NSArray *)cards { | |
int score = 0; | |
for (Card *card in cards) { | |
if ([card.contents isEqualToString:self.contents]) { | |
score = 1; | |
break; | |
} | |
} |
@implementation CardTest | |
- (void)testShouldKnowCardCannotMatchEmptyCardList { | |
Card *card = [Card new]; | |
NSArray *otherCards = [NSArray new]; | |
STAssertEquals(0, [card match:otherCards], @"Should not match empty card list."); | |
} | |
- (void)testShouldMatchCardWhenCardListContainsCardWithSameContent { | |
Card *card = [[Card alloc] initWithContents:@"Test Card"]; | |
Card *matchingCard = [[Card alloc] initWithContents:@"Test Card"]; |