Skip to content

Instantly share code, notes, and snippets.

@gregoryyoung
gregoryyoung / gist:826331
Created February 14, 2011 18:46
How to make this an ellipse with 2 chars in it?
var ellipse = new Ellipse
{
Fill = Brushes.Red,
StrokeThickness = 2,
Stroke = Brushes.Black,
Height = _glyphSize,
Width = _glyphSize
};
return ellipse; //its as UIElement
@gregoryyoung
gregoryyoung / gist:827744
Created February 15, 2011 16:24
set tooltip on a wpf grid?
thought this would work
ToolTip objTooltip = new ToolTip();
//set background color
objTooltip.Background = new LinearGradientBrush(Color.FromRgb(100, 120, 130),
Color.FromRgb(200, 220, 230), 0);
//Set border color
@gregoryyoung
gregoryyoung / WTF
Created February 28, 2011 17:41
GO MS GO
for (short i = 1; i <= projectItem.FileCount; i++)
{
var filename = projectItem.FileNames[i];
if (filename != null && filename.ToLower() == path) //SERIOUSLY WTF YOU TOLD ME YOU HAVE ONE AND RETURN ME NULL?
{
return projectItem;
}
}
@gregoryyoung
gregoryyoung / WTF
Created March 15, 2011 23:35
Came out of redgate ...
C:\Users\ack\src\AutoTestExtensions>"C:\Program Files\Red Gate\SmartAssembly 6\SmartAssembly.com" /build Obfuscation\Aut
oTest.VS.saproj
SmartAssembly v6.0.0.513
Copyright © Red Gate Software 2005-2011
Because I wanna ask you about your girlfriend. I must know who she is, or you would've told me her name.
System.NullReferenceException : Object reference not set to an instance of an object.
@gregoryyoung
gregoryyoung / ProbabilityKata2
Created June 10, 2011 09:51
Probability Kata part 2
OK so now you have implemented the kata. Your tests should look something like this:
We can say that the tests define the object "in a calculus of itself". They are not state based tests, they define how the behaviours of the object interact with each other.
To see the real value of this let's introduce some change ... I hear real system's do this occasionally. Because this is a high performance system decimal math is too slow. You now need to use floats instead.
Need help on floating point math? Check out: http://www-users.math.umd.edu/~jkolesar/mait613/floating_point_math.pdf
You will need to use a non-exact equality... How will this change your code?
@gregoryyoung
gregoryyoung / ProbabilityKata
Created June 10, 2011 09:56
Greg Young's Probability Kata
Value objects are an important concept in DDD. This kata is made both to learn value objects and to learn better ways of testing.
Write a probability value object. It should contain the following methods:
Probability CombinedWith(Probability)
Probability InverseOf()
Probability Either(Probability)
if you forget your probability math:
Either:P(A) + P(B) - P(A)P(B)
CombinedWith: P(A)P(B)
@gregoryyoung
gregoryyoung / Sample.cs
Created July 4, 2011 14:51
Sample Test From Simple.Testing
//This is a sample specification.
public SutSpecification<Depositor> when_withdrawing_money_from_empty_account = new SutSpecification<Depositor>
{
On = () => new Depositor(13),
When = depositor => depositor.Withdraw(50.00m),
Expect =
{
depositor => depositor.Balance > 0.01m,
depositor => depositor.AccountIsOpen
@gregoryyoung
gregoryyoung / query spec.cs
Created July 4, 2011 21:33
query specification
/*
* A query specification is intended to be used on a method with a return value. The
* general idea is that the Given() will build the SUT. The when() will call the method
* returning the methods return value. The expectations are then on the returned value.
*
* You may wonder how you can assert on the sut after the call. You can't using this
* template. This is by design, see CQS by Bertrand Meyer, you should not mutate state
* of the object when querying. If you want to break this rule use a more open template
* and specialize it.
*/
@gregoryyoung
gregoryyoung / dep.cs
Created July 4, 2011 21:33
depositor specification
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Simple.Testing.Framework;
namespace Simple.Testing.Example
{
/*
@gregoryyoung
gregoryyoung / fail.cs
Created July 4, 2011 21:34
Failing spec
/*
* Sometimes the point of a specification is to show that a given scenario fails.
*
* A failing specification is similar to a SUT specification. It will return the SUT
* from its given method. The SUT will then be passed to the when() method where some
* action will happen. It is expected that this action will throw an exception.
*
* The exception is then passed to the expectations.
*
* note: if you are doing more complex operations other templates can be used with