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

Implemented collection methods so that they crash on nulls #158

Merged
merged 5 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -91,82 +91,82 @@ public void FirstOption()
var x = StringEnumerable.FirstOption();
}

// // Last Result - 25.8.2023 - 14.6 ns - 40 B
// [Benchmark]
// public void SingleOption_Empty()
// {
// var x = StringStack_Empty.SingleOption();
// }
//
// // Last Result - 25.8.2023 - 23.6 ns - 72 B
// [Benchmark]
// public void SingleOption_Single()
// {
// var x = StringStack_Single.SingleOption();
// }
//
// // Last Result - 25.8.2023 - 22.0 ns - 40 B
// [Benchmark]
// public void SingleOption()
// {
// var x = StringStack_Many.SingleOption();
// }
//
// // Last Result - 25.8.2023 - 1.4 ns - 0 B
// [Benchmark]
// public void IsMultiple_Stack()
// {
// var x = StringStack_Many.IsMultiple();
// }
//
// // Last Result - 25.8.2023 - 53.8 ns - 144 B
// [Benchmark]
// public void IsMultiple_Enumerable()
// {
// var x = StringEnumerable.IsMultiple();
// }
//
// // Last Result - 25.8.2023 - 6.9 ns - 0 B
// [Benchmark]
// public void IsMultiple_ArrayAsEnumerable()
// {
// var x = StringEnumerable_Array.IsMultiple();
// }
//
// // Last Result - 25.8.2023 - 2.2 ns - 0 B
// [Benchmark]
// public void IsMultiple_Array()
// {
// var x = StringArray.IsMultiple();
// }
//
// // Last Result - 25.8.2023 - 1.4 ns - 0 B
// [Benchmark]
// public void IsSingle_Stack()
// {
// var x = StringStack_Many.IsSingle();
// }
//
// // Last Result - 25.8.2023 - 54.2 ns - 144 B
// [Benchmark]
// public void IsSingle_Enumerable()
// {
// var x = StringEnumerable.IsSingle();
// }
//
// // Last Result - 25.8.2023 - 5.3 ns - 0 B
// [Benchmark]
// public void IsSingle_ArrayAsEnumerable()
// {
// var x = StringEnumerable_Array.IsSingle();
// }
//
// // Last Result - 25.8.2023 - 2.2 ns - 0 B
// [Benchmark]
// public void IsSingle_Array()
// {
// var x = StringArray.IsSingle();
// }
// Last Result - 25.8.2023 - 14.6 ns - 40 B
[Benchmark]
public void SingleOption_Empty()
{
var x = StringStack_Empty.SingleOption();
}

// Last Result - 25.8.2023 - 23.6 ns - 72 B
[Benchmark]
public void SingleOption_Single()
{
var x = StringStack_Single.SingleOption();
}

// Last Result - 25.8.2023 - 22.0 ns - 40 B
[Benchmark]
public void SingleOption()
{
var x = StringStack_Many.SingleOption();
}

// Last Result - 25.8.2023 - 1.4 ns - 0 B
[Benchmark]
public void IsMultiple_Stack()
{
var x = StringStack_Many.IsMultiple();
}

// Last Result - 25.8.2023 - 53.8 ns - 144 B
[Benchmark]
public void IsMultiple_Enumerable()
{
var x = StringEnumerable.IsMultiple();
}

// Last Result - 25.8.2023 - 6.9 ns - 0 B
[Benchmark]
public void IsMultiple_ArrayAsEnumerable()
{
var x = StringEnumerable_Array.IsMultiple();
}

// Last Result - 25.8.2023 - 2.2 ns - 0 B
[Benchmark]
public void IsMultiple_Array()
{
var x = StringArray.IsMultiple();
}

// Last Result - 25.8.2023 - 1.4 ns - 0 B
[Benchmark]
public void IsSingle_Stack()
{
var x = StringStack_Many.IsSingle();
}

// Last Result - 25.8.2023 - 54.2 ns - 144 B
[Benchmark]
public void IsSingle_Enumerable()
{
var x = StringEnumerable.IsSingle();
}

// Last Result - 25.8.2023 - 5.3 ns - 0 B
[Benchmark]
public void IsSingle_ArrayAsEnumerable()
{
var x = StringEnumerable_Array.IsSingle();
}

// Last Result - 25.8.2023 - 2.2 ns - 0 B
[Benchmark]
public void IsSingle_Array()
{
var x = StringArray.IsSingle();
}

// Last Result - 25.8.2023 - 121.5 ns - 416 B
[Benchmark]
Expand Down
70 changes: 30 additions & 40 deletions src/FuncSharp.Tests/Collections/IsMultipleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,34 @@ namespace FuncSharp.Tests.Collections.INonEmptyEnumerable;

public class IsMultipleTests
{
// [Fact]
// public void IsMultiple_null()
// {
// IEnumerable<string> enumerableNull = null;
// string[] arrayNull = null;
//
// Assert.False(enumerableNull.IsMultiple());
// Assert.False(arrayNull.IsMultiple());
// }
//
// [Fact]
// public void IsMultiple_Empty()
// {
// IEnumerable<string> enumerableEmpty = Enumerable.Empty<string>();
// string[] arrayEmpty = new string[]{};
//
//
// Assert.False(enumerableEmpty.IsMultiple());
// Assert.False(arrayEmpty.IsMultiple());
// }
//
// [Fact]
// public void IsMultiple_Single()
// {
// IEnumerable<string> enumerableSingle = Enumerable.Repeat("A potato", 1);
// string[] arraySingle = new []{"A potato"};
//
// Assert.False(enumerableSingle.IsMultiple());
// Assert.False(arraySingle.IsMultiple());
// }
//
// [Fact]
// public void IsMultiple_Multiple()
// {
// IEnumerable<string> enumerableMultiple = Enumerable.Range(0, 10).Select(i => $"{i} potatoes");
// string[] arrayMultiple = Enumerable.Range(0, 10).Select(i => $"{i} potatoes").ToArray();
//
// Assert.True(enumerableMultiple.IsMultiple());
// Assert.True(arrayMultiple.IsMultiple());
// }
[Fact]
public void IsMultiple_Empty()
{
IEnumerable<string> enumerableEmpty = Enumerable.Empty<string>();
string[] arrayEmpty = new string[]{};


Assert.False(enumerableEmpty.IsMultiple());
Assert.False(arrayEmpty.IsMultiple());
}

[Fact]
public void IsMultiple_Single()
{
IEnumerable<string> enumerableSingle = Enumerable.Repeat("A potato", 1);
string[] arraySingle = new []{"A potato"};

Assert.False(enumerableSingle.IsMultiple());
Assert.False(arraySingle.IsMultiple());
}

[Fact]
public void IsMultiple_Multiple()
{
IEnumerable<string> enumerableMultiple = Enumerable.Range(0, 10).Select(i => $"{i} potatoes");
string[] arrayMultiple = Enumerable.Range(0, 10).Select(i => $"{i} potatoes").ToArray();

Assert.True(enumerableMultiple.IsMultiple());
Assert.True(arrayMultiple.IsMultiple());
}
}
68 changes: 29 additions & 39 deletions src/FuncSharp.Tests/Collections/IsSingleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,33 @@ namespace FuncSharp.Tests.Collections.INonEmptyEnumerable;

public class IsSingleTests
{
// [Fact]
// public void IsSingle_null()
// {
// IEnumerable<string> enumerableNull = null;
// string[] arrayNull = null;
//
// Assert.False(enumerableNull.IsSingle());
// Assert.False(arrayNull.IsSingle());
// }
//
// [Fact]
// public void IsSingle_Empty()
// {
// IEnumerable<string> enumerableEmpty = Enumerable.Empty<string>();
// string[] arrayEmpty = new string[]{};
//
// Assert.False(enumerableEmpty.IsSingle());
// Assert.False(arrayEmpty.IsSingle());
// }
//
// [Fact]
// public void IsSingle_Single()
// {
// IEnumerable<string> enumerableSingle = Enumerable.Repeat("A potato", 1);
// string[] arraySingle = new []{"A potato"};
//
// Assert.True(enumerableSingle.IsSingle());
// Assert.True(arraySingle.IsSingle());
// }
//
// [Fact]
// public void IsSingle_Multiple()
// {
// IEnumerable<string> enumerableMultiple = Enumerable.Range(0, 10).Select(i => $"{i} potatoes");
// string[] arrayMultiple = Enumerable.Range(0, 10).Select(i => $"{i} potatoes").ToArray();
//
// Assert.False(enumerableMultiple.IsSingle());
// Assert.False(arrayMultiple.IsSingle());
// }
[Fact]
public void IsSingle_Empty()
{
IEnumerable<string> enumerableEmpty = Enumerable.Empty<string>();
string[] arrayEmpty = new string[]{};

Assert.False(enumerableEmpty.IsSingle());
Assert.False(arrayEmpty.IsSingle());
}

[Fact]
public void IsSingle_Single()
{
IEnumerable<string> enumerableSingle = Enumerable.Repeat("A potato", 1);
string[] arraySingle = new []{"A potato"};

Assert.True(enumerableSingle.IsSingle());
Assert.True(arraySingle.IsSingle());
}

[Fact]
public void IsSingle_Multiple()
{
IEnumerable<string> enumerableMultiple = Enumerable.Range(0, 10).Select(i => $"{i} potatoes");
string[] arrayMultiple = Enumerable.Range(0, 10).Select(i => $"{i} potatoes").ToArray();

Assert.False(enumerableMultiple.IsSingle());
Assert.False(arrayMultiple.IsSingle());
}
}
Loading