Search And Destroy

Look out honey, ’cause I’m using technology!

Archive for December, 2009

My Favourite Programming Language Feature

Posted by kilfour on December 29, 2009

Higher Order Functions

Higher Order Functions.

Posted in My Favourite | Leave a Comment »

My Favourite Vegetable

Posted by kilfour on December 27, 2009

The Jalapeño Pepper.

Very un-christmas-like I know, but I’m enjoying it thouroughly right now anyway.

Posted in My Favourite, Rants | Leave a Comment »

Mr. Bad Example

Posted by kilfour on December 27, 2009

System under test :

public class BugHouse
{
    private int count;
    public bool Run(int a)
    {
        if (count++ >= 3 && a == 6)
            throw new Exception();
        return true;
    }
}

The AcidTest :
public class UsingGenerator : AcidTest
{
    static BugHouse bugHouse;
    public override void Setup()
    {
        bugHouse = new BugHouse();
    }

    class BugRun : MetaTransition<int, bool>
    {
        public BugRun()
        {
            Generator = new IntGenerator(0, 20);
            Execute = input => bugHouse.Run(input);
        }
    }

    [SpecFor(typeof(BugRun))]
    public Spec ShrinksIrrelevantInput(int input, bool output)
    {
        return new Spec(() => Ensure.True(output));
    }
}

The Output :
—— Test started: Assembly: QuickNet.Example.dll ——

TestCase ‘BugRun ShrinksIrrelevantInput’ failed: System.Exception : Exception of type ‘System.Exception’ was thrown.
D:\DotNetDev\QN\QuickNet.Example\SimpleTransitionShrinking.cs(16,0): at QuickNet.Example.BugHouse.Run(Int32 a)
D:\DotNetDev\QN\QuickNet.Example\SimpleTransitionShrinking.cs(58,0): at QuickNet.Example.UsingGenerator.BugRun.b__3(Int32 input)
D:\DotNetDev\QN\QuickNet\Transition.cs(55,0): at QuickNet.Transition`2.PerformTransition(TestRunReport report)

Output from BugRun ShrinksIrrelevantInput:
———————————————————-
BugRun ShrinksIrrelevantInput
Falsifiable after 1 test(s), 40 Transition(s).
——————–Simplest Fail Case——————–
Transition : BugRun, Output : True
Transition : BugRun, Output : True
Transition : BugRun, Output : True
Transition : BugRun, Output : True
6
———————————————————-

Posted in Property Based Testing, QuickNet | 2 Comments »

You’d Go West and I’d Go East

Posted by kilfour on December 25, 2009

Interest in QuickNet seems to have picked up.

Follow this link for another example of what property based testing can do for you.

I’m on my well-deserved holliday now, in fact I was forbidden to enter the office in the next two weeks by my project-manager. Hence you can expect a next quicknet release early next year, and I’m working on an example app, which should lower the learning curve. Documentation is also ‘under construction’. I usually handle this requirement through tests. Some kind of parsing turning tests into html doc. This approach is just not working for quicknet. Still looking, but it’s number one on the todo list, so either I’ll come up with something soon or otherwise I’ll just resort to the ‘old-fashioned’ way of producing doc.

On a more personal note, normally my yearly winter-depression hits sometime october, rendering me totally useless and very unpleasant to talk too. This year, probably due to not having the time to think about anything else than machine related problems, it arrived quite late. But it hit with a vengeance.
I’m particulary disturbed by the fact that a well layed out plan to assault mankind with some heart-tearing sounds failed. And I have no idea why. And no interest in finding out, as I’m tired of having to defend sincerity.
This made one particular day slightly less grim.

Posted in Rants | Leave a Comment »

To See What I Could See

Posted by kilfour on December 22, 2009

I’ve been asked about the documentation for QuickNet, and I have to admit that this blog is it. The example I suplied on google code probably does not make things a lot clearer, and even the examples in the source code in the trunk might be a bit bewildering without further explanation.

In a couple of days I’m going on a much needed holiday, during which I had planned doing some work on quicknet and also on the Agatha tests, as the latter will surely lead.to improvements to quicknet. Some of which are already in ‘experimental’ use.

As there have been a few downloads, some remarks about incomprehensibility, and the odd request for explanations, getting some sort of documentation out of the door has moved up the list.

As an early response to a question posed in the comments :
‘Is there a blog post which describes the relationship of the parameters that is passed between the Specs, MetaTransitions and the actual tests?’

Not as such, but this one contains a toy example (as the spec does not really ensure much) that kind of does.

The first example uses the ‘old’ syntax where everything is defined as a function. In this, it is clear that a specific Spec is registered to a specific transition. The first paragraph in the post describes the way a test is run.

Revisiting :
The transition :

new MetaTransition<Root, int>
{
    Generator = new RootGenerator(),
    Execute = i => i.DivideByMyItemSomething()
}

The generic type parameters of the transition respectively define input and output type. Root is a user defined class and int is, well an int.
When a transition is executed, quicknet can generate input in one of two ways. In this case we supplied a generator, so quicknet will call Generator.GetRandomValue() to obtain input.
In case writing a generator is too difficult, or too much work, there is also the possibility of defining a function for the purpose of supplying input. Above transition for example, could be rewritten as :

new MetaTransition<Root, int>
{
    GenerateInput = new RootGenerator().GetRandomValue(),
    Execute = i => i.DivideByMyItemSomething()
}

By using the Generator however, we give quicknet the possibility to ‘shrink’ the input when it looks for the simplest possible fail case. Using GenerateInput only the transition list is simplified.

This generated input is then passed to the Execute function, (the ‘i’ in above snippet) and the execute function returns some output, again in above snippet, an int, the result of the Root.DivideByMyItemSomething() method.

It is this input/output pair that is passed to all the specs that are registered on the transition everytime the transition is executed.

A ‘Spec registration’, again in the first example, is actually a lambda expression passed to the RegisterSpec function of the transition, f.i. :

(input, output) => new Spec("ShouldJustPass", () => Ensure.IsTrue(true))))

The second example of the post shows the ‘new’-er syntax.
It behaves exactly the same as the first, only now we’ve broken up the test run definition in different methods and the SpecFor attributes defines which transition this particular Spec is for. This way of writing has turned out to be much more usuable in large tests, even though nostalgia and an inherent love for all things functional makes me like the first one aswell.

Posted in QuickNet | Leave a Comment »

Keep Away From Children

Posted by kilfour on December 16, 2009

Earlier today I was running out of disk space on the c drive of our build server as it seems to have a ridiculously small system partition.
Not a problem for me really as TeamCity is deployed on another drive and it runs just fine without messing with the c drive.
I started looking for stuff I could delete and couldn’t find too much except some TFS related stuff, I asked around if I could delete this or whether it was still being used. Nobody could give me a conclusive answer, but all I asked came back with an ‘I don’t think so’.

When I said : ‘I’ll just delete it then’, they screamed : ‘No please don’t, we’ll never get it configured correctly again if it turns out we still need it !’

To me this sounded like the most compelling reason I have ever heard to remove the ‘ken thing entirely, and never use it again.

Posted in Rants | Leave a Comment »

Baby I Have Been Here Before

Posted by kilfour on December 14, 2009

Hallelujah
‘The fourth, the fifth
The minor fall, the major lift’
Most likely everybody’s favourite Leonard Cohen song, even of those that have never heard about this ‘Beautifull Loser’.
Jeff Buckley made it famous.

Worms Make Their Cruel Design
‘Saying d-i-e into her skin’
The Birthday Party : Deep in the Woods
Must be the wintertime. I seem to be listening to the more darker songs in my collection these days.

Shivers
Written by Rowland S Howard, his guitar playing on the Birthday Party stuff has influenced more people than you can imagine.
This song originally appeared on the first, and as far as I know only, recording of The Boys Next Door, featuring amongst others Nick Cave and Rowland S. Howard. They would later turn into The Birthday Party and change musical history. These days they are known as The Bad Seeds.
Rowland S. Howard never made it into the bad seeds. He released an album earlier this year in an attempt to escape the clutches of poverty and raise enough money for some badly needed medical attention as he is suffering from liver cancer.

I Misunderstood
Richard Thompson
My favourite solo artist. I saw him do a gig with just an acoustic guitar and I rate it in my top ten experiences of all time. Being a musician myself, I know how hard that is to pull off, having no band to hide your mistakes behind and all. Probably the best guitarist I’ve seen when it boils down to doing everything yourself, a wicked singer (even though he does not possess the natural gift of a golden voice) and an utterly amazing songwriter.

The Murder Mistery
V.U. : from their nameless third album, although it’s still a great record I think John Cale was sadly missed on that one.

Different Colors Made of Tears
V.U. : Venus in Furs
Probably my all-time favourite.
Likely the song that made me pick up a guitar, and definitely the song that made me look for violin players to jam with.

You Better Hit Her
Again V.U. : There She Goes Again.
I felt pretty clever after coming up with this title.

I Could Sleep For a Thousand Years
Again V.U. : Again Venus in Furs

Go Check
… if I’m alive. Go Check … if I’m on fire…
Ms. John Soda.
Wicked band, wicked song.

Is That All There Is
Written by Jerry Leiber and Mike Stoller.
First recorded by Dan Daniels. Peggy Lee made it famous. PJ Harvey ruined it a bit.
Very existentialistic.

I Woke Up With a Word in My Head
Camper Van Beethoven : Seven Languages.
You should all love Camper … or Step Away…

a + a = b
Console : Reset the Preset is turning out to be one of my favourite CD’s.

I’ll be Your Mirror
V.U. : One of Nico’s moments of glory. I’ve seen her do it live on more than one occasion and everytime it broke my heart.
I saw one of her last gigs, as she fell of her bike shortly thereafter and suffered a brain hemorrhage. It was a double billing with John Cale and she joined him on stage for the last couple of songs giving me the thrill of a lifetime. I’m … waiting for my man…

Posted in Looking Back, Music | Leave a Comment »

Worms Make Their Cruel Design

Posted by kilfour on December 14, 2009

Or :

How to Hide a Switch

private void ValidateCheckAndApply_Step1(int InitialMLTC, int FinalMLTC)
{
    //----
    if (ApplyTab[(int)MldOperations.DetachTheReusedLabel, FinalMLTC, InitialMLTC])
        ReusedMaterialLabel = null;
}

bool[, ,] ApplyTab = new bool[9, 3, 4];
private void SetApplyTab()
{
    for (int a = 0; a < 9; a++)
        for (int b = 0; b < 3; b++)
            for (int c = 0; c < 4; c++)
            {
                ApplyTab[a, b, c] = false;
            }

    ApplyTab[
        (int)MldOperations.CheckForAReusedLabel,
        (int)FinalLabelTypeCodes.Reusing,
        (int)InitialLabelTypeCodes.Normal] = true;
    ApplyTab[
        (int)MldOperations.CheckForAReusedLabel,
        (int)FinalLabelTypeCodes.Reusing,
        (int)InitialLabelTypeCodes.Automatic] = true;
    ApplyTab[
        (int)MldOperations.CheckForAReusedLabel,
        (int)FinalLabelTypeCodes.Reusing,
        (int)InitialLabelTypeCodes.New] = true;


    ApplyTab[
        (int)MldOperations.DetachTheReusedLabel,
        (int)FinalLabelTypeCodes.Normal,
        (int)InitialLabelTypeCodes.Reusing] = true;
    ApplyTab[
        (int)MldOperations.DetachTheReusedLabel,
        (int)FinalLabelTypeCodes.Automatic,
        (int)InitialLabelTypeCodes.Reusing] = true;


    ApplyTab[
        (int)MldOperations.AttachTheReusedLabelAndInheritContext,
        (int)FinalLabelTypeCodes.Reusing,
        (int)InitialLabelTypeCodes.Normal] = true;
    ApplyTab[
        (int)MldOperations.AttachTheReusedLabelAndInheritContext,
        (int)FinalLabelTypeCodes.Reusing,
        (int)InitialLabelTypeCodes.Automatic] = true;
    ApplyTab[
        (int)MldOperations.AttachTheReusedLabelAndInheritContext,
        (int)FinalLabelTypeCodes.Reusing,
        (int)InitialLabelTypeCodes.Reusing] = true;
    ApplyTab[
        (int)MldOperations.AttachTheReusedLabelAndInheritContext,
        (int)FinalLabelTypeCodes.Reusing,
        (int)InitialLabelTypeCodes.New] = true;


    ApplyTab[
        (int)MldOperations.DetachTheIssueCodeWeekOfOfferDetail,
        (int)FinalLabelTypeCodes.Reusing,
        (int)InitialLabelTypeCodes.Normal] = true;
    ApplyTab[
        (int)MldOperations.DetachTheIssueCodeWeekOfOfferDetail,
        (int)FinalLabelTypeCodes.Reusing,
        (int)InitialLabelTypeCodes.Automatic] = true;
    ApplyTab[
        (int)MldOperations.DetachTheIssueCodeWeekOfOfferDetail,
        (int)FinalLabelTypeCodes.Reusing,
        (int)InitialLabelTypeCodes.Reusing] = true;


    ApplyTab[
        (int)MldOperations.DetachThePickUpLabel,
        (int)FinalLabelTypeCodes.Reusing,
        (int)InitialLabelTypeCodes.Normal] = true;
    ApplyTab[
        (int)MldOperations.DetachThePickUpLabel,
        (int)FinalLabelTypeCodes.Reusing,
        (int)InitialLabelTypeCodes.Automatic] = true;
    ApplyTab[
        (int)MldOperations.DetachThePickUpLabel,
        (int)FinalLabelTypeCodes.Reusing,
        (int)InitialLabelTypeCodes.Reusing] = true;


    ApplyTab[
        (int)MldOperations.AttachThePickUpLabel,
        (int)FinalLabelTypeCodes.Normal,
        (int)InitialLabelTypeCodes.Normal] = true;
    ApplyTab[
        (int)MldOperations.AttachThePickUpLabel,
        (int)FinalLabelTypeCodes.Normal,
        (int)InitialLabelTypeCodes.Automatic] = true;
    ApplyTab[
        (int)MldOperations.AttachThePickUpLabel,
        (int)FinalLabelTypeCodes.Normal,
        (int)InitialLabelTypeCodes.Reusing] = true;
    ApplyTab[
        (int)MldOperations.AttachThePickUpLabel,
        (int)FinalLabelTypeCodes.Normal,
        (int)InitialLabelTypeCodes.New] = true;
    ApplyTab[
        (int)MldOperations.AttachThePickUpLabel,
        (int)FinalLabelTypeCodes.Automatic,
        (int)InitialLabelTypeCodes.Normal] = true;
    ApplyTab[
        (int)MldOperations.AttachThePickUpLabel,
        (int)FinalLabelTypeCodes.Automatic,
        (int)InitialLabelTypeCodes.Automatic] = true;
    ApplyTab[
        (int)MldOperations.AttachThePickUpLabel,
        (int)FinalLabelTypeCodes.Automatic,
        (int)InitialLabelTypeCodes.Reusing] = true;
    ApplyTab[
        (int)MldOperations.AttachThePickUpLabel,
        (int)FinalLabelTypeCodes.Automatic,
        (int)InitialLabelTypeCodes.New] = true;


    ApplyTab[
        (int)MldOperations.ImpactIssueWeekCodeAssignments,
        (int)FinalLabelTypeCodes.Automatic,
        (int)InitialLabelTypeCodes.Normal] = true;
    ApplyTab[
        (int)MldOperations.ImpactIssueWeekCodeAssignments,
        (int)FinalLabelTypeCodes.Automatic,
        (int)InitialLabelTypeCodes.Reusing] = true;

    for (int b = 0; b < 3; b++)
        for (int c = 0; c < 4; c++)
        {
            ApplyTab[(int)MldOperations.LogicalLabelGroupingIsLeftAsIs, b, c] = true;
        }


    ApplyTab[
        (int)MldOperations.NoChangeToMaterialLabelContextAndIssueWeekCodeAssignments,
        (int)FinalLabelTypeCodes.Normal,
        (int)InitialLabelTypeCodes.Normal] = true;
    ApplyTab[
        (int)MldOperations.NoChangeToMaterialLabelContextAndIssueWeekCodeAssignments,
        (int)FinalLabelTypeCodes.Normal,
        (int)InitialLabelTypeCodes.Automatic] = true;
    ApplyTab[
        (int)MldOperations.NoChangeToMaterialLabelContextAndIssueWeekCodeAssignments,
        (int)FinalLabelTypeCodes.Normal,
        (int)InitialLabelTypeCodes.Reusing] = true;
    ApplyTab[
        (int)MldOperations.NoChangeToMaterialLabelContextAndIssueWeekCodeAssignments,
        (int)FinalLabelTypeCodes.Normal,
        (int)InitialLabelTypeCodes.New] = true;
    ApplyTab[
        (int)MldOperations.NoChangeToMaterialLabelContextAndIssueWeekCodeAssignments,
        (int)FinalLabelTypeCodes.Automatic,
        (int)InitialLabelTypeCodes.Normal] = true;
    ApplyTab[
        (int)MldOperations.NoChangeToMaterialLabelContextAndIssueWeekCodeAssignments,
        (int)FinalLabelTypeCodes.Automatic,
        (int)InitialLabelTypeCodes.Automatic] = true;
    ApplyTab[
        (int)MldOperations.NoChangeToMaterialLabelContextAndIssueWeekCodeAssignments,
        (int)FinalLabelTypeCodes.Automatic,
        (int)InitialLabelTypeCodes.Reusing] = true;
    ApplyTab[
        (int)MldOperations.NoChangeToMaterialLabelContextAndIssueWeekCodeAssignments,
        (int)FinalLabelTypeCodes.Automatic,
        (int)InitialLabelTypeCodes.New] = true;
}

Notice the ‘ValidateCheckAndApply_Step1′ function… There’s another six similar ones, all equally creatively named.

I usually don’t post production code but in this case you can have it … for free. And if you can figure out what it does, please tell me.

Posted in Rants | 3 Comments »

Shivers

Posted by kilfour on December 13, 2009

Using one of the most favourite tricks in the bloggers bag of … erm … tricks :

Which one do you prefer ?
The Boys Next Door
or :
Rowland Stuart Howard

;-)

Posted in Music | 3 Comments »

I Misunderstood

Posted by kilfour on December 12, 2009

Is All This QuickNet Stuff Too Hard To Read ?

Yep, that’s the question, see the previous post and feel (very) free to share your thoughts.

Let’s think back to one of the reasons why I wrote this. I don’t like duplicate code, not even in tests.
Refactoring tests however can lead to obfuscation.
A simple extract method on a test can lead to more than one test to fail making it harder to track down the problem, whereas if you duplicated the code, unit tests tend to pin down the bug with impunity.
But I still don’t like it.
So I came up with a pattern that avoids this issue. Actually I stole that pattern from QuickCheck, but according to Picasso : ‘Good artists copy, great artists steal’.
Still, it seems quite hard to grasp, even for me at times, and I wrote/copied/stole the ‘ken thing.

It reminds me of a lot of conversations that I’ve had in the past where I had to explain something that by now is so intuitive to me as f.i. the Command Pattern to somebody who had never thought about it. They always said (and still do on occasion) that what I was doing was unnecessarily complicating things untill they grasped the pattern and then appreciated how it actually simplified things.
In a distant past I even was forced to discuss the usuability of OOP. Something a lot of you probably take for granted by now.

I consider myself an early adopter and maybe even an innovator on the innovation adoption curve of Rogers. There’s no value judgement in that statement, everybody plays their part and I’ve been wrong and/or too early on previous occasions.
Although I must admit I have very little patience for ‘Laggards’.

On the matter of property based testing however, I am convinced that it will turn out to be the next-generation of automated testing, even if QuickNet fails to deliver, there will be a lib that does.

As stated : that’s the question, and feel (very) free to share your thoughts. In particular any suggestions on how to improve readability are more than welcome.

Posted in Rants | 2 Comments »

 
Follow

Get every new post delivered to your Inbox.