Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 1f17b78

Browse files
committed
Merge pull request #2874 from akoeplinger/linq-tests
System.Linq: Initial port of legacy tests
2 parents 7cbc755 + e72bbba commit 1f17b78

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+28485
-0
lines changed

src/System.Linq/tests/LegacyTests/AggregateTests.cs

Lines changed: 467 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using Xunit;
7+
8+
namespace System.Linq.Tests.LegacyTests
9+
{
10+
public class AllTests
11+
{
12+
public class All007
13+
{
14+
private static int All001()
15+
{
16+
var q = from x in new[] { 9999, 0, 888, -1, 66, -777, 1, 2, -12345 }
17+
where x > Int32.MinValue
18+
select x;
19+
20+
Func<int, bool> predicate = Functions.IsEven;
21+
var rst1 = q.All(predicate);
22+
var rst2 = q.All(predicate);
23+
24+
return ((rst1 == rst2) ? 0 : 1);
25+
}
26+
27+
private static int All002()
28+
{
29+
var q = from x in new[] { "!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", String.Empty }
30+
select x;
31+
32+
Func<string, bool> predicate = Functions.IsEmpty;
33+
var rst1 = q.All(predicate);
34+
var rst2 = q.All(predicate);
35+
36+
return ((rst1 == rst2) ? 0 : 1);
37+
}
38+
39+
public static int Main()
40+
{
41+
int ret = RunTest(All001) + RunTest(All002);
42+
if (0 != ret)
43+
Console.Write(s_errorMessage);
44+
45+
return ret;
46+
}
47+
48+
private static string s_errorMessage = String.Empty;
49+
private delegate int D();
50+
51+
private static int RunTest(D m)
52+
{
53+
int n = m();
54+
if (0 != n)
55+
s_errorMessage += m.ToString() + " - FAILED!\r\n";
56+
return n;
57+
}
58+
[Fact]
59+
public void Test()
60+
{
61+
Assert.Equal(0, Main());
62+
}
63+
}
64+
65+
public class All01
66+
{
67+
// source is empty
68+
public static int Test1()
69+
{
70+
int[] source = { };
71+
Func<int, bool> predicate = Functions.IsEven;
72+
bool expected = true;
73+
74+
var actual = source.All(predicate);
75+
76+
return ((expected == actual) ? 0 : 1);
77+
}
78+
79+
public static int Main()
80+
{
81+
return Test1();
82+
}
83+
84+
[Fact]
85+
public void Test()
86+
{
87+
Assert.Equal(0, Main());
88+
}
89+
}
90+
91+
public class All02
92+
{
93+
// source has one element and predicate is false
94+
public static int Test2()
95+
{
96+
int[] source = { 3 };
97+
Func<int, bool> predicate = Functions.IsEven;
98+
bool expected = false;
99+
100+
var actual = source.All(predicate);
101+
102+
return ((expected == actual) ? 0 : 1);
103+
}
104+
105+
public static int Main()
106+
{
107+
return Test2();
108+
}
109+
110+
[Fact]
111+
public void Test()
112+
{
113+
Assert.Equal(0, Main());
114+
}
115+
}
116+
117+
public class All03
118+
{
119+
// source has one element and predicate is true
120+
public static int Test3()
121+
{
122+
int[] source = { 4 };
123+
Func<int, bool> predicate = Functions.IsEven;
124+
bool expected = true;
125+
126+
var actual = source.All(predicate);
127+
128+
return ((expected == actual) ? 0 : 1);
129+
}
130+
131+
public static int Main()
132+
{
133+
return Test3();
134+
}
135+
136+
[Fact]
137+
public void Test()
138+
{
139+
Assert.Equal(0, Main());
140+
}
141+
}
142+
143+
public class All04
144+
{
145+
// predicate is true for all except 3rd and 4th elements
146+
public static int Test4()
147+
{
148+
int[] source = { 4, 8, 3, 5, 10, 20, 12 };
149+
Func<int, bool> predicate = Functions.IsEven;
150+
bool expected = false;
151+
152+
var actual = source.All(predicate);
153+
154+
return ((expected == actual) ? 0 : 1);
155+
}
156+
157+
public static int Main()
158+
{
159+
return Test4();
160+
}
161+
162+
[Fact]
163+
public void Test()
164+
{
165+
Assert.Equal(0, Main());
166+
}
167+
}
168+
169+
public class All05
170+
{
171+
// predicate is true for all except the last element
172+
public static int Test5()
173+
{
174+
int[] source = { 4, 2, 10, 12, 8, 6, 3 };
175+
Func<int, bool> predicate = Functions.IsEven;
176+
bool expected = false;
177+
178+
var actual = source.All(predicate);
179+
180+
return ((expected == actual) ? 0 : 1);
181+
}
182+
183+
public static int Main()
184+
{
185+
return Test5();
186+
}
187+
188+
[Fact]
189+
public void Test()
190+
{
191+
Assert.Equal(0, Main());
192+
}
193+
}
194+
195+
public class All06
196+
{
197+
// predicate is true for all elements
198+
public static int Test6()
199+
{
200+
int[] source = { 4, 2, 10, 12, 8, 6, 14 };
201+
Func<int, bool> predicate = Functions.IsEven;
202+
bool expected = true;
203+
204+
var actual = source.All(predicate);
205+
206+
return ((expected == actual) ? 0 : 1);
207+
}
208+
209+
public static int Main()
210+
{
211+
return Test6();
212+
}
213+
214+
[Fact]
215+
public void Test()
216+
{
217+
Assert.Equal(0, Main());
218+
}
219+
}
220+
}
221+
}

0 commit comments

Comments
 (0)