Skip to content

.NET Core #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
76fb465
Replace NUnit with xUnit
ErikSchierboom Feb 7, 2017
10c9164
Add .NET CLI support
ErikSchierboom Feb 13, 2017
f0cc2f5
Enable CI support for .NET Core
ErikSchierboom Feb 13, 2017
aa7d89b
Default file work
ErikSchierboom Feb 19, 2017
6994af0
Update hello-world exercise
ErikSchierboom Feb 20, 2017
10dc4da
Move enumerations to outer scope
ErikSchierboom Feb 20, 2017
e00cf19
Merge branch 'master' into dotnet-core
ErikSchierboom Feb 20, 2017
5a8fc26
All building single project
ErikSchierboom Feb 20, 2017
4300f5c
Ignore Example.cs in project
ErikSchierboom Feb 21, 2017
49b9b4f
Update package references
ErikSchierboom Feb 22, 2017
8a60e34
Use RTM version of Microsoft.NET.Test.Sdk package
ErikSchierboom Feb 27, 2017
f8cefcf
Merge remote-tracking branch 'exercism/master' into dotnet-core
ErikSchierboom Feb 27, 2017
5849e3b
Added static keyword to static classes
tushartyagi Feb 28, 2017
e839e27
Added static keyword to static classes and the examples
tushartyagi Feb 28, 2017
b52a761
Merge pull request #215 from tushartyagi/dotnet-core
ErikSchierboom Feb 28, 2017
19c7c3b
Ignore Project Rider folder and *.userpref files
ErikSchierboom Feb 27, 2017
33ffad6
Update installation and test instructions
ErikSchierboom Feb 27, 2017
1bf058a
Remove unused documentation images
ErikSchierboom Feb 28, 2017
06832e5
Update solution file
ErikSchierboom Mar 6, 2017
48d567f
Update docs with latest CLI and VS download link
ErikSchierboom Mar 7, 2017
746aa1b
Revert back to version 1.0.0 CLI message
ErikSchierboom Mar 7, 2017
d0ba801
Use correct project configuration in solution file
ErikSchierboom Mar 7, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ bin/configlet.exe
.fake/
.paket/paket.exe
.vs/
.vscode/
tools/
build/
packages/
paket-files
TestResult.xml
junit-results.xml
junit-results.xml
obj/
bin/
*.userprefs
.idea/
29 changes: 26 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
language: csharp

sudo: required
dist: trusty
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages:
- gettext
- libcurl4-openssl-dev
- libicu-dev
- libssl-dev
- libunwind8
- zlib1g
- libstdc++6
env:
global:
- DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
- DOTNET_CLI_TELEMETRY_OPTOUT: 1
mono:
- 4.0.5
os:
- linux
- osx

before_install:
- curl https://download.microsoft.com/download/B/4/6/B4678511-01F4-4F97-902B-0E58A985932A/dotnet-dev-debian-x64.1.0.0-rc4-004771.tar.gz -o /tmp/dotnet.tar.gz
- sudo mkdir -p /opt/dotnet
- sudo tar zxf /tmp/dotnet.tar.gz -C /opt/dotnet
- sudo ln -s /opt/dotnet/dotnet /usr/local/bin

script:
- ./bin/fetch-configlet
- ./bin/configlet .
- ./build.sh
- ./build.sh
137 changes: 137 additions & 0 deletions Zipper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using System;
using System.Collections.Generic;
using System.Linq;

public class BinTree<T> : IEquatable<BinTree<T>>
{
public BinTree(T value, BinTree<T> left, BinTree<T> right)
{
Value = value;
Left = left;
Right = right;
}

public BinTree(BinTree<T> tree) : this(tree.Value, tree.Left, tree.Right)
{
}

public T Value { get; }
public BinTree<T> Left { get; }
public BinTree<T> Right { get; }

public bool Equals(BinTree<T> other)
{
if (other == null || !Equals(Value, other.Value))
return false;

if (!ReferenceEquals(Left, other.Left) && (!Left?.Equals(other.Left) ?? false))
return false;

if (!ReferenceEquals(Right, other.Right) && (!Right?.Equals(other.Right) ?? false))
return false;

return true;
}
}

public abstract class BinTreeCrumb<T>
{
public BinTreeCrumb(T value, BinTree<T> tree)
{
Value = value;
Tree = tree;
}

public T Value { get; }
public BinTree<T> Tree { get; }
}

public class BinTreeLeftCrumb<T> : BinTreeCrumb<T>
{
public BinTreeLeftCrumb(T value, BinTree<T> tree) : base(value, tree)
{
}
}

public class BinTreeRightCrumb<T> : BinTreeCrumb<T>
{
public BinTreeRightCrumb(T value, BinTree<T> tree) : base(value, tree)
{
}
}

public class Zipper<T>
{
private readonly T value;
private readonly BinTree<T> left;
private readonly BinTree<T> right;
private readonly List<BinTreeCrumb<T>> crumbs;

public Zipper(T value, BinTree<T> left, BinTree<T> right, List<BinTreeCrumb<T>> crumbs)
{
this.value = value;
this.left = left;
this.right = right;
this.crumbs = crumbs;
}

public T Value => value;

public Zipper<T> SetValue(T newValue) => new Zipper<T>(newValue, left, right, crumbs);

public Zipper<T> SetLeft(BinTree<T> binTree) => new Zipper<T>(value, binTree, right, crumbs);

public Zipper<T> SetRight(BinTree<T> binTree) => new Zipper<T>(value, left, binTree, crumbs);

public Zipper<T> Left()
{
if (left == null)
return null;

var newCrumbs = new[] { new BinTreeLeftCrumb<T>(value, right) }.Concat(crumbs).ToList();
return new Zipper<T>(left.Value, left.Left, left.Right, newCrumbs);
}

public Zipper<T> Right()
{
if (right == null)
return null;

var newCrumbs = new[] { new BinTreeRightCrumb<T>(value, left) }.Concat(crumbs).ToList();
return new Zipper<T>(right.Value, right.Left, right.Right, newCrumbs);
}

public Zipper<T> Up()
{
if (crumbs.Count == 0)
return null;

var firstCrumb = crumbs[0];
var remainingCrumbs = crumbs.Skip(1).ToList();

if (firstCrumb is BinTreeLeftCrumb<T>)
return new Zipper<T>(firstCrumb.Value, new BinTree<T>(value, left, right), firstCrumb.Tree, remainingCrumbs);

if (firstCrumb is BinTreeRightCrumb<T>)
return new Zipper<T>(firstCrumb.Value, firstCrumb.Tree, new BinTree<T>(value, left, right), remainingCrumbs);

return null;
}

public BinTree<T> ToTree()
{
var tree = new BinTree<T>(value, left, right);

foreach (var crumb in crumbs)
{
if (crumb is BinTreeLeftCrumb<T>)
tree = new BinTree<T>(crumb.Value, new BinTree<T>(tree), crumb.Tree);
if (crumb is BinTreeRightCrumb<T>)
tree = new BinTree<T>(crumb.Value, crumb.Tree, new BinTree<T>(tree));
}

return tree;
}

public static Zipper<T> FromTree(BinTree<T> tree) => new Zipper<T>(tree.Value, tree.Left, tree.Right, new List<BinTreeCrumb<T>>());
}
7 changes: 6 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
init:
- ps: (New-Object Net.WebClient).DownloadFile('https://download.microsoft.com/download/5/F/E/5FEB7E95-C643-48D5-8329-9D2C63676CE8/dotnet-dev-win-x64.1.0.0-rc4-004771.exe', "c:/dotnet-install.exe")
- cmd: c:\dotnet-install.exe /install /quiet
build_script:
- ps: .\build.cmd

environment:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
test: off
106 changes: 59 additions & 47 deletions build.fsx
Original file line number Diff line number Diff line change
@@ -1,66 +1,78 @@
// Include Fake library
#r "./packages/FAKE/tools/FakeLib.dll"

open Fake
open Fake.Testing.NUnit3
open Fake.DotNetCli
open System.Text

// Directories
let buildDir = "./build/"
let sourceDir = "./exercises/"
let project = environVarOrDefault "project" "*"
let buildDir = "./build/"
let sourceDir = "./exercises/"
let projectDirs = buildDir @@ project

// Files
let solutionFile = buildDir @@ "/exercises.csproj"
let compiledOutput = buildDir @@ "xcsharp.dll"
let nunitToJunitTransformFile = "./paket-files" @@ "nunit" @@ "nunit-transforms" @@ "nunit3-junit" @@ "nunit3-junit.xslt"
let testFiles = !! (projectDirs @@ "*Test.cs")
let allProjects = !! (projectDirs @@ "*.csproj")
let defaultProjects =
!! (projectDirs @@ "*.csproj") --
(projectDirs @@ "DotDsl.csproj") --
(projectDirs @@ "Hangman.csproj") --
(projectDirs @@ "React.csproj")
let refactoringProjects =
!! (projectDirs @@ "TreeBuilding.csproj") ++
(projectDirs @@ "Ledger.csproj") ++
(projectDirs @@ "Markdown.csproj")

// Targets
Target "PrepareUnchanged" (fun _ ->
CleanDirs [buildDir]
CopyDir buildDir sourceDir allFiles
)
let restore project = DotNetCli.Restore (fun p -> { p with Project = project })
let build project = DotNetCli.Build (fun p -> { p with Project = project })
let test project = DotNetCli.Test (fun p -> { p with Project = project })

let restoreAndBuild project =
restore project
build project

Target "BuildUnchanged" (fun _ ->
MSBuildRelease buildDir "Build" [solutionFile]
|> Log "Build unchanged output: "
let restoreAndTest project =
restore project
test project

Target "Clean" (fun _ ->
DeleteDir buildDir
)

Target "PrepareTests" (fun _ ->
CleanDirs [buildDir]
Target "CopyExercises" (fun _ ->
CopyDir buildDir sourceDir allFiles
)

let ignorePattern = "(\[Ignore\(\"Remove to run test\"\)]|, Ignore = \"Remove to run test case\")"
Target "BuildUsingStubImplementation" (fun _ ->
Seq.iter restoreAndBuild defaultProjects
)

Target "EnableAllTests" (fun _ ->
let skipProperty = "Skip\s*=\s*\"Remove to run test\""
RegexReplaceInFilesWithEncoding skipProperty "" Encoding.UTF8 testFiles
)

!! (buildDir @@ "**/*Test.cs")
|> RegexReplaceInFilesWithEncoding ignorePattern "" System.Text.Encoding.UTF8
Target "TestRefactoringProjects" (fun _ ->
Seq.iter restoreAndTest refactoringProjects
)

Target "BuildTests" (fun _ ->
MSBuildRelease buildDir "Build" [solutionFile]
|> Log "Build tests output: "
Target "ReplaceStubWithExampleImplementation" (fun _ ->
let replaceStubWithExampleImplementation project =
let stubFile = filename project + "" |> changeExt ".cs"
let exampleFile = "Example.cs"
RegexReplaceInFileWithEncoding exampleFile stubFile Encoding.UTF8 project

Seq.iter replaceStubWithExampleImplementation allProjects
)

Target "Test" (fun _ ->
if getEnvironmentVarAsBool "APPVEYOR" then
[compiledOutput]
|> NUnit3 (fun p -> { p with
ShadowCopy = false
ToolPath = "nunit3-console.exe" })
else if getEnvironmentVarAsBool "CIRCLECI" then
[compiledOutput]
|> NUnit3 (fun p -> { p with
ShadowCopy = false
ResultSpecs = [sprintf "junit-results.xml;transform=%s" nunitToJunitTransformFile] })
else
[compiledOutput]
|> NUnit3 (fun p -> { p with ShadowCopy = false })
Target "TestUsingExampleImplementation" (fun _ ->
Seq.iter restoreAndTest allProjects
)

// Build order
"PrepareUnchanged"
==> "BuildUnchanged"
==> "PrepareTests"
==> "BuildTests"
==> "Test"
"Clean"
==> "CopyExercises"
==> "BuildUsingStubImplementation"
==> "EnableAllTests"
==> "TestRefactoringProjects"
==> "ReplaceStubWithExampleImplementation"
==> "TestUsingExampleImplementation"

// start build
RunTargetOrDefault "Test"
RunTargetOrDefault "TestUsingExampleImplementation"
20 changes: 15 additions & 5 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
machine:
environment:
TERM: xterm-256color
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_CLI_TELEMETRY_OPTOUT: 1
dependencies:
pre:
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
- echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
- sudo apt-get update
- sudo apt-get install mono-complete
- sudo apt-get install gettext
- sudo apt-get install libcurl4-openssl-dev
- sudo apt-get install libicu-dev
- sudo apt-get install libssl-dev
- sudo apt-get install libunwind8
- sudo apt-get install zlib1g
- sudo apt-get install libstdc++6
- curl https://download.microsoft.com/download/B/4/6/B4678511-01F4-4F97-902B-0E58A985932A/dotnet-dev-debian-x64.1.0.0-rc4-004771.tar.gz -o /tmp/dotnet.tar.gz
- sudo mkdir -p /opt/dotnet
- sudo tar zxf /tmp/dotnet.tar.gz -C /opt/dotnet
- sudo ln -s /opt/dotnet/dotnet /usr/local/bin
test:
override:
- ./build.sh
post:
- mkdir -p $CIRCLE_TEST_REPORTS/junit/
- sed -i '1 s/^\xef\xbb\xbf//' .*/junit-results.xml
- find . -type f -regex ".*/junit-results.xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;
- ./build.sh
Loading