Skip to content

Commit 9ab786a

Browse files
committed
ToDictionary
1 parent 08ef966 commit 9ab786a

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

MoreLinq.Test/ToDictionaryTest.cs

+19-28
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,28 @@
1818
namespace MoreLinq.Test
1919
{
2020
using System;
21+
using System.Collections.Generic;
2122
using NUnit.Framework;
2223

2324
[TestFixture]
2425
public class ToDictionaryTest
2526
{
27+
static TestingSequence<KeyValuePair<string, int>> Pairs() =>
28+
TestingSequence.Of(KeyValuePair.Create("foo", 123),
29+
KeyValuePair.Create("bar", 456),
30+
KeyValuePair.Create("baz", 789));
31+
32+
static TestingSequence<(string, int)> Couples() =>
33+
TestingSequence.Of(("foo", 123),
34+
("bar", 456),
35+
("baz", 789));
36+
2637
[Test]
2738
public void ToDictionaryWithKeyValuePairs()
2839
{
29-
var pairs = new[]
30-
{
31-
KeyValuePair.Create("foo", 123),
32-
KeyValuePair.Create("bar", 456),
33-
KeyValuePair.Create("baz", 789),
34-
};
40+
using var source = Pairs();
3541

36-
var dict = MoreEnumerable.ToDictionary(pairs);
42+
var dict = MoreEnumerable.ToDictionary(source);
3743

3844
Assert.That(dict["foo"], Is.EqualTo(123));
3945
Assert.That(dict["bar"], Is.EqualTo(456));
@@ -43,14 +49,9 @@ public void ToDictionaryWithKeyValuePairs()
4349
[Test]
4450
public void ToDictionaryWithCouples()
4551
{
46-
var pairs = new[]
47-
{
48-
("foo", 123),
49-
("bar", 456),
50-
("baz", 789),
51-
};
52+
using var source = Couples();
5253

53-
var dict = MoreEnumerable.ToDictionary(pairs);
54+
var dict = MoreEnumerable.ToDictionary(source);
5455

5556
Assert.That(dict["foo"], Is.EqualTo(123));
5657
Assert.That(dict["bar"], Is.EqualTo(456));
@@ -60,14 +61,9 @@ public void ToDictionaryWithCouples()
6061
[Test]
6162
public void ToDictionaryWithKeyValuePairsWithComparer()
6263
{
63-
var pairs = new[]
64-
{
65-
KeyValuePair.Create("foo", 123),
66-
KeyValuePair.Create("bar", 456),
67-
KeyValuePair.Create("baz", 789),
68-
};
64+
using var source = Pairs();
6965

70-
var dict = MoreEnumerable.ToDictionary(pairs, StringComparer.OrdinalIgnoreCase);
66+
var dict = MoreEnumerable.ToDictionary(source, StringComparer.OrdinalIgnoreCase);
7167

7268
Assert.That(dict["FOO"], Is.EqualTo(123));
7369
Assert.That(dict["BAR"], Is.EqualTo(456));
@@ -77,14 +73,9 @@ public void ToDictionaryWithKeyValuePairsWithComparer()
7773
[Test]
7874
public void ToDictionaryWithCouplesWithComparer()
7975
{
80-
var pairs = new[]
81-
{
82-
("foo", 123),
83-
("bar", 456),
84-
("baz", 789),
85-
};
76+
using var source = Couples();
8677

87-
var dict = MoreEnumerable.ToDictionary(pairs, StringComparer.OrdinalIgnoreCase);
78+
var dict = MoreEnumerable.ToDictionary(source, StringComparer.OrdinalIgnoreCase);
8879

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

0 commit comments

Comments
 (0)