Skip to content

Instantly share code, notes, and snippets.

Area of difficulty: coding a class constructor, initially anticipating two constructor arguments, then realising that an extra argument is needed.

Example: TDD of a class to encapsulate forename and surname.

Prior vision: an immutable class with two constructor arguments: forename and surname, public read-only property for each of these.

Up to the point where I realised I wanted another constructor argument, I found TDD of this straightforward:

Iteration 1: test that, after construction, the read-only Forename property returns the correct value. By the end of this iteration, the class constructor with both arguments has been coded, but the surname argument is not yet used. I got the test to initially fail by not assigning the Forename value.

### Keybase proof
I hereby claim:
* I am mcsnootch on github.
* I am mcsnootch (https://keybase.io/mcsnootch) on keybase.
* I have a public key ASC-Co5EhBlQwmR0AkU-ybaPQCsYktsFcum170iv8_dEkQo
To claim this, I am signing this object:
#!/bin/bash
netloc=$(/usr/sbin/scselect 2>&1 | egrep '^ \*' | sed 's:.*(\(.*\)):\1:')
http_proxy=$(egrep "${netloc}[ \t]*=" ~/.http_proxies | sed 's/.*=[ \t]*\(.*\)/\1/')
if [ -n "$http_proxy" ]; then
export http_proxy
export HTTP_PROXY="$http_proxy"
export HTTPS_PROXY="$http_proxy"
awk '$9 ~ /500/{time=substr($4,11,5); times[time]++}END{for(t in times){print t" "times[t]}}' /logs/live_dc*/liveapp*/jetty_logs/cadmium.request.2012_12_19.log | sort
{"AssetID":"-2147482872","CategoryCopyText":"Driving Technology","CategoryOrder":"1","RelatesToCopyText":"","AssetCopyHeading":"Dual-range transfer box","AssetCopyText":"Whether Defender is towing, climbing or driving off-road, control of engine Torque is provided through a robust dual-range transfer box. This gives drivers more control and the flexibility of twelve forward and two reverse gears.","Price":"","VATIncluded":"0","FittingPrice":"","FittingIncluded":"0","Priority":"","FileName":"-2147482872_EN_Standard_1024.jpg","Path_URL":"http://mars.2ndbyte.com.krusty/LR/LandRover_2009/EN/" },
@mcsnootch
mcsnootch / gist:1388269
Created November 23, 2011 09:27
visitor example
import org.junit.Test;
public class TestDispatching {
public void renderVehicleNoVisit( Vehicle vehicle ) {
if( vehicle instanceof Car ) {
Car car = (Car) vehicle;
System.out.println( car.getMake() + " car " + car.getTaxBand() );
@mcsnootch
mcsnootch / gist:1165830
Last active September 26, 2015 22:07
median in awk
function median(vectorOfValues) {
asort(vectorOfValues,tempVector);
countOfValues = length(tempVector);
if (countOfValues % 2) {
return tempVector[(countOfValues+1)/2];
} else {
return (tempVector[countOfValues/2+1]+tempVector[countOfValues/2])/2.0;
}
}
@mcsnootch
mcsnootch / gist:1151597
Created August 17, 2011 14:11
awk to get total requests per minute, for stock, by server
awk '$7 ~ /stock/ { servertime = substr(FILENAME,13,10)" "substr($4, 14,5); total[servertime]++} END{ for ( minute in total ){ print minute" "total[minute]};}' live_dc1*/liveapp{230,231,260,261}/apache2_logs/Mercury-uk_access.log | sort | less