Skip to content

Instantly share code, notes, and snippets.

View kevinpet's full-sized avatar

Kevin Peterson kevinpet

View GitHub Profile
public class AccountTest {
Mockery mockery;
Strategy mockStrategy;
Account account;
@Before
public void before() {
mockery = new Mockery();
mockery.setImposteriser(ClassImposteriser.INSTANCE);
mockStrategy = mockery.mock(Strategy.class);
public class StrategyTest {
@Test
public void testHighRiskLowFraction_okayForRisky() {
assertTrue(Strategy.AGGRESIVE.isRiskAcceptable(0.1, 0.75));
assertTrue(Strategy.AGGRESIVE.isRiskAcceptable(0.2, 0.75));
assertTrue(Strategy.AGGRESIVE.isRiskAcceptable(0.2, 0.5));
}
}
enum Strategy {
AGGRESIVE {
@Override
boolean isRiskAcceptable(double percentOfAssets, double riskiness) {
return percentOfAssets * riskiness < 0.25;
}
},
CONSERVATIVE {
@Override
boolean isRiskAcceptable(double percentOfAssets, double riskiness) {
switch (account.getStrategy()) {
case AGGRESIVE:
return "aggressive high risk";
case CONSERVATIVE:
return "conservative low risk";
default:
return "unknown strategy";
}
@kevinpet
kevinpet / bus
Last active December 18, 2015 14:38
At 8:55am on 2013-06-17, while riding west at about 12-15mph
over the Willow Rd. Hwy 101 overcrossing in the right hand lane,
a dumbarton express bus #DB1 passed unsafely, with 12-18" of
space between the bus and my handlebar before taking the 101S onramp.
AC Transit feedback #10300
class WithLambda {
public static void main(String[] args) {
Runnable r = () -> System.out.println("and it works...");
r.run();
}
}
@kevinpet
kevinpet / MarketTest.java
Created November 12, 2012 17:41
Test to update the market
@Test
public void testNeedToUpdateHolidaysBeforeNextYear() throws Exception {
DateTime now = new DateTime(ET);
DateTime warningDate = new DateTime(2012, 12, 15, 0, 0, 0, 0, ET);
LocalDate newYearsDate = new LocalDate(warningDate.getYear()+1, 1, 1);
/**
* Once you update the holidays in Market.java, increment the year in this test
* so it passes until next year.
*/
@kevinpet
kevinpet / Market.java
Created November 12, 2012 17:37
Extract from Market showing holidays
@Singleton
public class Market {
final static Set<LocalDate> HOLIDAYS = ImmutableSet.of(
// ...
new LocalDate(2012, 1, 2), // New Years
new LocalDate(2012, 1, 16), // MLK
new LocalDate(2012, 2, 20), // Washington's Birthday
new LocalDate(2012, 4, 6), // Good Friday
new LocalDate(2012, 5, 28), // Memorial Day
@kevinpet
kevinpet / Nullery.java
Created April 11, 2012 16:57 — forked from anonymous/Nullery.java
Nullery: self-aware nulls for testing
public class Nullery {
private static MockObjectNamingScheme namingScheme = new CamelCaseNamingScheme();
private static Imposteriser imposteriser = ClassImposteriser.INSTANCE;
public static <T> T nulled(Class<T> typeToNull) {
return nulled(typeToNull, namingScheme.defaultNameFor(typeToNull));
}
public static <T> T nulled(Class<T> typeToMock, final String name) {
@kevinpet
kevinpet / emacs.rb
Created September 25, 2011 16:34 — forked from rust/emacs.rb
Homebrew Emacs for OSX Lion with native full-screen
require 'formula'
class Emacs < Formula
url 'http://ftp.gnu.org/pub/gnu/emacs/emacs-23.3a.tar.bz2'
md5 'f2cf8dc6f28f8ae59bc695b4ddda339c'
homepage 'http://www.gnu.org/software/emacs/'
if ARGV.include? "--use-git-head"
head 'git://repo.or.cz/emacs.git'
else