Skip to content

Commit

Permalink
Merge pull request #28
Browse files Browse the repository at this point in the history
V2.1.0
  • Loading branch information
th3oth3rjak3 authored Dec 31, 2023
2 parents a108f1a + 5e7a9e6 commit 5f24ed9
Show file tree
Hide file tree
Showing 15 changed files with 1,103 additions and 334 deletions.
20 changes: 20 additions & 0 deletions DocumentationHelp.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Getting Started\n",
"\n",
"MkDocs uses a python package installed locally in the virtual environment. In order to run the documentation site to inspect it locally before publishing, run the command `mkdocs serve`."
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
18 changes: 8 additions & 10 deletions Functional.Test/Common/CommonExtensionTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;

using static Functional.Common.CommonExtensions;

namespace Functional.Test.Common;
Expand All @@ -24,7 +23,7 @@ public void MapShouldConvertIntToString() =>
/// </summary>
[TestMethod]
public void ItShouldTapResults() =>
new TestObject() { Value = 1 }
new TestObject { Value = 1 }
.Tap(objToChange => objToChange.Value = 2)
.ShouldBeEquivalentTo(new TestObject() { Value = 2 });

Expand Down Expand Up @@ -108,14 +107,14 @@ public void ConsShouldAddItemsToAnImmutableList() =>
"1",
"2",
}
.Pipe(strs => ImmutableList<string>.Empty.AddRange(strs))
.Tap(strs => Cons("1", "2").ShouldBeEquivalentTo(strs))
.Pipe(strings => ImmutableList<string>.Empty.AddRange(strings))
.Tap(strings => Cons("1", "2").ShouldBeEquivalentTo(strings))
.Ignore();

/// <summary>
/// A test object to mock data mutation behavior.
/// </summary>
internal class TestObject
private class TestObject
{
internal int Value { get; set; }

Expand All @@ -132,21 +131,20 @@ internal Task<int> AddOneAsync()
/// A test record to verify behavior mapping with records.
/// </summary>
/// <param name="Value">The value to store.</param>
internal record TestRecord(int Value);
private record TestRecord(int Value);

[TestMethod]
public async Task ItShouldAllowActionsPassedToTapAsync() =>
await new TestObject() { Value = 1 }
await new TestObject { Value = 1 }
.AsAsync()
.TapAsync(obj => obj.AddOne())
.TapAsync(obj => obj.Value.ShouldBe(2));

[TestMethod]
public async Task ItShouldAllowTaskMappersToBePassedToTapAsync() =>
await new TestObject() { Value = 1 }
await new TestObject { Value = 1 }
.AsAsync()
.PipeAsync(obj => obj.AddOneAsync())
.TapAsync(obj => Task.FromResult(obj))
.TapAsync(Task.FromResult)
.TapAsync(number => number.ShouldBe(2));

}
124 changes: 122 additions & 2 deletions Functional.Test/Options/OptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ public async Task ItShouldHandleAsyncNoneOptions() =>
public async Task ItShouldHandleAsyncSomeOptions() =>
await AlwaysReturnsNullableString("input")
.Optional()
.TapAsync(result => result.ShouldBeEquivalentTo(Option.Some("input")));
.TapAsync(result => result.ShouldBeEquivalentTo("input".Some()));

[TestMethod]
public async Task ItShouldMapOptionOfTaskOfString() =>
await Option.Some("input")
await "input".Some()
.Map(input => input.AsAsync())
.MapAsync(value => value + "!")
.ReduceAsync("Oops.")
Expand Down Expand Up @@ -452,4 +452,124 @@ await Option.None<string>()

msg.ShouldBe("None");
}

[TestMethod]
public async Task ItShouldNotReturnTaskOfTaskWhenSome()
{
var taskOfTask =
"something"
.Optional()
.AsAsync()
.MatchAsync(
some => some.AsAsync(),
() => "none".AsAsync());

(await taskOfTask).ShouldBeOfType<string>();
}

[TestMethod]
public async Task ItShouldNotReturnTaskOfTaskWhenNone()
{
var taskOfTask =
Option.None<string>()
.AsAsync()
.MatchAsync(
some => some.AsAsync(),
() => "none".AsAsync());

(await taskOfTask).ShouldBeOfType<string>();
}

[TestMethod]
public async Task ItShouldNotReturnTaskOfTaskWhenSome1()
{
var taskOfTask =
"something"
.Optional()
.AsAsync()
.MatchAsync(
some => some.AsAsync(),
() => "none");

(await taskOfTask).ShouldBeOfType<string>();
}

[TestMethod]
public async Task ItShouldNotReturnTaskOfTaskWhenNone1()
{
var taskOfTask =
Option.None<string>()
.AsAsync()
.MatchAsync(
some => some.AsAsync(),
() => "none");

(await taskOfTask).ShouldBeOfType<string>();
}

[TestMethod]
public async Task ItShouldNotReturnTaskOfTaskWhenSome2()
{
var taskOfTask =
"something"
.Optional()
.AsAsync()
.MatchAsync(
some => some,
() => "none".AsAsync());

(await taskOfTask).ShouldBeOfType<string>();
}

[TestMethod]
public async Task ItShouldNotReturnTaskOfTaskWhenNone2()
{
var taskOfTask =
Option.None<string>()
.AsAsync()
.MatchAsync(
some => some,
() => "none".AsAsync());

(await taskOfTask).ShouldBeOfType<string>();
}

[TestMethod]
public async Task ItShouldNotReturnTaskOfTaskWhenSome3()
{
var taskOfTask =
"something"
.Optional()
.AsAsync()
.MatchAsync(
some => some,
() => "none");

(await taskOfTask).ShouldBeOfType<string>();
}

[TestMethod]
public async Task ItShouldNotReturnTaskOfTaskWhenNone3()
{
var taskOfTask =
Option.None<string>()
.AsAsync()
.MatchAsync(
some => some,
() => "none");

(await taskOfTask).ShouldBeOfType<string>();
}

[TestMethod]
public async Task ItShouldHandleValueTasks()
{
var option =
ValueTask
.FromResult(1)
.Optional();

(await option)
.ShouldBeOfType<Option<int>>();
}
}
Loading

0 comments on commit 5f24ed9

Please sign in to comment.