2010-04-03 Jb Evain <jbevain@novell.com>
[mcs.git] / tests / gtest-linq-04.cs
blob3c214fdaf9959ced4c2ed20ed683b969dc178890
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
7 class TestGroupBy
9 public static int Main ()
11 int[] int_array = new int [] { 0, 1, 2, 3, 4 };
13 IEnumerable<IGrouping<int, int>> e;
15 // group by i % 2 from 1
16 e = from int i in int_array group 1 by i % 2;
18 List<IGrouping<int, int>> output = e.ToList ();
19 if (output.Count != 2)
20 return 1;
22 foreach (IGrouping<int, int> ig in e) {
23 Console.WriteLine (ig.Key);
24 foreach (int value in ig) {
25 Console.WriteLine ("\t" + value);
26 if (value != 1)
27 return 2;
31 // group by i % 2 from i
32 e = from int i in int_array group i by i % 2;
34 output = e.ToList ();
35 if (output.Count != 2)
36 return 1;
38 int[] results_a = new int[] { 0, 2, 4, 1, 3 };
39 int pos = 0;
41 foreach (IGrouping<int, int> ig in e) {
42 Console.WriteLine (ig.Key);
43 foreach (int value in ig) {
44 Console.WriteLine ("\t" + value);
45 if (value != results_a [pos++])
46 return 3;
50 Console.WriteLine ("OK");
51 return 0;