Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gtest-linq-04.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3c214fdaf9959ced4c2ed20ed683b969dc178890 (plain)
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


using System;
using System.Collections.Generic;
using System.Linq;

class TestGroupBy
{
	public static int Main ()
	{
		int[] int_array = new int [] { 0, 1, 2, 3, 4 };
		
		IEnumerable<IGrouping<int, int>> e;
		
		// group by i % 2 from 1
		e = from int i in int_array group 1 by i % 2;

		List<IGrouping<int, int>> output = e.ToList ();
		if (output.Count != 2)
			return 1;
		
		foreach (IGrouping<int, int> ig in e) {
			Console.WriteLine (ig.Key);
			foreach (int value in ig) {
				Console.WriteLine ("\t" + value);
				if (value != 1)
					return 2;
			}
		}

		// group by i % 2 from i
		e = from int i in int_array group i by i % 2;

		output = e.ToList ();
		if (output.Count != 2)
			return 1;
		
		int[] results_a = new int[] { 0, 2, 4, 1, 3 };
		int pos = 0;
		
		foreach (IGrouping<int, int> ig in e) {
			Console.WriteLine (ig.Key);
			foreach (int value in ig) {
				Console.WriteLine ("\t" + value);
				if (value != results_a [pos++])
					return 3;
			}
		}
		
		Console.WriteLine ("OK");
		return 0;
	}
}