Skip to content

Commit 9793fcb

Browse files
Merge pull request #199 from ErikSchierboom/dotnet-core
.NET Core
2 parents cc38c76 + d0ba801 commit 9793fcb

369 files changed

Lines changed: 8355 additions & 4304 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ bin/configlet.exe
66
.fake/
77
.paket/paket.exe
88
.vs/
9+
.vscode/
910
tools/
1011
build/
1112
packages/
1213
paket-files
1314
TestResult.xml
14-
junit-results.xml
15+
junit-results.xml
16+
obj/
17+
bin/
18+
*.userprefs
19+
.idea/

.travis.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
11
language: csharp
2-
2+
sudo: required
3+
dist: trusty
4+
addons:
5+
apt:
6+
sources: ['ubuntu-toolchain-r-test']
7+
packages:
8+
- gettext
9+
- libcurl4-openssl-dev
10+
- libicu-dev
11+
- libssl-dev
12+
- libunwind8
13+
- zlib1g
14+
- libstdc++6
15+
env:
16+
global:
17+
- DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
18+
- DOTNET_CLI_TELEMETRY_OPTOUT: 1
19+
mono:
20+
- 4.0.5
321
os:
422
- linux
5-
- osx
23+
24+
before_install:
25+
- 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
26+
- sudo mkdir -p /opt/dotnet
27+
- sudo tar zxf /tmp/dotnet.tar.gz -C /opt/dotnet
28+
- sudo ln -s /opt/dotnet/dotnet /usr/local/bin
629

730
script:
831
- ./bin/fetch-configlet
932
- ./bin/configlet .
10-
- ./build.sh
33+
- ./build.sh

Zipper.cs

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
public class BinTree<T> : IEquatable<BinTree<T>>
6+
{
7+
public BinTree(T value, BinTree<T> left, BinTree<T> right)
8+
{
9+
Value = value;
10+
Left = left;
11+
Right = right;
12+
}
13+
14+
public BinTree(BinTree<T> tree) : this(tree.Value, tree.Left, tree.Right)
15+
{
16+
}
17+
18+
public T Value { get; }
19+
public BinTree<T> Left { get; }
20+
public BinTree<T> Right { get; }
21+
22+
public bool Equals(BinTree<T> other)
23+
{
24+
if (other == null || !Equals(Value, other.Value))
25+
return false;
26+
27+
if (!ReferenceEquals(Left, other.Left) && (!Left?.Equals(other.Left) ?? false))
28+
return false;
29+
30+
if (!ReferenceEquals(Right, other.Right) && (!Right?.Equals(other.Right) ?? false))
31+
return false;
32+
33+
return true;
34+
}
35+
}
36+
37+
public abstract class BinTreeCrumb<T>
38+
{
39+
public BinTreeCrumb(T value, BinTree<T> tree)
40+
{
41+
Value = value;
42+
Tree = tree;
43+
}
44+
45+
public T Value { get; }
46+
public BinTree<T> Tree { get; }
47+
}
48+
49+
public class BinTreeLeftCrumb<T> : BinTreeCrumb<T>
50+
{
51+
public BinTreeLeftCrumb(T value, BinTree<T> tree) : base(value, tree)
52+
{
53+
}
54+
}
55+
56+
public class BinTreeRightCrumb<T> : BinTreeCrumb<T>
57+
{
58+
public BinTreeRightCrumb(T value, BinTree<T> tree) : base(value, tree)
59+
{
60+
}
61+
}
62+
63+
public class Zipper<T>
64+
{
65+
private readonly T value;
66+
private readonly BinTree<T> left;
67+
private readonly BinTree<T> right;
68+
private readonly List<BinTreeCrumb<T>> crumbs;
69+
70+
public Zipper(T value, BinTree<T> left, BinTree<T> right, List<BinTreeCrumb<T>> crumbs)
71+
{
72+
this.value = value;
73+
this.left = left;
74+
this.right = right;
75+
this.crumbs = crumbs;
76+
}
77+
78+
public T Value => value;
79+
80+
public Zipper<T> SetValue(T newValue) => new Zipper<T>(newValue, left, right, crumbs);
81+
82+
public Zipper<T> SetLeft(BinTree<T> binTree) => new Zipper<T>(value, binTree, right, crumbs);
83+
84+
public Zipper<T> SetRight(BinTree<T> binTree) => new Zipper<T>(value, left, binTree, crumbs);
85+
86+
public Zipper<T> Left()
87+
{
88+
if (left == null)
89+
return null;
90+
91+
var newCrumbs = new[] { new BinTreeLeftCrumb<T>(value, right) }.Concat(crumbs).ToList();
92+
return new Zipper<T>(left.Value, left.Left, left.Right, newCrumbs);
93+
}
94+
95+
public Zipper<T> Right()
96+
{
97+
if (right == null)
98+
return null;
99+
100+
var newCrumbs = new[] { new BinTreeRightCrumb<T>(value, left) }.Concat(crumbs).ToList();
101+
return new Zipper<T>(right.Value, right.Left, right.Right, newCrumbs);
102+
}
103+
104+
public Zipper<T> Up()
105+
{
106+
if (crumbs.Count == 0)
107+
return null;
108+
109+
var firstCrumb = crumbs[0];
110+
var remainingCrumbs = crumbs.Skip(1).ToList();
111+
112+
if (firstCrumb is BinTreeLeftCrumb<T>)
113+
return new Zipper<T>(firstCrumb.Value, new BinTree<T>(value, left, right), firstCrumb.Tree, remainingCrumbs);
114+
115+
if (firstCrumb is BinTreeRightCrumb<T>)
116+
return new Zipper<T>(firstCrumb.Value, firstCrumb.Tree, new BinTree<T>(value, left, right), remainingCrumbs);
117+
118+
return null;
119+
}
120+
121+
public BinTree<T> ToTree()
122+
{
123+
var tree = new BinTree<T>(value, left, right);
124+
125+
foreach (var crumb in crumbs)
126+
{
127+
if (crumb is BinTreeLeftCrumb<T>)
128+
tree = new BinTree<T>(crumb.Value, new BinTree<T>(tree), crumb.Tree);
129+
if (crumb is BinTreeRightCrumb<T>)
130+
tree = new BinTree<T>(crumb.Value, crumb.Tree, new BinTree<T>(tree));
131+
}
132+
133+
return tree;
134+
}
135+
136+
public static Zipper<T> FromTree(BinTree<T> tree) => new Zipper<T>(tree.Value, tree.Left, tree.Right, new List<BinTreeCrumb<T>>());
137+
}

appveyor.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
init:
2+
- 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")
3+
- cmd: c:\dotnet-install.exe /install /quiet
14
build_script:
25
- ps: .\build.cmd
3-
6+
environment:
7+
DOTNET_CLI_TELEMETRY_OPTOUT: true
8+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
49
test: off

build.fsx

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,78 @@
1-
// Include Fake library
21
#r "./packages/FAKE/tools/FakeLib.dll"
32

43
open Fake
5-
open Fake.Testing.NUnit3
4+
open Fake.DotNetCli
5+
open System.Text
66

7-
// Directories
8-
let buildDir = "./build/"
9-
let sourceDir = "./exercises/"
7+
let project = environVarOrDefault "project" "*"
8+
let buildDir = "./build/"
9+
let sourceDir = "./exercises/"
10+
let projectDirs = buildDir @@ project
1011

11-
// Files
12-
let solutionFile = buildDir @@ "/exercises.csproj"
13-
let compiledOutput = buildDir @@ "xcsharp.dll"
14-
let nunitToJunitTransformFile = "./paket-files" @@ "nunit" @@ "nunit-transforms" @@ "nunit3-junit" @@ "nunit3-junit.xslt"
12+
let testFiles = !! (projectDirs @@ "*Test.cs")
13+
let allProjects = !! (projectDirs @@ "*.csproj")
14+
let defaultProjects =
15+
!! (projectDirs @@ "*.csproj") --
16+
(projectDirs @@ "DotDsl.csproj") --
17+
(projectDirs @@ "Hangman.csproj") --
18+
(projectDirs @@ "React.csproj")
19+
let refactoringProjects =
20+
!! (projectDirs @@ "TreeBuilding.csproj") ++
21+
(projectDirs @@ "Ledger.csproj") ++
22+
(projectDirs @@ "Markdown.csproj")
1523

16-
// Targets
17-
Target "PrepareUnchanged" (fun _ ->
18-
CleanDirs [buildDir]
19-
CopyDir buildDir sourceDir allFiles
20-
)
24+
let restore project = DotNetCli.Restore (fun p -> { p with Project = project })
25+
let build project = DotNetCli.Build (fun p -> { p with Project = project })
26+
let test project = DotNetCli.Test (fun p -> { p with Project = project })
27+
28+
let restoreAndBuild project =
29+
restore project
30+
build project
2131

22-
Target "BuildUnchanged" (fun _ ->
23-
MSBuildRelease buildDir "Build" [solutionFile]
24-
|> Log "Build unchanged output: "
32+
let restoreAndTest project =
33+
restore project
34+
test project
35+
36+
Target "Clean" (fun _ ->
37+
DeleteDir buildDir
2538
)
2639

27-
Target "PrepareTests" (fun _ ->
28-
CleanDirs [buildDir]
40+
Target "CopyExercises" (fun _ ->
2941
CopyDir buildDir sourceDir allFiles
42+
)
3043

31-
let ignorePattern = "(\[Ignore\(\"Remove to run test\"\)]|, Ignore = \"Remove to run test case\")"
44+
Target "BuildUsingStubImplementation" (fun _ ->
45+
Seq.iter restoreAndBuild defaultProjects
46+
)
47+
48+
Target "EnableAllTests" (fun _ ->
49+
let skipProperty = "Skip\s*=\s*\"Remove to run test\""
50+
RegexReplaceInFilesWithEncoding skipProperty "" Encoding.UTF8 testFiles
51+
)
3252

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

37-
Target "BuildTests" (fun _ ->
38-
MSBuildRelease buildDir "Build" [solutionFile]
39-
|> Log "Build tests output: "
57+
Target "ReplaceStubWithExampleImplementation" (fun _ ->
58+
let replaceStubWithExampleImplementation project =
59+
let stubFile = filename project + "" |> changeExt ".cs"
60+
let exampleFile = "Example.cs"
61+
RegexReplaceInFileWithEncoding exampleFile stubFile Encoding.UTF8 project
62+
63+
Seq.iter replaceStubWithExampleImplementation allProjects
4064
)
4165

42-
Target "Test" (fun _ ->
43-
if getEnvironmentVarAsBool "APPVEYOR" then
44-
[compiledOutput]
45-
|> NUnit3 (fun p -> { p with
46-
ShadowCopy = false
47-
ToolPath = "nunit3-console.exe" })
48-
else if getEnvironmentVarAsBool "CIRCLECI" then
49-
[compiledOutput]
50-
|> NUnit3 (fun p -> { p with
51-
ShadowCopy = false
52-
ResultSpecs = [sprintf "junit-results.xml;transform=%s" nunitToJunitTransformFile] })
53-
else
54-
[compiledOutput]
55-
|> NUnit3 (fun p -> { p with ShadowCopy = false })
66+
Target "TestUsingExampleImplementation" (fun _ ->
67+
Seq.iter restoreAndTest allProjects
5668
)
5769

58-
// Build order
59-
"PrepareUnchanged"
60-
==> "BuildUnchanged"
61-
==> "PrepareTests"
62-
==> "BuildTests"
63-
==> "Test"
70+
"Clean"
71+
==> "CopyExercises"
72+
==> "BuildUsingStubImplementation"
73+
==> "EnableAllTests"
74+
==> "TestRefactoringProjects"
75+
==> "ReplaceStubWithExampleImplementation"
76+
==> "TestUsingExampleImplementation"
6477

65-
// start build
66-
RunTargetOrDefault "Test"
78+
RunTargetOrDefault "TestUsingExampleImplementation"

circle.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
machine:
22
environment:
33
TERM: xterm-256color
4+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
5+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
46
dependencies:
57
pre:
8+
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
69
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
710
- echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
811
- sudo apt-get update
912
- sudo apt-get install mono-complete
13+
- sudo apt-get install gettext
14+
- sudo apt-get install libcurl4-openssl-dev
15+
- sudo apt-get install libicu-dev
16+
- sudo apt-get install libssl-dev
17+
- sudo apt-get install libunwind8
18+
- sudo apt-get install zlib1g
19+
- sudo apt-get install libstdc++6
20+
- 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
21+
- sudo mkdir -p /opt/dotnet
22+
- sudo tar zxf /tmp/dotnet.tar.gz -C /opt/dotnet
23+
- sudo ln -s /opt/dotnet/dotnet /usr/local/bin
1024
test:
1125
override:
12-
- ./build.sh
13-
post:
14-
- mkdir -p $CIRCLE_TEST_REPORTS/junit/
15-
- sed -i '1 s/^\xef\xbb\xbf//' .*/junit-results.xml
16-
- find . -type f -regex ".*/junit-results.xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;
26+
- ./build.sh

0 commit comments

Comments
 (0)