Skip to content

Commit

Permalink
ToDictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz committed Dec 29, 2024
1 parent 08ef966 commit 9ab786a
Showing 1 changed file with 19 additions and 28 deletions.
47 changes: 19 additions & 28 deletions MoreLinq.Test/ToDictionaryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,28 @@
namespace MoreLinq.Test
{
using System;
using System.Collections.Generic;
using NUnit.Framework;

[TestFixture]
public class ToDictionaryTest
{
static TestingSequence<KeyValuePair<string, int>> Pairs() =>
TestingSequence.Of(KeyValuePair.Create("foo", 123),
KeyValuePair.Create("bar", 456),
KeyValuePair.Create("baz", 789));

static TestingSequence<(string, int)> Couples() =>
TestingSequence.Of(("foo", 123),
("bar", 456),
("baz", 789));

[Test]
public void ToDictionaryWithKeyValuePairs()
{
var pairs = new[]
{
KeyValuePair.Create("foo", 123),
KeyValuePair.Create("bar", 456),
KeyValuePair.Create("baz", 789),
};
using var source = Pairs();

var dict = MoreEnumerable.ToDictionary(pairs);
var dict = MoreEnumerable.ToDictionary(source);

Assert.That(dict["foo"], Is.EqualTo(123));
Assert.That(dict["bar"], Is.EqualTo(456));
Expand All @@ -43,14 +49,9 @@ public void ToDictionaryWithKeyValuePairs()
[Test]
public void ToDictionaryWithCouples()
{
var pairs = new[]
{
("foo", 123),
("bar", 456),
("baz", 789),
};
using var source = Couples();

var dict = MoreEnumerable.ToDictionary(pairs);
var dict = MoreEnumerable.ToDictionary(source);

Assert.That(dict["foo"], Is.EqualTo(123));
Assert.That(dict["bar"], Is.EqualTo(456));
Expand All @@ -60,14 +61,9 @@ public void ToDictionaryWithCouples()
[Test]
public void ToDictionaryWithKeyValuePairsWithComparer()
{
var pairs = new[]
{
KeyValuePair.Create("foo", 123),
KeyValuePair.Create("bar", 456),
KeyValuePair.Create("baz", 789),
};
using var source = Pairs();

var dict = MoreEnumerable.ToDictionary(pairs, StringComparer.OrdinalIgnoreCase);
var dict = MoreEnumerable.ToDictionary(source, StringComparer.OrdinalIgnoreCase);

Assert.That(dict["FOO"], Is.EqualTo(123));
Assert.That(dict["BAR"], Is.EqualTo(456));
Expand All @@ -77,14 +73,9 @@ public void ToDictionaryWithKeyValuePairsWithComparer()
[Test]
public void ToDictionaryWithCouplesWithComparer()
{
var pairs = new[]
{
("foo", 123),
("bar", 456),
("baz", 789),
};
using var source = Couples();

var dict = MoreEnumerable.ToDictionary(pairs, StringComparer.OrdinalIgnoreCase);
var dict = MoreEnumerable.ToDictionary(source, StringComparer.OrdinalIgnoreCase);

Assert.That(dict["FOO"], Is.EqualTo(123));
Assert.That(dict["BAR"], Is.EqualTo(456));
Expand Down

0 comments on commit 9ab786a

Please sign in to comment.