Skip to content

Instantly share code, notes, and snippets.

Avatar

Robert C. Martin unclebob

View GitHub Profile
View gist:526188
(ns life (:use clojure.test clojure.set))
(def under-populated 1)
(def over-populated 4)
(def fertile 3)
(defn north [[x y]] [x (inc y)])
(defn south [[x y]] [x (dec y)])
(defn east [[x y]] [(inc x) y])
(defn west [[x y]] [(dec x) y])
View PayCalculator.java
package payroll;
public class PayCalculator {
public static float calculate(double hours,
double rate,
boolean isHourlyWorker) {
if (hours < 0 || hours > 80) {
throw new RuntimeException("Hours out of range: " + hours);
}
float wages = 0;
View PayCalculatorTest.java
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static payroll.PayCalculator.calculate;
public class PayCalculatorTest {
private void assertPay(double expectedPay, double actualPay) {
assertEquals(expectedPay, actualPay, .001);
}
View PayCalculator.java
package payroll;
public class PayCalculator {
public static double calculate(double hours,
double rate,
boolean isHourlyWorker) {
if (hours < 0 || hours > 80) {
throw new RuntimeException("Hours out of range: " + hours);
}
View PayCalculator.java
package payroll;
public class PayCalculator {
private boolean isHourlyWorker;
public PayCalculator(boolean hourlyWorker) {
isHourlyWorker = hourlyWorker;
}
public double calculate(double hours, double rate) {
View ContractorCalculator.java
package payroll;
public class ContractorCalculator extends PayCalculator {
public ContractorCalculator() {
super(false);
}
}
View ContractorCalculator.java
package payroll;
public class ContractorCalculator extends PayCalculator {
public ContractorCalculator() {
super(false);
}
public double calculate(double hours, double rate) {
if (hours < 0 || hours > 80) {
throw new RuntimeException("Hours out of range: " + hours);
View ContractorCalculator.java
package payroll;
public class ContractorCalculator extends PayCalculator {
public double calculate(double hours, double rate) {
validateHours(hours);
return hours * rate;
}
}
View 1 WrapperTest.java
@RunWith(Suite.class)
@Suite.SuiteClasses({
WrapperTest.DegenerateTests.class})
public class WrapperTest {
public static class DegenerateTests {
@Test
public void emptyString() throws Exception {
assertThat(wrap("", 1), equalTo(""));
}
View 1 WrapperTest.java
@RunWith(Suite.class)
@Suite.SuiteClasses({
WrapperTest.DegenerateTests.class,
WrapperTest.wrapWordsTest.class
})
public class WrapperTest {
public static class DegenerateTests {
@Test
public void emptyString() throws Exception {
You can’t perform that action at this time.