Skip to content

Commit

Permalink
⏮ Switch to file scope namespaces (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcscharf authored Jan 10, 2022
1 parent 3f7ce92 commit 98d88a6
Show file tree
Hide file tree
Showing 171 changed files with 13,282 additions and 13,448 deletions.
83 changes: 41 additions & 42 deletions Bearded.Utilities.Benchmarks/Linq/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,63 @@
using Bearded.Utilities.Linq;
using BenchmarkDotNet.Attributes;

namespace Bearded.Utilities.Benchmarks.Linq
namespace Bearded.Utilities.Benchmarks.Linq;

[SuppressMessage("ReSharper", "ClassCanBeSealed.Global")]
public sealed class Extensions
{
[SuppressMessage("ReSharper", "ClassCanBeSealed.Global")]
public sealed class Extensions
private const int seed = 1337;
private const int count = 10000;

public abstract class ListBenchmark
{
private const int seed = 1337;
private const int count = 10000;
protected List<int> List { get; }
protected Random Random { get; }

public abstract class ListBenchmark
protected ListBenchmark()
{
protected List<int> List { get; }
protected Random Random { get; }

protected ListBenchmark()
List = new List<int>(count);
Random = new Random(seed);
for (var i = 0; i < count; i++)
{
List = new List<int>(count);
Random = new Random(seed);
for (var i = 0; i < count; i++)
{
List.Add(Random.Next());
}
List.Add(Random.Next());
}
}
}

public class RandomElement : ListBenchmark
public class RandomElement : ListBenchmark
{
[Benchmark]
public int GetRandomElement()
{
[Benchmark]
public int GetRandomElement()
{
return List.RandomElement();
}
return List.RandomElement();
}
}

public class RandomSubset : ListBenchmark
{
[Params(1, 100, count / 2, count - 100, count)]
public int SubsetSize { get; set; }
public class RandomSubset : ListBenchmark
{
[Params(1, 100, count / 2, count - 100, count)]
public int SubsetSize { get; set; }

[Benchmark]
public List<int> GetRandomSubset()
{
return List.RandomSubset(SubsetSize);
}
[Benchmark]
public List<int> GetRandomSubset()
{
return List.RandomSubset(SubsetSize);
}
}

public class Shuffle : ListBenchmark
public class Shuffle : ListBenchmark
{
[Benchmark]
public void ShuffleInPlace()
{
[Benchmark]
public void ShuffleInPlace()
{
List.Shuffle(Random);
}
List.Shuffle(Random);
}

[Benchmark]
public IList<int> Shuffled()
{
return List.Shuffled(Random);
}
[Benchmark]
public IList<int> Shuffled()
{
return List.Shuffled(Random);
}
}
}
11 changes: 5 additions & 6 deletions Bearded.Utilities.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;

namespace Bearded.Utilities.Benchmarks
namespace Bearded.Utilities.Benchmarks;

static class Program
{
static class Program
static void Main(string[] args)
{
static void Main(string[] args)
{
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, new DebugInProcessConfig());
}
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, new DebugInProcessConfig());
}
}
191 changes: 95 additions & 96 deletions Bearded.Utilities.Testing.Tests/Core/MaybeAssertionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,147 +3,146 @@
using Xunit;
using Xunit.Sdk;

namespace Bearded.Utilities.Testing.Tests
namespace Bearded.Utilities.Testing.Tests;

public sealed class MaybeAssertionsTests
{
public sealed class MaybeAssertionsTests
public sealed class BeJustWithNoParameter
{
public sealed class BeJustWithNoParameter
[Fact]
public void SucceedsWhenJust()
{
[Fact]
public void SucceedsWhenJust()
{
var maybe = Maybe.Just(100);
var maybe = Maybe.Just(100);

Action assertion = () => maybe.Should().BeJust();
Action assertion = () => maybe.Should().BeJust();

assertion.Should().NotThrow();
}
assertion.Should().NotThrow();
}

[Fact]
public void FailsWhenNothing()
{
var maybe = Maybe<int>.Nothing;
[Fact]
public void FailsWhenNothing()
{
var maybe = Maybe<int>.Nothing;

Action assertion = () => maybe.Should().BeJust();
Action assertion = () => maybe.Should().BeJust();

assertion.Should().Throw<XunitException>();
}
assertion.Should().Throw<XunitException>();
}

[Fact]
public void ReturnsAndConstraintThatSucceedsAsExpected()
{
var maybe = Maybe.Just(100);
[Fact]
public void ReturnsAndConstraintThatSucceedsAsExpected()
{
var maybe = Maybe.Just(100);

Action assertion = () => maybe.Should().BeJust().And.Should().NotBeNull();
Action assertion = () => maybe.Should().BeJust().And.Should().NotBeNull();

assertion.Should().NotThrow();
}
assertion.Should().NotThrow();
}

[Fact]
public void ReturnsAndConstraintThatFailsAsExpected()
{
var maybe = Maybe.Just(100);
[Fact]
public void ReturnsAndConstraintThatFailsAsExpected()
{
var maybe = Maybe.Just(100);

Action assertion = () => maybe.Should().BeJust().And.Should().BeNull();
Action assertion = () => maybe.Should().BeJust().And.Should().BeNull();

assertion.Should().Throw<XunitException>();
}
assertion.Should().Throw<XunitException>();
}

[Fact]
public void FailsWhenNothingEvenIfAndConstraintSucceeds()
{
var maybe = Maybe.Just(100);
[Fact]
public void FailsWhenNothingEvenIfAndConstraintSucceeds()
{
var maybe = Maybe.Just(100);

Action assertion = () => maybe.Should().BeJust().And.Should().NotBeNull();
Action assertion = () => maybe.Should().BeJust().And.Should().NotBeNull();

assertion.Should().NotThrow();
}
assertion.Should().NotThrow();
}

[Fact]
public void ReturnsWhichConstraintThatSucceedsAsExpected()
{
var maybe = Maybe.Just(100);
[Fact]
public void ReturnsWhichConstraintThatSucceedsAsExpected()
{
var maybe = Maybe.Just(100);

Action assertion = () => maybe.Should().BeJust().Which.Should().Be(100);
Action assertion = () => maybe.Should().BeJust().Which.Should().Be(100);

assertion.Should().NotThrow();
}
assertion.Should().NotThrow();
}

[Fact]
public void ReturnsWhichConstraintThatFailsAsExpected()
{
var maybe = Maybe.Just(100);
[Fact]
public void ReturnsWhichConstraintThatFailsAsExpected()
{
var maybe = Maybe.Just(100);

Action assertion = () => maybe.Should().BeJust().Which.Should().Be(200);
Action assertion = () => maybe.Should().BeJust().Which.Should().Be(200);

assertion.Should().Throw<XunitException>();
}
assertion.Should().Throw<XunitException>();
}

[Fact]
public void FailsWhenNothingEvenIfWhichConstraintSucceeds()
{
var maybe = Maybe.Just(100);
[Fact]
public void FailsWhenNothingEvenIfWhichConstraintSucceeds()
{
var maybe = Maybe.Just(100);

Action assertion = () => maybe.Should().BeJust().Which.Should().Be(100);
Action assertion = () => maybe.Should().BeJust().Which.Should().Be(100);

assertion.Should().NotThrow();
}
assertion.Should().NotThrow();
}
}

public sealed class BeJustWithValue
public sealed class BeJustWithValue
{
[Fact]
public void SucceedsWhenJustComparedToSameValue()
{
[Fact]
public void SucceedsWhenJustComparedToSameValue()
{
var maybe = Maybe.Just(100);
var maybe = Maybe.Just(100);

Action assertion = () => maybe.Should().BeJust(100);
Action assertion = () => maybe.Should().BeJust(100);

assertion.Should().NotThrow();
}
assertion.Should().NotThrow();
}

[Fact]
public void FailsWhenJustComparedToDifferentValue()
{
var maybe = Maybe.Just(100);
[Fact]
public void FailsWhenJustComparedToDifferentValue()
{
var maybe = Maybe.Just(100);

Action assertion = () => maybe.Should().BeJust(200);
Action assertion = () => maybe.Should().BeJust(200);

assertion.Should().Throw<XunitException>();
}
assertion.Should().Throw<XunitException>();
}

[Fact]
public void FailsWhenNothing()
{
var maybe = Maybe<int>.Nothing;
[Fact]
public void FailsWhenNothing()
{
var maybe = Maybe<int>.Nothing;

Action assertion = () => maybe.Should().BeJust(200);
Action assertion = () => maybe.Should().BeJust(200);

assertion.Should().Throw<XunitException>();
}
assertion.Should().Throw<XunitException>();
}
}

public sealed class BeNothing
public sealed class BeNothing
{
[Fact]
public void SucceedsWhenNothing()
{
[Fact]
public void SucceedsWhenNothing()
{
var maybe = Maybe<int>.Nothing;
var maybe = Maybe<int>.Nothing;

Action assertion = () => maybe.Should().BeNothing();
Action assertion = () => maybe.Should().BeNothing();

assertion.Should().NotThrow();
}
assertion.Should().NotThrow();
}

[Fact]
public void FailsWhenJust()
{
var maybe = Maybe.Just(100);
[Fact]
public void FailsWhenJust()
{
var maybe = Maybe.Just(100);

Action assertion = () => maybe.Should().BeNothing();
Action assertion = () => maybe.Should().BeNothing();

assertion.Should().Throw<XunitException>();
}
assertion.Should().Throw<XunitException>();
}
}
}
Loading

0 comments on commit 98d88a6

Please sign in to comment.