Skip to content
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

[WIP] xUnit #196

Closed
wants to merge 22 commits into from
Closed
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: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ build/
packages/
paket-files
TestResult.xml
junit-results.xml
junit-results.xml
exercises/obj/
exercises/bin/
20 changes: 4 additions & 16 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#r "./packages/FAKE/tools/FakeLib.dll"

open Fake
open Fake.Testing.NUnit3
open Fake.Testing.XUnit2

// Directories
let buildDir = "./build/"
Expand All @@ -11,7 +11,6 @@ let sourceDir = "./exercises/"
// Files
let solutionFile = buildDir @@ "/exercises.csproj"
let compiledOutput = buildDir @@ "xcsharp.dll"
let nunitToJunitTransformFile = "./paket-files" @@ "nunit" @@ "nunit-transforms" @@ "nunit3-junit" @@ "nunit3-junit.xslt"

// Targets
Target "PrepareUnchanged" (fun _ ->
Expand All @@ -28,7 +27,7 @@ Target "PrepareTests" (fun _ ->
CleanDirs [buildDir]
CopyDir buildDir sourceDir allFiles

let ignorePattern = "(\[Ignore\(\"Remove to run test\"\)]|, Ignore = \"Remove to run test case\")"
let ignorePattern = "Skip\s*=\s*\"Remove to run test\""

!! (buildDir @@ "**/*Test.cs")
|> RegexReplaceInFilesWithEncoding ignorePattern "" System.Text.Encoding.UTF8
Expand All @@ -40,19 +39,8 @@ Target "BuildTests" (fun _ ->
)

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 })
[compiledOutput]
|> xUnit2 (fun p -> { p with ShadowCopy = false })
)

// Build order
Expand Down
6 changes: 1 addition & 5 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ dependencies:
- sudo apt-get install mono-complete
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
43 changes: 16 additions & 27 deletions exercises/accumulate/AccumulateTest.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Xunit;

[TestFixture]
public class AccumulateTest
{
[Test]
[Fact]
public void Empty_accumulation_produces_empty_accumulation()
{
Assert.That(new int[0].Accumulate(x => x * x), Is.EqualTo(new int[0]));
Assert.Equal(new int[0], new int[0].Accumulate(x => x * x));
}

[Ignore("Remove to run test")]
[Test]
[Fact(Skip = "Remove to run test")]
public void Accumulate_squares()
{
Assert.That(new[] { 1, 2, 3 }.Accumulate(x => x * x), Is.EqualTo(new[] { 1, 4, 9 }));
Assert.Equal(new[] { 1, 4, 9 }, new[] { 1, 2, 3 }.Accumulate(x => x * x));
}

[Ignore("Remove to run test")]
[Test]
[Fact(Skip = "Remove to run test")]
public void Accumulate_upcases()
{
Assert.That(new List<string> { "hello", "world" }.Accumulate(x => x.ToUpper()),
Is.EqualTo(new List<string> { "HELLO", "WORLD" }));
Assert.Equal(new List<string> { "HELLO", "WORLD" }, new List<string> { "hello", "world" }.Accumulate(x => x.ToUpper()));
}

[Ignore("Remove to run test")]
[Test]
[Fact(Skip = "Remove to run test")]
public void Accumulate_reversed_strings()
{
Assert.That("the quick brown fox etc".Split(' ').Accumulate(Reverse),
Is.EqualTo("eht kciuq nworb xof cte".Split(' ')));
Assert.Equal("eht kciuq nworb xof cte".Split(' '), "the quick brown fox etc".Split(' ').Accumulate(Reverse));
}

private static string Reverse(string value)
Expand All @@ -42,33 +36,28 @@ private static string Reverse(string value)
return new string(array);
}

[Ignore("Remove to run test")]
[Test]
[Fact(Skip = "Remove to run test")]
public void Accumulate_within_accumulate()
{
var actual = new[] { "a", "b", "c" }.Accumulate(c =>
string.Join(" ", new[] { "1", "2", "3" }.Accumulate(d => c + d)));
Assert.That(actual, Is.EqualTo(new[] { "a1 a2 a3", "b1 b2 b3", "c1 c2 c3" }));
Assert.Equal(new[] { "a1 a2 a3", "b1 b2 b3", "c1 c2 c3" }, actual);
}

[Ignore("Remove to run test")]
[Test]
[Fact(Skip = "Remove to run test")]
public void Accumulate_is_lazy()
{
var counter = 0;
var accumulation = new[] { 1, 2, 3 }.Accumulate(x => x * counter++);

Assert.That(counter, Is.EqualTo(0));
Assert.Equal(0, counter);
accumulation.ToList();
Assert.That(counter, Is.EqualTo(3));
Assert.Equal(3, counter);
}

[Ignore("Remove to run test")]
[Test]
[Fact(Skip = "Remove to run test")]
public void Accumulate_allows_different_return_type()
{
Assert.That(
new[] { 1, 2, 3 }.Accumulate(x => x.ToString()),
Is.EqualTo(new[] { "1", "2", "3" }));
Assert.Equal(new[] { "1", "2", "3" }, new[] { 1, 2, 3 }.Accumulate(x => x.ToString()));
}
}
37 changes: 17 additions & 20 deletions exercises/acronym/AcronymTest.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
namespace Exercism
{
using NUnit.Framework;
using Xunit;

[TestFixture]
public class AcronymTest
public class AcronymTest
{
[Fact]
public void Empty_string_abbreviated_to_empty_string()
{
[Test]
public void Empty_string_abbreviated_to_empty_string()
{
Assert.That(Acronym.Abbreviate(string.Empty), Is.EqualTo(string.Empty));
}
Assert.Equal(string.Empty, Acronym.Abbreviate(string.Empty));
}

[TestCase("Portable Network Graphics", ExpectedResult = "PNG", Ignore = "Remove to run test case")]
[TestCase("Ruby on Rails", ExpectedResult = "ROR", Ignore = "Remove to run test case")]
[TestCase("HyperText Markup Language", ExpectedResult = "HTML", Ignore = "Remove to run test case")]
[TestCase("First In, First Out", ExpectedResult = "FIFO", Ignore = "Remove to run test case")]
[TestCase("PHP: Hypertext Preprocessor", ExpectedResult = "PHP", Ignore = "Remove to run test case")]
[TestCase("Complementary metal-oxide semiconductor", ExpectedResult = "CMOS", Ignore = "Remove to run test case")]
public string Phrase_abbreviated_to_acronym(string phrase)
{
return Acronym.Abbreviate(phrase);
}
[Theory(Skip = "Remove to run test")]
[InlineData("Portable Network Graphics", "PNG")]
[InlineData("Ruby on Rails", "ROR")]
[InlineData("HyperText Markup Language", "HTML")]
[InlineData("First In, First Out", "FIFO")]
[InlineData("PHP: Hypertext Preprocessor", "PHP")]
[InlineData("Complementary metal-oxide semiconductor", "CMOS")]
public void Phrase_abbreviated_to_acronym(string phrase, string expected)
{
Assert.Equal(expected, Acronym.Abbreviate(phrase));
}
}
25 changes: 11 additions & 14 deletions exercises/acronym/Example.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
namespace Exercism
{
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

public static class Acronym
public static class Acronym
{
public static string Abbreviate(string phrase)
{
public static string Abbreviate(string phrase)
{
return Words(phrase).Aggregate("", (abbr, word) => abbr + char.ToUpperInvariant(word[0]));
}
return Words(phrase).Aggregate("", (abbr, word) => abbr + char.ToUpperInvariant(word[0]));
}

private static IEnumerable<string> Words(string phrase)
{
return Regex.Matches(phrase, "[A-Z]+[a-z]*|[a-z]+").Cast<Match>().Select(m => m.Value);
}
private static IEnumerable<string> Words(string phrase)
{
return Regex.Matches(phrase, "[A-Z]+[a-z]*|[a-z]+").Cast<Match>().Select(m => m.Value);
}
}
Loading