Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ target
.DS_Store
.gradle
build
/Csharp/.vs/RefactoringGolf/v15/
/Csharp/RefactoringGolf/obj/
/Csharp/RefactoringGolf/bin/
/Csharp/RefactoringGolf/*.csproj.user
25 changes: 25 additions & 0 deletions Csharp/RefactoringGolf.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2027
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RefactoringGolf", "RefactoringGolf\RefactoringGolf.csproj", "{252168AF-B7EE-4F5C-8677-B31104CBE13A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{252168AF-B7EE-4F5C-8677-B31104CBE13A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{252168AF-B7EE-4F5C-8677-B31104CBE13A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{252168AF-B7EE-4F5C-8677-B31104CBE13A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{252168AF-B7EE-4F5C-8677-B31104CBE13A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CF666B81-C45C-4B11-9ED0-49A5115327FC}
EndGlobalSection
EndGlobal
33 changes: 33 additions & 0 deletions Csharp/RefactoringGolf/Hole1/Hole1After.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace RefactoringGolf.Hole1
{
public class Hole1After
{
private IList<Instruction> instructions = new List<Instruction>();

public void parseCommand(String command)
{

String[] parts = command.Split(" ");
String direction = parts[0];
int amount = int.Parse(parts[1]);

if (direction.Equals("foward"))
{
instructions.Add(new MoveInstruction(amount));
}
if (direction.Equals("left"))
{
instructions.Add(new TurnInstruction(amount));
}
if (direction.Equals("right"))
{
instructions.Add(new TurnInstruction(-1 * amount));
}

}
}
}
32 changes: 32 additions & 0 deletions Csharp/RefactoringGolf/Hole1/Hole1Before.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;

namespace RefactoringGolf.Hole1
{
public class Hole1Before
{
private IList<Instruction> instructions = new List<Instruction>();

public void parseCommand(String command)
{

String[] parts = command.Split(" ");
String direction = parts[0];
String amount = parts[1];

if (direction.Equals("foward"))
{
instructions.Add(new MoveInstruction(int.Parse(amount)));
}
if (direction.Equals("left"))
{
instructions.Add(new TurnInstruction(int.Parse(amount)));
}
if (direction.Equals("right"))
{
instructions.Add(new TurnInstruction(-1 * int.Parse(amount)));
}

}
}
}
33 changes: 33 additions & 0 deletions Csharp/RefactoringGolf/Hole2/Hole2After.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;

namespace RefactoringGolf.Hole2
{
public class Hole2After
{
private IList<Instruction> instructions = new List<Instruction>();

public void parseCommand(String command)
{
String[] parts = command.Split(" ");
String direction = parts[0];
int amount = int.Parse(parts[1]);

Instruction instruction = null;
if (direction.Equals("foward"))
{
instruction = new MoveInstruction(amount);
}
if (direction.Equals("left"))
{
instruction = new TurnInstruction(amount);
}
if (direction.Equals("right"))
{
instruction = new TurnInstruction(-1 * amount);
}

instructions.Add(instruction);
}
}
}
30 changes: 30 additions & 0 deletions Csharp/RefactoringGolf/Hole2/Hole2Before.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;

namespace RefactoringGolf.Hole2
{
public class Hole2Before
{
private IList<Instruction> instructions = new List<Instruction>();

public void parseCommand(String command)
{
String[] parts = command.Split(" ");
String direction = parts[0];
int amount = int.Parse(parts[1]);

if (direction.Equals("foward"))
{
instructions.Add(new MoveInstruction(amount));
}
if (direction.Equals("left"))
{
instructions.Add(new TurnInstruction(amount));
}
if (direction.Equals("right"))
{
instructions.Add(new TurnInstruction(-1 * amount));
}
}
}
}
16 changes: 16 additions & 0 deletions Csharp/RefactoringGolf/Hole3/Hole3After.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;

namespace RefactoringGolf.Hole3
{
public class Hole3After
{
private IList<Instruction> instructions = new List<Instruction>();

public void parseCommand(String command)
{
// Uncomment this...
// instructions.add(Instruction.toPerform(command));
}
}
}
33 changes: 33 additions & 0 deletions Csharp/RefactoringGolf/Hole3/Hole3Before.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;

namespace RefactoringGolf.Hole3
{
public class Hole3Before
{
private IList<Instruction> instructions = new List<Instruction>();

public void parseCommand(String command)
{
String[] parts = command.Split(" ");
String direction = parts[0];
int amount = int.Parse(parts[1]);

Instruction instruction = null;
if (direction.Equals("foward"))
{
instruction = new MoveInstruction(amount);
}
if (direction.Equals("left"))
{
instruction = new TurnInstruction(amount);
}
if (direction.Equals("right"))
{
instruction = new TurnInstruction(-1 * amount);
}

instructions.Add(instruction);
}
}
}
36 changes: 36 additions & 0 deletions Csharp/RefactoringGolf/Hole4/Hole4After.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace RefactoringGolf.Hole4
{
public class Hole4After
{
public void printLabelAndReceipt()
{
new Label().Print();
new Receipt().Print();
}

class Receipt
{
public void Print()
{
Console.WriteLine("1 Book, 5.99");
Console.WriteLine("1 CD, 9.99");
Console.WriteLine("Total: 15.98 ");
}
}

class Label
{
public void Print()
{
Console.WriteLine("Mr J Smith");
Console.WriteLine("34 High Street");
Console.WriteLine("Oxford");
Console.WriteLine("OX1 1TT");
}
}
}
}
22 changes: 22 additions & 0 deletions Csharp/RefactoringGolf/Hole4/Hole4Before.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace RefactoringGolf.Hole4
{
public class Hole4Before
{
public void printLabelAndReceipt()
{

Console.WriteLine("Mr J Smith");
Console.WriteLine("34 High Street");
Console.WriteLine("Oxford");
Console.WriteLine("OX1 1TT");
Console.WriteLine("1 Book, 5.99");
Console.WriteLine("1 CD, 9.99");
Console.WriteLine("Total: 15.98 ");

}
}
}
75 changes: 75 additions & 0 deletions Csharp/RefactoringGolf/Hole5/Hole5After.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;

namespace RefactoringGolf.Hole5
{
public class Hole5After
{

class FibonacciSequence : NumberSequence
{
public override int term(int n)
{
if (n < 0)
{
throw new ArgumentOutOfRangeException("Sequence undefined for negative index");
}
if (n < 2)
{
return 1;
}
return term(n - 2) + term(n - 1);
}

}

class TriangularNumberSequence : NumberSequence
{
public override int term(int n)
{
if (n < 0)
{
throw new ArgumentOutOfRangeException("Sequence undefined for negative index");
}
return (n + 2) * (n + 1) / 2;
}

}

public abstract class NumberSequence
{
public abstract int term(int n);

//public Iterator<Integer> iterator()
//{
// // return new Iterator<Integer>()
// // {

// // private int currentIndex = 0;

// // public boolean hasNext()
// // {
// // return true;
// // }

// // public Integer next()
// // {
// // int result = term(currentIndex);
// // currentIndex++;
// // return result;
// // }

// // public void remove()
// // {
// // throw new UnsupportedOperationException();
// // }
// //};
//}
}

public void generate()
{
new FibonacciSequence().term(3);
new TriangularNumberSequence().term(3);
}
}
}
Loading