Skip to content

Commit

Permalink
Merge pull request #12 from Meerownymous/i11-add-map-tuple-constructors
Browse files Browse the repository at this point in the history
feat: introduce map by tuples
  • Loading branch information
Meerownymous authored Dec 17, 2024
2 parents 965d52a + f788c47 commit c1858fb
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 869 deletions.
827 changes: 11 additions & 816 deletions src/Tonga/Map/AsMap.cs

Large diffs are not rendered by default.

26 changes: 18 additions & 8 deletions tests/Tonga.Tests/Map/AsMapTest.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using Xunit;
using System.Threading.Tasks;
using Tonga.Enumerable;
using Tonga.Map;
using Tonga.Scalar;
using Tonga.Tests;
using System.Diagnostics;
using System.Threading.Tasks;
using Xunit;

namespace Tonga.Map.Tests
namespace Tonga.Tests.Map
{
public sealed class AsMapTests
{
Expand Down Expand Up @@ -42,6 +40,18 @@ public void MapsKeysToValues()
);
}

[Fact]
public void BuildsFromTuples()
{
Assert.Equal(
20,
AsMap._(
(45, 10),
(33, 20)
)[33]
);
}

[Theory]
[InlineData(12, 39478624)]
[InlineData(24, 60208801)]
Expand Down Expand Up @@ -198,4 +208,4 @@ public void BuildsFromInputsFasterThanMap()
);
}
}
}
}
7 changes: 3 additions & 4 deletions tests/Tonga.Tests/Map/AsPairTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@


using System;
using Tonga.Map;
using Xunit;

namespace Tonga.Map.Tests
namespace Tonga.Tests.Map
{
public sealed class AsPairTests
{
Expand Down Expand Up @@ -45,4 +44,4 @@ public void KnowsAboutBeingNotLazy()
Assert.False(AsPair._("2", "4").IsLazy());
}
}
}
}
19 changes: 9 additions & 10 deletions tests/Tonga.Tests/Map/DeepMapTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Diagnostics;
using Tonga.Map;
using Xunit;

namespace Tonga.Map.Tests
namespace Tonga.Tests.Map
{
public sealed class DeepMap
{
Expand All @@ -14,10 +13,10 @@ public void RetrievesValueByDiggingDown()
new DeepMap<string[], string, int>(
digDown: key => key[0],
AsMap._(
AsPair._(new string[] { "one", "rubbish" }, 1),
AsPair._(new string[] { "two", "irrelevant stuff" }, 2)
(["one", "rubbish"], 1),
(new[] { "two", "irrelevant stuff" }, 2)
)
)[new string[] { "one", "otherthings" }]
)[["one", "otherthings"]]
);
}

Expand All @@ -29,12 +28,12 @@ public void CanBeRefined()
new DeepMap<string[], string, int>(
digDown: key => key[0],
AsMap._(
AsPair._(new string[] { "one", "rubbish" }, 1),
AsPair._(new string[] { "two", "irrelevant stuff" }, 2)
(new[] { "one", "rubbish" }, 1),
(new[] { "two", "irrelevant stuff" }, 2)
)
)
.With(AsPair._(new string[] { "three", "trash" }, 3))
[new string[] { "three", "otherthings" }]
.With(AsPair._(new[] { "three", "trash" }, 3))
[["three", "otherthings"]]
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Tonga.Tests/Map/EmptyTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@



using Tonga.Map;
using Xunit;

namespace Tonga.Map.Tests
namespace Tonga.Tests.Map
{
public sealed class EmptyMapTests
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Tonga.Tests/Map/FallbackTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using Tonga.Map;
using Xunit;

namespace Tonga.Map.Tests
namespace Tonga.Tests.Map
{
public class FallbackMapTests
{
Expand Down
7 changes: 3 additions & 4 deletions tests/Tonga.Tests/Map/GroupedTest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@


using Xunit;
using Tonga.Func;
using Tonga.IO;
using Tonga.List;
using Tonga.Map;
using Tonga.Number;
using Tonga.Scalar;
using Xunit;

namespace Tonga.Map.Tests
namespace Tonga.Tests.Map
{
public sealed class GroupedTest
{
Expand Down
7 changes: 2 additions & 5 deletions tests/Tonga.Tests/Map/MapEnvelopeTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@



using System;
using System.Collections.Generic;
using Tonga.Map;
using Xunit;

namespace Tonga.Map.Tests
namespace Tonga.Tests.Map
{
public class MapEnvelopeTest
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Tonga.Tests/Map/MergedTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@


using Tonga.Map;
using Xunit;

namespace Tonga.Map.Tests
namespace Tonga.Tests.Map
{
public sealed class JoinedTests
{
Expand Down
6 changes: 2 additions & 4 deletions tests/Tonga.Tests/Map/NoNullsTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@


using System;
using System.Collections.Generic;
using Tonga.Map;
using Xunit;

namespace Tonga.Map.Tests
namespace Tonga.Tests.Map
{
public class MapNoNullTest
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Tonga.Tests/Map/OneTimePairTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using Tonga.Map;
using Xunit;

namespace Tonga.Map.Tests
namespace Tonga.Tests.Map
{
public sealed class OneTimePairTests
{
Expand Down
18 changes: 9 additions & 9 deletions tests/Tonga.Tests/Map/SortedTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public void ValueStillBehindCorrectKeyMap(int key, int expectedValue)
{
var unsorted =
AsMap._(
1, 4,
6, 3,
-5, 2
(1, 4),
(6, 3),
(-5, 2)
);

var sorted = Sorted._(unsorted);
Expand Down Expand Up @@ -56,9 +56,9 @@ public void SortsByFunction(int index, int expectedKey)
ItemAt._(
Sorted._(
AsMap._(
1, 4,
6, 3,
-5, 2
(1, 4),
(6, 3),
(-5, 2)
),
(a, b) => a.CompareTo(b)
)
Expand All @@ -81,9 +81,9 @@ public void DefaultComparerSortsByKey(int index, int expectedKey)
AsList._(
Sorted._(
AsMap._(
1, 4,
6, 3,
-5, 2
(1, 4),
(6, 3),
(-5, 2)
)
).Pairs()
)[index]
Expand Down
3 changes: 2 additions & 1 deletion tests/Tonga.Tests/Map/StickyTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Tonga.Map;
using Xunit;

namespace Tonga.Map.Tests
namespace Tonga.Tests.Map
{
public sealed class StickyTests
{
Expand Down
6 changes: 2 additions & 4 deletions tests/Tonga.Tests/Map/VersionMapTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@


using System;
using Xunit;
using Tonga.Map;
using Xunit;

namespace Tonga.Map.Tests
namespace Tonga.Tests.Map
{
public sealed class VersionMapTests
{
Expand Down

0 comments on commit c1858fb

Please sign in to comment.