Skip to content

Instantly share code, notes, and snippets.

View jbrains's full-sized avatar

J. B. Rainsberger jbrains

View GitHub Profile
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
//Using Maybe.cs
namespace ArrayStructure
{
[TestFixture]
public class Tests
{
@jbrains
jbrains / PointOfSaleTerminal.java
Last active November 28, 2016 21:20 — forked from CoryFoy/sample.rb
TDD no Expectations
package ca.jbrains.pos;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.util.HashMap;
public class PointOfSaleTerminal {
public static void main(String[] args) throws IOException {
final InputStreamReader commandSource = new InputStreamReader(System.in);
-- Thanks to @kimwallmark for teaching me `maybe` and showing me how a single lookup.
-- I had the brilliant idea of using `snd`, even though I dislike the name. :)
fizzbuzz :: Integer -> String
fizzbuzz n = maybe (show n) snd $ classify n
where
classify n = find (\(m, _) -> n `mod` m == 0) [(15, "Fizzbuzz"), (5, "Buzz"), (3, "Fizz")]
@jbrains
jbrains / gist:9451941
Last active August 29, 2015 13:57 — forked from CoryFoy/gist:9441665
# SMELL I don't like the name gemfile_lock_file, but I don't know
# what else to call it. I want to distinguish it from Gemfile.
def extract_gems_from_gemfile_lock_file(contents)
gems = []
# Extract all the non-empty lines between and excluding 'specs:' and 'PLATFORMS'
contents.each_line do |line|
line = line.strip
# It takes a few seconds to understand this algorithm,
# but I can't yet justify replacing it with a functional
# approach. Again, it depends what the reader understands
#!/bin/bash
download_yuml_image() {
local file="$1"
local output_directory="$2"
instructions=$(tr "\\n" "," < <(cat $file))
image_basename=$(basename $(echo $file | sed -E "s/(.+)\.yuml$/\1/"))
image_filename="${output_directory}/${image_basename}.png"
@jbrains
jbrains / gist:1259077
Created October 3, 2011 13:14 — forked from philipschwarz/gist:1241175
Separating use from construction - Before
public class BusinessObject {
/** @deprecated */
public void actionMethod() {
actionMethod(Service.getInstance());
}
// A SEAM! A SEAM! New clients should use me!!
public void actionMethod(ServiceDelegate serviceDelegate) {
// Other things
serviceDelegate.doService();
@jbrains
jbrains / Cell.java
Created January 20, 2011 21:13 — forked from patrickwilsonwelsh/RulesForNextGenerationTest
One way to remove duplication from PWW's tests
package rules;
public class Cell {
protected int numberOfLiveNeighbors;
private CellState state;
public Cell() {
this.state = CellState.DEAD;
}
# common use of mocks in a Rails app
it "updates the requested book" do
mock_book = mock(:book)
Book.should_receive(:find).with("37").and_return(mock_book)
mock_book.should_receive(:update_attributes).with({:these => 'params'})
put :update, :id => "37", :book => {:these => 'params'}
end
# without mocks a more readable, less brittle test
it "updates the requested book" do
ackage ca.jbrains.pos.test;
import org.junit.*;
import static org.junit.Assert.*;
import java.util.*;
public class SellOneItemTest {
private POSDisplay posDisplay = new POSDisplay();
private Sale sale;
public class CreateActionTest {
def mockery = new JUnit4Mockery();
def modelRepository = mockery.mock(ModelRepository.class); // corresponds to class methods on Model in Rails
def model = new Model(); // treated as Entity (DDD sense)
def controller = new Controller(modelRepository);
@Before
public void supposeModelRepositoryCreatesOurModelObject() {
mockery.stub(modelRepository).create().will(returnValue(model));