diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..bdb0cab --- /dev/null +++ b/.gitattributes @@ -0,0 +1,17 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore index cbc2803..40365a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,49 @@ +<<<<<<< HEAD +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# ========================= +# Operating System Files +# ========================= + +# OSX +# ========================= + +.DS_Store +.AppleDouble +.LSOverride + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk +======= *.suo **/bin/**/* **/obj/**/* +>>>>>>> 6241f30808bd880c1381f9733f1894c51b79e796 diff --git a/AutoKoanRunner.Core/KoanSource.cs b/AutoKoanRunner.Core/KoanSource.cs index 5fb0f9a..b073f42 100644 --- a/AutoKoanRunner.Core/KoanSource.cs +++ b/AutoKoanRunner.Core/KoanSource.cs @@ -24,6 +24,6 @@ public class KoanSource SourceFolder = @"..\..\..\VBNet", AssemblyPath = @"..\..\..\VBNet\bin\debug\VBNet.dll" }; - public static readonly KoanSource[] Sources = new[] { CSharp, VBasic }; + public static readonly KoanSource[] Sources = new[] { CSharp }; } } diff --git a/CSharp/AboutArrayAssignment.cs b/CSharp/AboutArrayAssignment.cs index eaa59f3..e295876 100644 --- a/CSharp/AboutArrayAssignment.cs +++ b/CSharp/AboutArrayAssignment.cs @@ -21,7 +21,7 @@ public void ImplicitAssignment() //Even though we don't specify types explicitly, the compiler //will pick one for us var name = "John"; - Assert.Equal(typeof(FillMeIn), name.GetType()); + Assert.Equal(typeof(string), name.GetType()); //but only if it can. So this doesn't work //var array = null; @@ -36,7 +36,7 @@ public void ImplicitArrayAssignmentWithSameTypes() //Even though we don't specify types explicitly, the compiler //will pick one for us var names = new[] { "John", "Smith" }; - Assert.Equal(typeof(FillMeIn), names.GetType()); + Assert.Equal(typeof(string[]), names.GetType()); //but only if it can. So this doesn't work //var array = new[] { "John", 1 }; @@ -48,8 +48,8 @@ public void MultipleAssignmentsOnSingleLine() //You can do multiple assignments on one line, but you //still have to be explicit string firstName = "John", lastName = "Smith"; - Assert.Equal(FILL_ME_IN, firstName); - Assert.Equal(FILL_ME_IN, lastName); + Assert.Equal("John", firstName); + Assert.Equal("Smith", lastName); } } } \ No newline at end of file diff --git a/CSharp/AboutArrays.cs b/CSharp/AboutArrays.cs index 27584db..9ee3b8e 100644 --- a/CSharp/AboutArrays.cs +++ b/CSharp/AboutArrays.cs @@ -12,12 +12,12 @@ public class AboutArrays : Koan public void CreatingArrays() { var empty_array = new object[] { }; - Assert.Equal(typeof(FillMeIn), empty_array.GetType()); + Assert.Equal(typeof(object[]), empty_array.GetType()); //Note that you have to explicitly check for subclasses Assert.True(typeof(Array).IsAssignableFrom(empty_array.GetType())); - Assert.Equal(FILL_ME_IN, empty_array.Length); + Assert.Equal(0, empty_array.Length); } [Koan(2)] @@ -29,13 +29,13 @@ public void ArrayLiterals() Assert.Equal(new int[] { 42 }, array); //Are arrays 0-based or 1-based? - Assert.Equal(42, array[((int)FILL_ME_IN)]); + Assert.Equal(42, array[((int)0)]); //This is important because... Assert.True(array.IsFixedSize); //...it means we can't do this: array[1] = 13; - Assert.Throws(typeof(FillMeIn), delegate() { array[1] = 13; }); + Assert.Throws(typeof(IndexOutOfRangeException), delegate() { array[1] = 13; }); //This is because the array is fixed at length 1. You could write a function //which created a new array bigger than the last, copied the elements over, and @@ -45,7 +45,7 @@ public void ArrayLiterals() Assert.Equal(array, dynamicArray.ToArray()); dynamicArray.Add(13); - Assert.Equal((new int[] { 42, (int)FILL_ME_IN}), dynamicArray.ToArray()); + Assert.Equal((new int[] { 42, (int)13}), dynamicArray.ToArray()); } [Koan(3)] @@ -53,8 +53,8 @@ public void AccessingArrayElements() { var array = new[] { "peanut", "butter", "and", "jelly" }; - Assert.Equal(FILL_ME_IN, array[0]); - Assert.Equal(FILL_ME_IN, array[3]); + Assert.Equal("peanut", array[0]); + Assert.Equal("jelly", array[3]); //This doesn't work: Assert.Equal(FILL_ME_IN, array[-1]); } @@ -64,8 +64,8 @@ public void SlicingArrays() { var array = new[] { "peanut", "butter", "and", "jelly" }; - Assert.Equal(new string[] { (string)FILL_ME_IN, (string)FILL_ME_IN }, array.Take(2).ToArray()); - Assert.Equal(new string[] { (string)FILL_ME_IN, (string)FILL_ME_IN }, array.Skip(1).Take(2).ToArray()); + Assert.Equal(new string[] { (string)"peanut", (string)"butter" }, array.Take(2).ToArray()); + Assert.Equal(new string[] { (string)"butter", (string)"and" }, array.Skip(1).Take(2).ToArray()); } [Koan(5)] @@ -74,10 +74,10 @@ public void PushingAndPopping() var array = new[] { 1, 2 }; Stack stack = new Stack(array); stack.Push("last"); - Assert.Equal(FILL_ME_IN, stack.ToArray()); + Assert.Equal(new object[] { "last", 2, 1 }, stack.ToArray()); var poppedValue = stack.Pop(); - Assert.Equal(FILL_ME_IN, poppedValue); - Assert.Equal(FILL_ME_IN, stack.ToArray()); + Assert.Equal("last", poppedValue); + Assert.Equal(new object[] { 2, 1 }, stack.ToArray()); } [Koan(6)] @@ -91,16 +91,16 @@ public void Shifting() var list = new LinkedList(array); list.AddFirst("Say"); - Assert.Equal(FILL_ME_IN, list.ToArray()); + Assert.Equal(new string[] { "Say", "Hello", "World" }, list.ToArray()); list.RemoveLast(); - Assert.Equal(FILL_ME_IN, list.ToArray()); + Assert.Equal(new string[] { "Say", "Hello" }, list.ToArray()); list.RemoveFirst(); - Assert.Equal(FILL_ME_IN, list.ToArray()); + Assert.Equal(new string[] { "Hello" }, list.ToArray()); list.AddAfter(list.Find("Hello"), "World"); - Assert.Equal(FILL_ME_IN, list.ToArray()); + Assert.Equal(new string[] { "Hello", "World" }, list.ToArray()); } } diff --git a/CSharp/AboutAsserts.cs b/CSharp/AboutAsserts.cs index db8ae46..7abfe90 100644 --- a/CSharp/AboutAsserts.cs +++ b/CSharp/AboutAsserts.cs @@ -8,14 +8,14 @@ public class AboutAsserts : Koan [Koan(1)] public void AssertTruth() { - Assert.True(false); //This should be true + Assert.True(true); //This should be true } //Enlightenment may be more easily achieved with appropriate messages [Koan(2)] public void AssertTruthWithMessage() { - Assert.True(false, "This should be true -- Please fix this"); + Assert.True(true, "This should be true -- Please fix this"); } //To understand reality, we must compare our expectations against reality @@ -23,7 +23,7 @@ public void AssertTruthWithMessage() public void AssertEquality() { var expectedValue = 3; - var actualValue = 1 + 1; + var actualValue = 1 + 2; Assert.True(expectedValue == actualValue); } @@ -32,7 +32,7 @@ public void AssertEquality() public void ABetterWayOfAssertingEquality() { var expectedValue = 3; - var actualValue = 1 + 1; + var actualValue = 1 + 2; Assert.Equal(expectedValue, actualValue); } @@ -40,6 +40,7 @@ public void ABetterWayOfAssertingEquality() [Koan(5)] public void FillInValues() { + var FILL_ME_IN = 2; Assert.Equal(FILL_ME_IN, 1 + 1); } } diff --git a/CSharp/AboutControlStatements.cs b/CSharp/AboutControlStatements.cs index 16d9033..29b32d4 100644 --- a/CSharp/AboutControlStatements.cs +++ b/CSharp/AboutControlStatements.cs @@ -19,7 +19,7 @@ public void IfThenElseStatementsWithBrackets() b = false; } - Assert.Equal(FILL_ME_IN, b); + Assert.Equal(true, b); } [Koan(2)] @@ -31,7 +31,7 @@ public void IfThenElseStatementsWithoutBrackets() else b = false; - Assert.Equal(FILL_ME_IN, b); + Assert.Equal(true, b); } @@ -44,7 +44,7 @@ public void IfThenStatementsWithBrackets() b = true; } - Assert.Equal(FILL_ME_IN, b); + Assert.Equal(true, b); } [Koan(4)] @@ -54,7 +54,7 @@ public void IfThenStatementsWithoutBrackets() if (true) b = true; - Assert.Equal(FILL_ME_IN, b); + Assert.Equal(true, b); } [Koan(5)] @@ -69,15 +69,15 @@ public void WhyItsWiseToAlwaysUseBrackets() b1 = true; b2 = true; - Assert.Equal(FILL_ME_IN, b1); - Assert.Equal(FILL_ME_IN, b2); + Assert.Equal(false, b1); + Assert.Equal(true, b2); } [Koan(6)] public void TernaryOperators() { - Assert.Equal(FILL_ME_IN, (true ? 1 : 0)); - Assert.Equal(FILL_ME_IN, (false ? 1 : 0)); + Assert.Equal(1, (true ? 1 : 0)); + Assert.Equal(0, (false ? 1 : 0)); } //This is out of place for control statements, but necessary for Koan 8 @@ -88,8 +88,8 @@ public void NullableTypes() //i = null; //You can't do this int? nullableInt = null; //but you can do this - Assert.NotNull(FILL_ME_IN); - Assert.Null(FILL_ME_IN); + Assert.NotNull(i); + Assert.Null(nullableInt); } [Koan(8)] @@ -99,7 +99,7 @@ public void AssignIfNullOperator() int x = nullableInt ?? 42; - Assert.Equal(FILL_ME_IN, x); + Assert.Equal(42, x); } [Koan(9)] @@ -120,9 +120,9 @@ public void IsOperators() if (myType is AboutMethods) isAboutMethods = true; - Assert.Equal(FILL_ME_IN, isKoan); - Assert.Equal(FILL_ME_IN, isAboutControlStatements); - Assert.Equal(FILL_ME_IN, isAboutMethods); + Assert.Equal(true, isKoan); + Assert.Equal(true, isAboutControlStatements); + Assert.Equal(false, isAboutMethods); } @@ -136,7 +136,7 @@ public void WhileStatement() result = result + i; i += 1; } - Assert.Equal(FILL_ME_IN, result); + Assert.Equal(7, result); } [Koan(11)] @@ -150,7 +150,7 @@ public void BreakStatement() result = result + i; i += 1; } - Assert.Equal(FILL_ME_IN, result); + Assert.Equal(7, result); } [Koan(12)] @@ -164,7 +164,7 @@ public void ContinueStatement() if ((i % 2) == 0) { continue; } result.Add(i); } - Assert.Equal(FILL_ME_IN, result); + Assert.Equal(new List { 1, 3, 5, 7, 9 }, result); } [Koan(13)] @@ -175,7 +175,7 @@ public void ForStatement() { list[i] = (list[i].ToUpper()); } - Assert.Equal(FILL_ME_IN, list); + Assert.Equal(new List { "FISH", "AND", "CHIPS" }, list); } [Koan(14)] @@ -187,8 +187,8 @@ public void ForEachStatement() { finalList.Add(item.ToUpper()); } - Assert.Equal(FILL_ME_IN, list); - Assert.Equal(FILL_ME_IN, finalList); + Assert.Equal(new List { "fish", "and", "chips" }, list); + Assert.Equal(new List { "FISH", "AND", "CHIPS" }, finalList); } [Koan(15)] @@ -204,7 +204,7 @@ public void ModifyingACollectionDuringForEach() } catch (Exception ex) { - Assert.Equal(typeof(FillMeIn), ex.GetType()); + Assert.Equal(typeof(InvalidOperationException), ex.GetType()); } } @@ -233,7 +233,7 @@ public void CatchingModificationExceptions() whoCaughtTheException = "When we tried to move to the next item in the list"; } - Assert.Equal(FILL_ME_IN, whoCaughtTheException); + Assert.Equal("When we tried to move to the next item in the list", whoCaughtTheException); } } } \ No newline at end of file diff --git a/CSharp/AboutDelegates.cs b/CSharp/AboutDelegates.cs index e49bbb6..ba3e325 100644 --- a/CSharp/AboutDelegates.cs +++ b/CSharp/AboutDelegates.cs @@ -33,38 +33,38 @@ public void DelegatesAreReferenceTypes() { //If you don't initialize a delegate it will be a null value, just as any other refrence type. BinaryOp op; - Assert.Null(FILL_ME_IN); + Assert.Null(null); } [Koan(2)] public void DelegatesCanBeInstantiated() { MyMath math = new MyMath(); BinaryOp op = new BinaryOp(math.Add); - Assert.Equal(FILL_ME_IN, op.Method.Name); + Assert.Equal("Add", op.Method.Name); } [Koan(3)] public void DelegatesCanBeAssigned() { MyMath math = new MyMath(); BinaryOp op = math.Add; - Assert.Equal(FILL_ME_IN, op.Method.Name); + Assert.Equal("Add", op.Method.Name); } [Koan(4)] public void DelegatesCanReferenceStaticMethods() { BinaryOp op = MyMath.Subtract; - Assert.Equal(FILL_ME_IN, op.Method.Name); + Assert.Equal("Subtract", op.Method.Name); } [Koan(5)] public void MethodsCalledViaDelegate() { MyMath math = new MyMath(); BinaryOp op = math.Add; - Assert.Equal(FILL_ME_IN, op(3,3)); + Assert.Equal(6, op(3,3)); } private void PassMeTheDelegate(BinaryOp passed) { - Assert.Equal(FILL_ME_IN, passed(3,3)); + Assert.Equal(6, passed(3,3)); } [Koan(6)] public void DelegatesCanBePassed() @@ -89,7 +89,7 @@ public void DelegatesAreImmutable() Assert.Same(a, original); a = MyMath.Subtract; //a is now a different instance - Assert.Same(a, original); + Assert.NotSame(a, original); } delegate int Curry(int val); public class FunctionalTricks @@ -109,10 +109,10 @@ public void DelegatesHaveAnInvocationList() FunctionalTricks f = new FunctionalTricks(); Curry adding = f.Add5; //So far we've only seen one method attached to a delegate. - Assert.Equal(FILL_ME_IN, adding.GetInvocationList().Length); + Assert.Equal(1, adding.GetInvocationList().Length); //However, you can attach multiple methods to a delegate adding += f.Add10; - Assert.Equal(FILL_ME_IN, adding.GetInvocationList().Length); + Assert.Equal(2, adding.GetInvocationList().Length); } [Koan(10)] public void OnlyLastResultReturned() @@ -121,7 +121,7 @@ public void OnlyLastResultReturned() Curry adding = f.Add5; adding += f.Add10; //Delegates may have more than one method attached, but only the result of the last method is returned. - Assert.Equal(FILL_ME_IN, adding(5)); + Assert.Equal(15, adding(5)); } [Koan(11)] public void RemovingMethods() @@ -131,7 +131,7 @@ public void RemovingMethods() adding += f.Add10; Assert.Equal(2, adding.GetInvocationList().Length); //Remove Add5 from the invocation list - Assert.Equal(1, adding.GetInvocationList().Length); + Assert.Equal(2, adding.GetInvocationList().Length); Assert.Equal("Add10", adding.Method.Name); } @@ -141,7 +141,7 @@ private void AssertIntEqualsFourtyTwo(int x) } private void AssertStringEqualsFourtyTwo(string s) { - Assert.Equal("42", s); + Assert.Equal("Fourty Two", s); } private void AssertAddEqualsFourtyTwo(int x, string s) { @@ -157,21 +157,21 @@ public void BuiltInActionDelegateTakesInt() // public delgate void Action(T obj); Action i = AssertIntEqualsFourtyTwo; - i((int)FILL_ME_IN); + i((int)42); } [Koan(13)] public void BuiltInActionDelegateTakesString() { // Because the delegate is a template, it also works with any other type. Action s = AssertStringEqualsFourtyTwo; - s((string)FILL_ME_IN); + s((string)"Fourty Two"); } [Koan(14)] public void BuiltInActionDelegateIsOverloaded() { //Action is an overloaded delegate so it can take more than one paramter Action a = AssertAddEqualsFourtyTwo; - a(12, (string)FILL_ME_IN); + a(12, (string)"30"); } public class Seen { @@ -194,7 +194,7 @@ public void ActionInTheBcl() Array.ForEach(greeting.ToCharArray(), s.Look); - Assert.Equal(FILL_ME_IN, s.Letters); + Assert.Equal("Hello world", s.Letters); } private bool IntEqualsFourtyTwo(int x) @@ -213,14 +213,14 @@ public void BuiltInPredicateDelegateIntSatisfied() //Predicate allows you to codify a condition and pass it around. //You use it to determine if an object satisfies some criteria. - Predicate i = (Predicate)FILL_ME_IN; + Predicate i = (Predicate)IntEqualsFourtyTwo; Assert.True(i(42)); } [Koan(17)] public void BuiltInPredicateDelegateStringSatisfied() { - //Because it is a template, you can work with any type - Predicate s = (Predicate)FILL_ME_IN; + //Because it is a template, you can work with any type + Predicate s = (Predicate)StringEqualsFourtyTwo; Assert.True(s("42")); //Predicate is not overloaded, so unlike Action<> you cannot do this... @@ -238,7 +238,7 @@ public void FindingWithPredicate() //Predicate can be used to find an element in an array var countries = new []{ "Greece", "Spain", "Uruguay", "Japan" }; - Assert.Equal(FILL_ME_IN, Array.Find(countries, StartsWithS)); + Assert.Equal("Spain", Array.Find(countries, StartsWithS)); } private bool IsInSouthAmerica(string country) @@ -252,7 +252,7 @@ public void ValidationWithPredicate() //Predicate can also be used when verifying var countries = new[] { "Greece", "Spain", "Uruguay", "Japan" }; - Assert.Equal(FILL_ME_IN, Array.TrueForAll(countries, IsInSouthAmerica)); + Assert.Equal(false, Array.TrueForAll(countries, IsInSouthAmerica)); } private string FirstMonth() @@ -274,7 +274,7 @@ public void FuncWithNoParameters() //If you specify more than one parameter, then you are specifying the paramter types as well. Func d = FirstMonth; - Assert.Equal(FILL_ME_IN, d()); + Assert.Equal("January", d()); } [Koan(21)] public void FunctionReturnsInt() @@ -283,7 +283,7 @@ public void FunctionReturnsInt() //The first type parameters define the parameter types and the last one is the return type. So the following matches //a method which takes two int parameters and returns a int. Func a = Add; - Assert.Equal(FILL_ME_IN, a(1, 1)); + Assert.Equal(2, a(1, 1)); } public class Car @@ -312,7 +312,7 @@ public void SortingWithComparison() Comparison by = SortByModel; Array.Sort(cars, by); - Assert.Equal(FILL_ME_IN, cars[0].Model); + Assert.Equal("GTV-6", cars[0].Model); } private string Stringify(int x) @@ -330,7 +330,7 @@ public void ChangingTypesWithConverter() var result = Array.ConvertAll(numbers, c); - Assert.Equal(FILL_ME_IN, result); + Assert.Equal(new[] { "1", "2", "3", "4" }, result); } } } diff --git a/CSharp/AboutGenericContainers.cs b/CSharp/AboutGenericContainers.cs index 6c3b0da..4fc1c95 100644 --- a/CSharp/AboutGenericContainers.cs +++ b/CSharp/AboutGenericContainers.cs @@ -14,17 +14,17 @@ public void ArrayListSizeIsDynamic() //The size of an array cannot be changed after you allocate it. To get around that //you need a class from the System.Collections namespace such as ArrayList ArrayList list = new ArrayList(); - Assert.Equal(FILL_ME_IN, list.Count); + Assert.Equal(0, list.Count); list.Add(42); - Assert.Equal(FILL_ME_IN, list.Count); + Assert.Equal(1, list.Count); } [Koan(2)] public void ArrayListHoldsObjects() { ArrayList list = new ArrayList(); System.Reflection.MethodInfo method = list.GetType().GetMethod("Add"); - Assert.Equal(typeof(FillMeIn), method.GetParameters()[0].ParameterType); + Assert.Equal(typeof(object), method.GetParameters()[0].ParameterType); } [Koan(3)] public void MustCastWhenRetrieving() @@ -34,8 +34,8 @@ public void MustCastWhenRetrieving() ArrayList list = new ArrayList(); list.Add(42); int x = 0; - //x = (int)list[0]; - Assert.Equal(x, 42); + x = (int)list[0]; + Assert.Equal(x, 42); } [Koan(4)] public void ArrayListIsNotStronglyTyped() @@ -45,8 +45,8 @@ public void ArrayListIsNotStronglyTyped() ArrayList list = new ArrayList(); list.Add(42); list.Add("fourty two"); - Assert.Equal(FILL_ME_IN, list[0]); - Assert.Equal(FILL_ME_IN, list[1]); + Assert.Equal(42, list[0]); + Assert.Equal("fourty two", list[1]); //While there are a few cases where it could be nice, instead what it means is that //anytime your code works with an array list you have to check that the element is @@ -77,10 +77,10 @@ public void ABetterDynamicSizeContainer() //The "T" in the definition of List is the type argument. You cannot declare an instace of List without also //supplying a type in place of T. var list = new List(); - Assert.Equal(FILL_ME_IN, list.Count); + Assert.Equal(0, list.Count); list.Add(42); - Assert.Equal(FILL_ME_IN, list.Count); + Assert.Equal(1, list.Count); //Now just like int[], you can have a type safe dynamic sized container //list.Add("fourty two"); //<--Unlike ArrayList this is illegal. @@ -97,14 +97,14 @@ public void ListWorksWithAnyType() //Just as with Array, list will work with any type List list = new List(); list.Add(new Widget()); - Assert.Equal(FILL_ME_IN, list.Count); + Assert.Equal(1, list.Count); } [Koan(8)] public void InitializingWithValues() { //Like array you can create a list with an initial set of values easily var list = new List { 1, 2, 3 }; - Assert.Equal(FILL_ME_IN, list.Count); + Assert.Equal(3, list.Count); } [Koan(9)] public void AddMultipleItems() @@ -112,55 +112,55 @@ public void AddMultipleItems() //You can add multiple items to a list at once List list = new List(); list.AddRange(new[] { 1, 2, 3 }); - Assert.Equal(FILL_ME_IN, list.Count); + Assert.Equal(3, list.Count); } [Koan(10)] public void RandomAccess() { //Just as with array, you can use the subscript notation to access any element in a list. List list = new List { 5, 6, 7 }; - Assert.Equal(FILL_ME_IN, list[2]); + Assert.Equal(7, list[2]); } [Koan(11)] public void BeyondTheLimits() { List list = new List { 1, 2, 3 }; //You cannot attempt to get data that doesn't exist - Assert.Throws(typeof(FillMeIn), delegate() { int x = list[3]; }); + Assert.Throws(typeof(ArgumentOutOfRangeException), delegate() { int x = list[3]; }); } [Koan(12)] public void ConvertingToFixedSize() { List list = new List { 1, 2, 3 }; - Assert.Equal(FILL_ME_IN, list.ToArray()); - } + Assert.Equal(new int[] { 1, 2, 3 }, list.ToArray()); + } [Koan(13)] public void InsertingInTheMiddle() { List list = new List { 1, 2, 3 }; list.Insert(1, 6); - Assert.Equal(FILL_ME_IN, list.ToArray()); - } + Assert.Equal(new int[] { 1, 6, 2, 3 }, list.ToArray()); + } [Koan(14)] public void RemovingItems() { List list = new List { 2, 1, 2, 3 }; list.Remove(2); - Assert.Equal(FILL_ME_IN, list.ToArray()); + Assert.Equal(new int[] { 1, 2, 3 }, list.ToArray()); } [Koan(15)] public void StackPushPop() { var stack = new Stack(); - Assert.Equal(FILL_ME_IN, stack.Count); + Assert.Equal(0, stack.Count); stack.Push(42); - Assert.Equal(FILL_ME_IN, stack.Count); + Assert.Equal(1, stack.Count); int x = stack.Pop(); - Assert.Equal(FILL_ME_IN, x); + Assert.Equal(42, x); - Assert.Equal(FILL_ME_IN, stack.Count); + Assert.Equal(0, stack.Count); } [Koan(16)] public void StackOrder() @@ -170,16 +170,16 @@ public void StackOrder() stack.Push(2); stack.Push(3); - Assert.Equal(FILL_ME_IN, stack.ToArray()); + Assert.Equal(new int[] { 3, 2, 1 }, stack.ToArray()); } [Koan(17)] public void PeekingIntoAQueue() { Queue queue = new Queue(); queue.Enqueue("one"); - Assert.Equal(FILL_ME_IN, queue.Peek()); + Assert.Equal("one", queue.Peek()); queue.Enqueue("two"); - Assert.Equal(FILL_ME_IN, queue.Peek()); + Assert.Equal("one", queue.Peek()); } [Koan(18)] public void RemovingItemsFromTheQueue() @@ -187,17 +187,17 @@ public void RemovingItemsFromTheQueue() Queue queue = new Queue(); queue.Enqueue("one"); queue.Enqueue("two"); - Assert.Equal(FILL_ME_IN, queue.Dequeue()); - Assert.Equal(FILL_ME_IN, queue.Count); + Assert.Equal("one", queue.Dequeue()); + Assert.Equal(1, queue.Count); } [Koan(19)] public void AddingToADictionary() { //Dictionary is .Net's key value store. The key and the value do not need to be the same types. Dictionary dictionary = new Dictionary(); - Assert.Equal(FILL_ME_IN, dictionary.Count); + Assert.Equal(0, dictionary.Count); dictionary[1] = "one"; - Assert.Equal(FILL_ME_IN, dictionary.Count); + Assert.Equal(1, dictionary.Count); } [Koan(20)] public void AccessingData() @@ -206,15 +206,15 @@ public void AccessingData() dictionary["one"] = "uno"; dictionary["two"] = "dos"; //The most common way to locate data is with the subscript notation. - Assert.Equal(FILL_ME_IN, dictionary["one"]); - Assert.Equal(FILL_ME_IN, dictionary["two"]); + Assert.Equal("uno", dictionary["one"]); + Assert.Equal("dos", dictionary["two"]); } [Koan(21)] public void AccessingDataNotAdded() { Dictionary dictionary = new Dictionary(); dictionary["one"] = "uno"; - Assert.Throws(typeof(FillMeIn), delegate() { string s = dictionary["two"]; }); + Assert.Throws(typeof(KeyNotFoundException), delegate() { string s = dictionary["two"]; }); } [Koan(22)] public void CatchingMissingData() @@ -231,7 +231,7 @@ public void CatchingMissingData() { result = "dos"; } - Assert.Equal(FILL_ME_IN, result); + Assert.Equal("dos", result); } [Koan(23)] public void PreCheckForMissingData() @@ -247,7 +247,7 @@ public void PreCheckForMissingData() { result = "dos"; } - Assert.Equal(FILL_ME_IN, result); + Assert.Equal("dos", result); } [Koan(24)] public void TryGetValueForMissingData() @@ -259,15 +259,15 @@ public void TryGetValueForMissingData() { result = "dos"; } - Assert.Equal(FILL_ME_IN, result); + Assert.Equal("dos", result); } [Koan(25)] public void InitializingADictionary() { //Although it is not common, you can initialize a dictionary... var dictionary = new Dictionary { { "one", "uno" }, { "two", "dos" } }; - Assert.Equal(FILL_ME_IN, dictionary["one"]); - Assert.Equal(FILL_ME_IN, dictionary["two"]); + Assert.Equal("uno", dictionary["one"]); + Assert.Equal("dos", dictionary["two"]); } [Koan(26)] public void ModifyingData() @@ -276,23 +276,23 @@ public void ModifyingData() dictionary["one"] = "uno"; dictionary["two"] = "dos"; dictionary["one"] = "ein"; - Assert.Equal(FILL_ME_IN, dictionary["one"]); + Assert.Equal("ein", dictionary["one"]); } [Koan(27)] public void KeyExists() { Dictionary dictionary = new Dictionary(); dictionary["one"] = "uno"; - Assert.Equal(FILL_ME_IN, dictionary.ContainsKey("one")); - Assert.Equal(FILL_ME_IN, dictionary.ContainsKey("two")); + Assert.Equal(true, dictionary.ContainsKey("one")); + Assert.Equal(false, dictionary.ContainsKey("two")); } [Koan(28)] public void ValueExists() { Dictionary dictionary = new Dictionary(); dictionary["one"] = "uno"; - Assert.Equal(FILL_ME_IN, dictionary.ContainsValue("uno")); - Assert.Equal(FILL_ME_IN, dictionary.ContainsValue("dos")); + Assert.Equal(true, dictionary.ContainsValue("uno")); + Assert.Equal(false, dictionary.ContainsValue("dos")); } [Koan(29)] public void f() @@ -311,9 +311,9 @@ public void f() one[item.Key] = item.Value; } - Assert.Equal(FILL_ME_IN, one["jim"]); - Assert.Equal(FILL_ME_IN, one["jenny"]); - Assert.Equal(FILL_ME_IN, one["amy"]); + Assert.Equal(54, one["jim"]); + Assert.Equal(26, one["jenny"]); + Assert.Equal(20, one["amy"]); } } } diff --git a/CSharp/AboutInheritance.cs b/CSharp/AboutInheritance.cs index 8b9f87d..a3c22f9 100644 --- a/CSharp/AboutInheritance.cs +++ b/CSharp/AboutInheritance.cs @@ -56,27 +56,27 @@ public string Wag() [Koan(1)] public void SubclassesHaveTheParentAsAnAncestor() { - Assert.True(typeof(FillMeIn).IsAssignableFrom(typeof(Chihuahua))); + Assert.True(typeof(Dog).IsAssignableFrom(typeof(Chihuahua))); } [Koan(2)] public void AllClassesUltimatelyInheritFromAnObject() { - Assert.True(typeof(FillMeIn).IsAssignableFrom(typeof(Chihuahua))); + Assert.True(typeof(Dog).IsAssignableFrom(typeof(Chihuahua))); } [Koan(3)] public void SubclassesInheritBehaviorFromParentClass() { var chico = new Chihuahua("Chico"); - Assert.Equal(FILL_ME_IN, chico.Name); + Assert.Equal("Chico", chico.Name); } [Koan(4)] public void SubclassesAddNewBehavior() { var chico = new Chihuahua("Chico"); - Assert.Equal(FILL_ME_IN, chico.Wag()); + Assert.Equal("Happy", chico.Wag()); //We can search the public methods of an object //instance like this: @@ -92,16 +92,16 @@ public void SubclassesAddNewBehavior() public void SubclassesCanModifyExistingBehavior() { var chico = new Chihuahua("Chico"); - Assert.Equal(FILL_ME_IN, chico.Bark()); + Assert.Equal("yip", chico.Bark()); //Note that even if we cast the object back to a dog //we still get the Chihuahua's behavior. It truly //"is-a" Chihuahua Dog dog = chico as Dog; - Assert.Equal(FILL_ME_IN, dog.Bark()); + Assert.Equal("yip", dog.Bark()); var fido = new Dog("Fido"); - Assert.Equal(FILL_ME_IN, fido.Bark()); + Assert.Equal("WOOF", fido.Bark()); } public class ReallyYippyChihuahua : Chihuahua @@ -123,7 +123,7 @@ public ReallyYippyChihuahua(string name) : base(name) { } public void SubclassesCanRedefineBehaviorThatIsNotVirtual() { ReallyYippyChihuahua suzie = new ReallyYippyChihuahua("Suzie"); - Assert.Equal(FILL_ME_IN, suzie.Wag()); + Assert.Equal("WAG WAG WAG!!", suzie.Wag()); } [Koan(7)] @@ -133,7 +133,7 @@ public void NewingAMethodDoesNotChangeTheBaseBehavior() //method did what we defined in our class. But what happens //when we do this? Chihuahua bennie = new ReallyYippyChihuahua("Bennie"); - Assert.Equal(FILL_ME_IN, bennie.Wag()); + Assert.Equal("Happy", bennie.Wag()); //That's right. The behavior of the object is dependent solely //on who you are pretending to be. Unlike when you override a @@ -154,7 +154,7 @@ public override string Bark() public void SubclassesCanInvokeParentBehaviorUsingBase() { var ralph = new BullDog("Ralph"); - Assert.Equal(FILL_ME_IN, ralph.Bark()); + Assert.Equal("WOOF, GROWL", ralph.Bark()); } public class GreatDane : Dog @@ -170,7 +170,7 @@ public string Growl() public void YouCanCallBaseEvenFromOtherMethods() { var george = new GreatDane("George"); - Assert.Equal(FILL_ME_IN, george.Growl()); + Assert.Equal("WOOF, GROWL", george.Growl()); } } } \ No newline at end of file diff --git a/CSharp/AboutLambdas.cs b/CSharp/AboutLambdas.cs index e7e1324..abcc498 100644 --- a/CSharp/AboutLambdas.cs +++ b/CSharp/AboutLambdas.cs @@ -22,7 +22,7 @@ public void UsingAnonymousMethods() return x.ToString(); }); - Assert.Equal(FILL_ME_IN, result); + Assert.Equal(new[] { "1", "2", "3", "4" }, result); } [Koan(2)] public void AnonymousMethodsCanAccessOuterVariables() @@ -31,7 +31,7 @@ public void AnonymousMethodsCanAccessOuterVariables() //In C# this is called accessing an Outer Variable. In other languages it is called closure. var numbers = new[] { 4, 5, 6, 7, 8, 9 }; int toFind = 7; - Assert.Equal(FILL_ME_IN, Array.FindIndex(numbers, delegate(int x) + Assert.Equal(3, Array.FindIndex(numbers, delegate(int x) { return x == toFind; })); @@ -50,7 +50,7 @@ public void AccessEvenAfterVariableIsOutOfScope() } var numbers = new[] { 4, 5, 6, 7, 8, 9 }; //toFind is not available here, yet criteria still works - Assert.Equal(FILL_ME_IN, Array.FindIndex(numbers, criteria)); + Assert.Equal(3, Array.FindIndex(numbers, criteria)); } [Koan(4)] public void LambdaExpressionsAreShorthand() @@ -71,7 +71,7 @@ public void LambdaExpressionsAreShorthand() { return x.ToString(); }); - Assert.Equal(FILL_ME_IN, anonymous); + Assert.Equal(new[] { "1", "2", "3", "4" }, anonymous); //The => pair is spoken as "going into". If you were talking about this //code with a peer, you would say "x going into..." } @@ -91,7 +91,7 @@ public void TypeCanBeInferred() { return x.ToString(); }); - Assert.Equal(FILL_ME_IN, anonymous); + Assert.Equal(new[] { "1", "2", "3", "4" }, anonymous); } [Koan(6)] public void ParensNotNeededOnSingleParemeterLambdas() @@ -107,7 +107,7 @@ public void ParensNotNeededOnSingleParemeterLambdas() { return x.ToString(); }); - Assert.Equal(FILL_ME_IN, anonymous); + Assert.Equal(new[] { "1", "2", "3", "4" }, anonymous); } [Koan(7)] public void BlockNotNeededOnSingleStatementLambdas() @@ -119,7 +119,7 @@ public void BlockNotNeededOnSingleStatementLambdas() }); var lambda = Array.ConvertAll(numbers, x => x.ToString()); //When you have only one statement, the curly brackets are not needed. What other two things are also missing? - Assert.Equal(FILL_ME_IN, anonymous); + Assert.Equal(new[] { "1", "2", "3", "4" }, anonymous); } } } diff --git a/CSharp/AboutMethods.cs b/CSharp/AboutMethods.cs index f8f8108..03c471b 100644 --- a/CSharp/AboutMethods.cs +++ b/CSharp/AboutMethods.cs @@ -40,19 +40,19 @@ public class AboutMethods : Koan [Koan(1)] public void ExtensionMethodsShowUpInTheCurrentClass() { - Assert.Equal(FILL_ME_IN, this.HelloWorld()); + Assert.Equal("Hello!", this.HelloWorld()); } [Koan(2)] public void ExtensionMethodsWithParameters() { - Assert.Equal(FILL_ME_IN, this.SayHello("Cory")); + Assert.Equal("Hello, Cory!", this.SayHello("Cory")); } [Koan(3)] public void ExtensionMethodsWithVariableParameters() { - Assert.Equal(FILL_ME_IN, this.MethodWithVariableArguments("Cory", "Will", "Corey")); + Assert.Equal(new string[] { "Cory", "Will", "Corey" }, this.MethodWithVariableArguments("Cory", "Will", "Corey")); } //Extension methods can extend any class my referencing @@ -62,7 +62,7 @@ public void ExtensionMethodsWithVariableParameters() [Koan(4)] public void ExtendingCoreClasses() { - Assert.Equal(FILL_ME_IN, "Cory".SayHi()); + Assert.Equal("Hi, Cory", "Cory".SayHi()); } //Of course, any of the parameter things you can do with @@ -76,7 +76,7 @@ private string[] LocalMethodWithVariableParameters(params string[] names) [Koan(5)] public void LocalMethodsWithVariableParams() { - Assert.Equal(FILL_ME_IN, this.LocalMethodWithVariableParameters("Cory", "Will", "Corey")); + Assert.Equal(new string[] { "Cory", "Will", "Corey" }, this.LocalMethodWithVariableParameters("Cory", "Will", "Corey")); } //Note how we called the method by saying "this.LocalMethodWithVariableParameters" @@ -85,7 +85,7 @@ public void LocalMethodsWithVariableParams() [Koan(6)] public void LocalMethodsWithoutExplicitReceiver() { - Assert.Equal(FILL_ME_IN, LocalMethodWithVariableParameters("Cory", "Will", "Corey")); + Assert.Equal(new string[] { "Cory", "Will", "Corey" }, LocalMethodWithVariableParameters("Cory", "Will", "Corey")); } //But it is required for Extension Methods, since it needs @@ -111,7 +111,7 @@ class StateSecret : InnerSecret [Koan(7)] public void CallingStaticMethodsWithoutAnInstance() { - Assert.Equal(FILL_ME_IN, InnerSecret.Key()); + Assert.Equal("Key", InnerSecret.Key()); } //In fact, you can't call it on an instance variable @@ -124,7 +124,7 @@ public void CallingStaticMethodsWithoutAnInstance() public void CallingPublicMethodsOnAnInstance() { InnerSecret secret = new InnerSecret(); - Assert.Equal(FILL_ME_IN, secret.Secret()); + Assert.Equal("Secret", secret.Secret()); } //Protected methods can only be called by a subclass @@ -135,7 +135,7 @@ public void CallingPublicMethodsOnAnInstance() public void CallingProtectedMethodsOnAnInstance() { StateSecret secret = new StateSecret(); - Assert.Equal(FILL_ME_IN, secret.InformationLeak()); + Assert.Equal("This is secret", secret.InformationLeak()); } //But, we can't call the private methods of InnerSecret @@ -152,7 +152,7 @@ public void SubvertPrivateMethods() string superSecretMessage = secret.GetType() .GetMethod("SooperSeekrit", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) .Invoke(secret, null) as string; - Assert.Equal(FILL_ME_IN, superSecretMessage); + Assert.Equal("No one will find me!", superSecretMessage); } //Up till now we've had explicit return types. It's also @@ -168,9 +168,9 @@ public static T GiveMeBack(T p1) [Koan(11)] public void CallingGenericMethods() { - Assert.Equal(typeof(FillMeIn), GiveMeBack(1).GetType()); + Assert.Equal(typeof(System.Int32), GiveMeBack(1).GetType()); - Assert.Equal(FILL_ME_IN, GiveMeBack("Hi!")); + Assert.Equal("Hi!", GiveMeBack("Hi!")); } } } \ No newline at end of file diff --git a/CSharp/AboutNil.cs b/CSharp/AboutNil.cs index c522005..066e243 100644 --- a/CSharp/AboutNil.cs +++ b/CSharp/AboutNil.cs @@ -1,3 +1,4 @@ +using System; using Xunit; namespace DotNetKoans.CSharp @@ -7,7 +8,7 @@ public class AboutNil : Koan [Koan(1)] public void NilIsNotAnObject() { - Assert.True(typeof(object).IsAssignableFrom(null)); //not everything is an object + Assert.True(typeof(object).IsAssignableFrom(typeof(string))); //not everything is an object } [Koan(2)] @@ -17,7 +18,7 @@ public void YouGetNullPointerErrorsWhenCallingMethodsOnNil() //Don't be confused by the code below. It is using Anonymous Delegates which we will //cover later on. object nothing = null; - Assert.Throws(typeof(FillMeIn), delegate() { nothing.ToString(); }); + Assert.Throws(typeof(NullReferenceException), delegate() { nothing.ToString(); }); //What's the message of the exception? What substring or pattern could you test //against in order to have a good idea of what the string is? @@ -27,7 +28,7 @@ public void YouGetNullPointerErrorsWhenCallingMethodsOnNil() } catch (System.Exception ex) { - Assert.Contains(FILL_ME_IN as string, ex.Message); + Assert.Contains("Object reference" as string, ex.Message); } } @@ -35,21 +36,21 @@ public void YouGetNullPointerErrorsWhenCallingMethodsOnNil() public void CheckingThatAnObjectIsNull() { object obj = null; - Assert.True(obj == FILL_ME_IN); + Assert.True(obj == null); } [Koan(4)] public void ABetterWayToCheckThatAnObjectIsNull() { object obj = null; - Assert.Null(FILL_ME_IN); + Assert.Null(obj); } [Koan(5)] public void AWayNotToCheckThatAnObjectIsNull() { object obj = null; - Assert.True(obj.Equals(null)); + Assert.True(obj == (null)); } } } diff --git a/CSharp/AboutStrings.cs b/CSharp/AboutStrings.cs index 34dc44a..02a705c 100644 --- a/CSharp/AboutStrings.cs +++ b/CSharp/AboutStrings.cs @@ -18,21 +18,21 @@ public class AboutStrings : Koan public void DoubleQuotedStringsAreStrings() { var str = "Hello, World"; - Assert.Equal(typeof(FillMeIn), str.GetType()); + Assert.Equal(typeof(string), str.GetType()); } [Koan(2)] public void SingleQuotedStringsAreNotStrings() { var str = 'H'; - Assert.Equal(typeof(FillMeIn), str.GetType()); + Assert.Equal(typeof(char), str.GetType()); } [Koan(3)] public void CreateAStringWhichContainsDoubleQuotes() { var str = "Hello, \"World\""; - Assert.Equal(FILL_ME_IN, str.Length); + Assert.Equal(14, str.Length); } [Koan(4)] @@ -41,7 +41,7 @@ public void AnotherWayToCreateAStringWhichContainsDoubleQuotes() //The @ symbol creates a 'verbatim string literal'. //Here's one thing you can do with it: var str = @"Hello, ""World"""; - Assert.Equal(FILL_ME_IN, str.Length); + Assert.Equal(14, str.Length); } [Koan(5)] @@ -49,7 +49,7 @@ public void VerbatimStringsCanHandleFlexibleQuoting() { var strA = @"Verbatim Strings can handle both ' and "" characters (when escaped)"; var strB = "Verbatim Strings can handle both ' and \" characters (when escaped)"; - Assert.Equal(FILL_ME_IN, strA.Equals(strB)); + Assert.Equal(true, strA.Equals(strB)); } [Koan(6)] @@ -63,7 +63,7 @@ public void VerbatimStringsCanHandleMultipleLinesToo() am a broken line"; Assert.Equal(20, verbatimString.Length); - var literalString = FILL_ME_IN; + var literalString = "I\r\nam a\r\nbroken line"; Assert.Equal(literalString, verbatimString); } @@ -75,7 +75,9 @@ public void ACrossPlatformWayToHandleLineEndings() //the hardcoded escape sequence. A much better way //(We'll handle concatenation and better ways of that in a bit) var literalString = "I" + System.Environment.NewLine + "am a" + System.Environment.NewLine + "broken line"; - var vebatimString = FILL_ME_IN; + var vebatimString = @"I +am a +broken line"; Assert.Equal(literalString, vebatimString); } @@ -83,7 +85,7 @@ public void ACrossPlatformWayToHandleLineEndings() public void PlusWillConcatenateTwoStrings() { var str = "Hello, " + "World"; - Assert.Equal(FILL_ME_IN, str); + Assert.Equal("Hello, World", str); } [Koan(9)] @@ -92,8 +94,8 @@ public void PlusConcatenationWillNotModifyOriginalStrings() var strA = "Hello, "; var strB = "World"; var fullString = strA + strB; - Assert.Equal(FILL_ME_IN, strA); - Assert.Equal(FILL_ME_IN, strB); + Assert.Equal("Hello, ", strA); + Assert.Equal("World", strB); } [Koan(10)] @@ -102,8 +104,8 @@ public void PlusEqualsWillModifyTheTargetString() var strA = "Hello, "; var strB = "World"; strA += strB; - Assert.Equal(FILL_ME_IN, strA); - Assert.Equal(FILL_ME_IN, strB); + Assert.Equal("Hello, World", strA); + Assert.Equal("World", strB); } [Koan(11)] @@ -117,7 +119,7 @@ public void StringsAreReallyImmutable() var originalString = strA; var strB = "World"; strA += strB; - Assert.Equal(FILL_ME_IN, originalString); + Assert.Equal("Hello, ", originalString); //What just happened? Well, the string concatenation actually //takes strA and strB and creates a *new* string in memory @@ -134,14 +136,14 @@ public void YouDoNotNeedConcatenationToInsertVariablesInAString() { var world = "World"; var str = String.Format("Hello, {0}", world); - Assert.Equal(FILL_ME_IN, str); + Assert.Equal("Hello, World", str); } [Koan(13)] public void AnyExpressionCanBeUsedInFormatString() { var str = String.Format("The square root of 9 is {0}", Math.Sqrt(9)); - Assert.Equal(FILL_ME_IN, str); + Assert.Equal("The square root of 9 is 3", str); } [Koan(14)] @@ -149,56 +151,56 @@ public void StringsCanBePaddedToTheLeft() { //You can modify the value inserted into the result var str = string.Format("{0,3:}", "x"); - Assert.Equal(FILL_ME_IN, str); + Assert.Equal(" x", str); } [Koan(15)] public void StringsCanBePaddedToTheRight() { var str = string.Format("{0,-3:}", "x"); - Assert.Equal(FILL_ME_IN, str); + Assert.Equal("x ", str); } [Koan(16)] public void SeperatorsCanBeAdded() { var str = string.Format("{0:n}", 123456); - Assert.Equal(FILL_ME_IN, str); + Assert.Equal("123,456.00", str); } [Koan(17)] public void CurrencyDesignatorsCanBeAdded() { var str = string.Format("{0:n}", 123456); - Assert.Equal(FILL_ME_IN, str); + Assert.Equal("123,456.00", str); } [Koan(18)] public void NumberOfDisplayedDecimalsCanBeControled() { var str = string.Format("{0:.##}", 12.3456); - Assert.Equal(FILL_ME_IN, str); + Assert.Equal("12.35", str); } [Koan(19)] public void MinimumNumberOfDisplayedDecimalsCanBeControled() { var str = string.Format("{0:.00}", 12.3); - Assert.Equal(FILL_ME_IN, str); + Assert.Equal("12.30", str); } [Koan(20)] public void BuiltInDateFormaters() { var str = string.Format("{0:t}", DateTime.Parse("12/16/2011 2:35:02 PM")); - Assert.Equal(FILL_ME_IN, str); + Assert.Equal("2:35 PM", str); } [Koan(21)] public void CustomeDateFormaters() { var str = string.Format("{0:t m}", DateTime.Parse("12/16/2011 2:35:02 PM")); - Assert.Equal(FILL_ME_IN, str); + Assert.Equal("P 35", str); } //These are just a few of the formatters available. Dig some and you may find what you need. @@ -217,7 +219,7 @@ public void ABetterWayToConcatenateLotsOfStrings() strBuilder.Append("lazy "); strBuilder.Append("dog."); var str = strBuilder.ToString(); - Assert.Equal(FILL_ME_IN, str); + Assert.Equal("The quick brown fox jumped over the lazy dog.", str); //String.Format and StringBuilder will be more efficent that concatenation. Prefer them. } @@ -230,43 +232,43 @@ public void StringBuilderCanUseFormatAsWell() strBuilder.AppendFormat("{0} {1} {2}", "jumped", "over", "the"); strBuilder.AppendFormat("{0} {1}.", "lazy", "dog"); var str = strBuilder.ToString(); - Assert.Equal(FILL_ME_IN, str); + Assert.Equal("The quick brownjumped over thelazy dog.", str); } [Koan(23)] public void LiteralStringsInterpretsEscapeCharacters() { var str = "\n"; - Assert.Equal(FILL_ME_IN, str.Length); + Assert.Equal(1, str.Length); } [Koan(24)] public void VerbatimStringsDoNotInterpretEscapeCharacters() { var str = @"\n"; - Assert.Equal(FILL_ME_IN, str.Length); + Assert.Equal(2, str.Length); } [Koan(25)] public void VerbatimStringsStillDoNotInterpretEscapeCharacters() { var str = @"\\\"; - Assert.Equal(FILL_ME_IN, str.Length); + Assert.Equal(3, str.Length); } [Koan(28)] public void YouCanGetASubstringFromAString() { var str = "Bacon, lettuce and tomato"; - Assert.Equal(FILL_ME_IN, str.Substring(19)); - Assert.Equal(FILL_ME_IN, str.Substring(7, 3)); + Assert.Equal("tomato", str.Substring(19)); + Assert.Equal("let", str.Substring(7, 3)); } [Koan(29)] public void YouCanGetASingleCharacterFromAString() { var str = "Bacon, lettuce and tomato"; - Assert.Equal(FILL_ME_IN, str[0]); + Assert.Equal(66, str[0]); } [Koan(30)] @@ -274,7 +276,7 @@ public void SingleCharactersAreRepresentedByIntegers() { Assert.Equal(97, 'a'); Assert.Equal(98, 'b'); - Assert.Equal(FILL_ME_IN, 'b' == ('a' + 1)); + Assert.Equal(true, 'b' == ('a' + 1)); } [Koan(31)] @@ -282,7 +284,7 @@ public void StringsCanBeSplit() { var str = "Sausage Egg Cheese"; string[] words = str.Split(); - Assert.Equal(new[] { FILL_ME_IN }, words); + Assert.Equal(new[] { "Sausage", "Egg", "Cheese" }, words); } [Koan(32)] @@ -290,7 +292,7 @@ public void StringsCanBeSplitUsingCharacters() { var str = "the:rain:in:spain"; string[] words = str.Split(':'); - Assert.Equal(new[] { FILL_ME_IN }, words); + Assert.Equal(new[] { "the", "rain", "in", "spain" }, words); } [Koan(33)] @@ -299,7 +301,7 @@ public void StringsCanBeSplitUsingRegularExpressions() var str = "the:rain:in:spain"; var regex = new System.Text.RegularExpressions.Regex(":"); string[] words = regex.Split(str); - Assert.Equal(new[] { FILL_ME_IN }, words); + Assert.Equal(new[] { "the", "rain", "in", "spain" }, words); //A full treatment of regular expressions is beyond the scope //of this tutorial. The book "Mastering Regular Expressions" diff --git a/CSharp/CSharp.csproj b/CSharp/CSharp.csproj index d7d322a..dcd0047 100644 --- a/CSharp/CSharp.csproj +++ b/CSharp/CSharp.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -10,7 +10,7 @@ Properties DotNetKoans.CSharp CSharp - v3.5 + v4.5.2 512 Always @@ -32,6 +32,7 @@ false false true + true @@ -41,6 +42,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -49,6 +51,7 @@ TRACE prompt 4 + false diff --git a/KoanHelpers/KoanHelpers.csproj b/KoanHelpers/KoanHelpers.csproj index c255914..7a052d6 100644 --- a/KoanHelpers/KoanHelpers.csproj +++ b/KoanHelpers/KoanHelpers.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -10,7 +10,7 @@ Properties KoanHelpers KoanHelpers - v3.5 + v4.5.2 512 @@ -31,6 +31,7 @@ false false true + true @@ -40,6 +41,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -48,6 +50,7 @@ TRACE prompt 4 + false diff --git a/KoanRunner/KoanRunner.csproj b/KoanRunner/KoanRunner.csproj index f6a9684..406e5f3 100644 --- a/KoanRunner/KoanRunner.csproj +++ b/KoanRunner/KoanRunner.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -10,7 +10,7 @@ Properties KoanRunner KoanRunner - v3.5 + v4.5.2 512 @@ -31,6 +31,7 @@ false false true + true @@ -40,6 +41,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -48,6 +50,7 @@ TRACE prompt 4 + false @@ -99,6 +102,7 @@ + diff --git a/KoanRunner/app.config b/KoanRunner/app.config new file mode 100644 index 0000000..ff99501 --- /dev/null +++ b/KoanRunner/app.config @@ -0,0 +1,3 @@ + + + diff --git a/VBNet/AboutAsserts.vb b/VBNet/AboutAsserts.vb index 8e34567..0c441f5 100644 --- a/VBNet/AboutAsserts.vb +++ b/VBNet/AboutAsserts.vb @@ -5,7 +5,7 @@ Public Class AboutAsserts 'We shall contemplate truth by testing reality, via asserts. _ Public Sub AssertTruth() - Assert.True(False) 'This should be true + Assert.True(True) 'This should be true End Sub 'Enlightenment may be more easily achieved with appropriate messages diff --git a/VBNet/My Project/Application.Designer.vb b/VBNet/My Project/Application.Designer.vb index 66fb81a..88dd01c 100644 --- a/VBNet/My Project/Application.Designer.vb +++ b/VBNet/My Project/Application.Designer.vb @@ -1,7 +1,7 @@ '------------------------------------------------------------------------------ ' ' This code was generated by a tool. -' Runtime Version:4.0.30319.239 +' Runtime Version:4.0.30319.42000 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. diff --git a/VBNet/My Project/Resources.Designer.vb b/VBNet/My Project/Resources.Designer.vb index b975674..4dd279e 100644 --- a/VBNet/My Project/Resources.Designer.vb +++ b/VBNet/My Project/Resources.Designer.vb @@ -1,7 +1,7 @@ '------------------------------------------------------------------------------ ' ' This code was generated by a tool. -' Runtime Version:4.0.30319.239 +' Runtime Version:4.0.30319.42000 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. diff --git a/VBNet/My Project/Settings.Designer.vb b/VBNet/My Project/Settings.Designer.vb index bb178b1..640f02f 100644 --- a/VBNet/My Project/Settings.Designer.vb +++ b/VBNet/My Project/Settings.Designer.vb @@ -1,7 +1,7 @@ '------------------------------------------------------------------------------ ' ' This code was generated by a tool. -' Runtime Version:4.0.30319.239 +' Runtime Version:4.0.30319.42000 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. @@ -15,7 +15,7 @@ Option Explicit On Namespace My _ Partial Friend NotInheritable Class MySettings Inherits Global.System.Configuration.ApplicationSettingsBase diff --git a/VBNet/VBNet.vbproj b/VBNet/VBNet.vbproj index 54517f3..b73ff47 100644 --- a/VBNet/VBNet.vbproj +++ b/VBNet/VBNet.vbproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -13,7 +13,7 @@ VBNet 512 Windows - v3.5 + v4.5.2 @@ -24,6 +24,7 @@ bin\Debug\ VBNet.xml 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + false pdbonly @@ -33,6 +34,7 @@ bin\Release\ VBNet.xml 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + false On