-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathStatics-Extensions.cs
130 lines (105 loc) · 5.81 KB
/
Statics-Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
namespace Towel_Testing;
// [TestClass]
public partial class Statics_Testing
{
#region string.Replace (multiple)
[TestMethod]
public void String_Replace()
{
Assert.AreEqual("aaa bbb c ddd e", "a b c d e".Replace(("a", "aaa"), ("b", "bbb"), ("d", "ddd")));
Assert.AreEqual("aaa bbb c d e", "a b c d e".Replace(("a", "aaa"), ("b", "bbb"), ("aaa", "ERROR")));
Assert.ThrowsException<ArgumentNullException>(() => Statics.Replace(null!, ("a", "b")));
Assert.ThrowsException<ArgumentNullException>(() => string.Empty.Replace(null!));
Assert.ThrowsException<ArgumentNullException>(() => string.Empty.Replace((null!, "a")));
Assert.ThrowsException<ArgumentNullException>(() => string.Empty.Replace(("a", null!)));
Assert.ThrowsException<ArgumentException>(() => string.Empty.Replace());
Assert.ThrowsException<ArgumentException>(() => string.Empty.Replace(("a", "b"), ("a", "c")));
Assert.ThrowsException<ArgumentException>(() => string.Empty.Replace((string.Empty, "a")));
}
#endregion
#region System.Range.ToIEnumerable
[TestMethod]
public void ToIEnumerable_Range()
{
Assert.IsTrue(EquateSequence<int>((0..4).ToIEnumerable().ToArray(), new[] { 0, 1, 2, 3 }));
Assert.IsTrue(EquateSequence<int>((4..0).ToIEnumerable().ToArray(), new[] { 4, 3, 2, 1 }));
Assert.IsTrue(EquateSequence<int>((11..14).ToIEnumerable().ToArray(), new[] { 11, 12, 13 }));
Assert.IsTrue(EquateSequence<int>((14..11).ToIEnumerable().ToArray(), new[] { 14, 13, 12 }));
//// unfortuntately System.Range syntax does not support negative values
// Assert.IsTrue(Equate<int>((0..-3).ToIEnumerable().ToArray(), new[] { 0, -1, -2 }));
// Assert.IsTrue(Equate<int>((-3..0).ToIEnumerable().ToArray(), new[] { -3, -2, -1 }));
Assert.ThrowsException<ArgumentException>(() => (^0..4).ToIEnumerable().ToArray());
Assert.ThrowsException<ArgumentException>(() => (0..^4).ToIEnumerable().ToArray());
Assert.ThrowsException<ArgumentException>(() => (^0..^4).ToIEnumerable().ToArray());
}
#endregion
#region System.Range.ToArray
[TestMethod]
public void ToArray_Range()
{
Assert.IsTrue(EquateSequence<int>(( ..0).ToArray(), Ɐ<int>()));
Assert.IsTrue(EquateSequence<int>((0..0).ToArray(), Ɐ<int>()));
Assert.IsTrue(EquateSequence<int>((1..1).ToArray(), Ɐ<int>()));
Assert.IsTrue(EquateSequence<int>((2..2).ToArray(), Ɐ<int>()));
// least to greatest
Assert.IsTrue(EquateSequence<int>(( ..1).ToArray(), Ɐ(0)));
Assert.IsTrue(EquateSequence<int>(( ..2).ToArray(), Ɐ(0, 1)));
Assert.IsTrue(EquateSequence<int>((0..1).ToArray(), Ɐ(0)));
Assert.IsTrue(EquateSequence<int>((0..2).ToArray(), Ɐ(0, 1)));
Assert.IsTrue(EquateSequence<int>((1..2).ToArray(), Ɐ(1)));
Assert.IsTrue(EquateSequence<int>((1..3).ToArray(), Ɐ(1, 2)));
Assert.IsTrue(EquateSequence<int>((1..4).ToArray(), Ɐ(1, 2, 3)));
Assert.IsTrue(EquateSequence<int>((1..5).ToArray(), Ɐ(1, 2, 3, 4)));
Assert.IsTrue(EquateSequence<int>((2..3).ToArray(), Ɐ(2)));
Assert.IsTrue(EquateSequence<int>((2..4).ToArray(), Ɐ(2, 3)));
// greatest to least
Assert.IsTrue(EquateSequence<int>((2..1).ToArray(), Ɐ(2)));
Assert.IsTrue(EquateSequence<int>((3..1).ToArray(), Ɐ(3, 2)));
Assert.IsTrue(EquateSequence<int>((4..1).ToArray(), Ɐ(4, 3, 2)));
Assert.IsTrue(EquateSequence<int>((5..1).ToArray(), Ɐ(5, 4, 3, 2)));
Assert.IsTrue(EquateSequence<int>((3..2).ToArray(), Ɐ(3)));
Assert.IsTrue(EquateSequence<int>((4..2).ToArray(), Ɐ(4, 3)));
Assert.ThrowsException<ArgumentException>(() => (..).ToArray());
Assert.ThrowsException<ArgumentException>(() => (1..).ToArray());
Assert.ThrowsException<ArgumentException>(() => (^1..).ToArray());
Assert.ThrowsException<ArgumentException>(() => (..^1).ToArray());
Assert.ThrowsException<ArgumentException>(() => (^1..^1).ToArray());
}
#endregion
#region System.Range.Select
[TestMethod]
public void Select_Range()
{
Assert.IsTrue(( ..0).Select(x => x).SequenceEqual(Ɐ<int>()));
Assert.IsTrue((0..0).Select(x => x).SequenceEqual(Ɐ<int>()));
Assert.IsTrue((1..1).Select(x => x).SequenceEqual(Ɐ<int>()));
Assert.IsTrue((2..2).Select(x => x).SequenceEqual(Ɐ<int>()));
// least to greatest
Assert.IsTrue(( ..1).Select(x => x).SequenceEqual(Ɐ(0)));
Assert.IsTrue(( ..2).Select(x => x).SequenceEqual(Ɐ(0, 1)));
Assert.IsTrue((0..1).Select(x => x).SequenceEqual(Ɐ(0)));
Assert.IsTrue((0..2).Select(x => x).SequenceEqual(Ɐ(0, 1)));
Assert.IsTrue((1..2).Select(x => x).SequenceEqual(Ɐ(1)));
Assert.IsTrue((1..3).Select(x => x).SequenceEqual(Ɐ(1, 2)));
Assert.IsTrue((1..4).Select(x => x).SequenceEqual(Ɐ(1, 2, 3)));
Assert.IsTrue((1..5).Select(x => x).SequenceEqual(Ɐ(1, 2, 3, 4)));
Assert.IsTrue((2..3).Select(x => x).SequenceEqual(Ɐ(2)));
Assert.IsTrue((2..4).Select(x => x).SequenceEqual(Ɐ(2, 3)));
// greatest to least
Assert.IsTrue((2..1).Select(x => x).SequenceEqual(Ɐ(2)));
Assert.IsTrue((3..1).Select(x => x).SequenceEqual(Ɐ(3, 2)));
Assert.IsTrue((4..1).Select(x => x).SequenceEqual(Ɐ(4, 3, 2)));
Assert.IsTrue((5..1).Select(x => x).SequenceEqual(Ɐ(5, 4, 3, 2)));
Assert.IsTrue((3..2).Select(x => x).SequenceEqual(Ɐ(3)));
Assert.IsTrue((4..2).Select(x => x).SequenceEqual(Ɐ(4, 3)));
// some types other than int
Assert.IsTrue(('a'..'f').Select(x => (char)x).SequenceEqual(Ɐ('a', 'b', 'c', 'd', 'e')));
Assert.IsTrue(('a'..'f').Select(x => ((char)x).ToString()).SequenceEqual(Ɐ("a", "b", "c", "d", "e")));
Assert.ThrowsException<ArgumentException>(() => (..).Select(x => x).ToArray());
Assert.ThrowsException<ArgumentException>(() => (1..).Select(x => x).ToArray());
Assert.ThrowsException<ArgumentException>(() => (^1..).Select(x => x).ToArray());
Assert.ThrowsException<ArgumentException>(() => (..^1).Select(x => x).ToArray());
Assert.ThrowsException<ArgumentException>(() => (^1..^1).Select(x => x).ToArray());
}
#endregion
}