[corlib] Make Marshal.BufferToBSTR(Array, int) non-public again (#5670)
[mono.git] / mcs / tests / gtest-linq-05.cs
1
2
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6
7 class OrderByTests
8 {
9         class Data
10         {
11                 public int ID { get; set; }
12                 public string Name { get; set; }
13                 
14                 public override string ToString ()
15                 {
16                         return ID + " " + Name;
17                 }
18         }
19         
20         public static int Main ()
21         {
22                 int[] int_array = new int [] { 0, 1 };
23                 string[] string_array = new string[] { "f", "a", "z", "aa" };
24                 
25                 IEnumerable<int> e;
26                 
27                 e = from int i in int_array orderby i select i;
28                 
29                 List<int> l = new List<int> (e);
30                 if (l [0] != 0)
31                         return 1;
32                         
33                 if (l [1] != 1)
34                         return 2;
35
36                 e = from int i in int_array orderby i ascending select i;
37                 
38                 l = new List<int> (e);
39                 if (l [0] != 0)
40                         return 100;
41                         
42                 if (l [1] != 1)
43                         return 101;
44                 
45                 e = from i in int_array orderby i descending select i + 1;
46                 l = new List<int> (e);
47                 if (l [0] != 2)
48                         return 3;
49                         
50                 if (l [1] != 1)
51                         return 4;
52
53                 IEnumerable<string> s;
54                 s = from i in string_array orderby i select i;
55                 
56                 List<string> ls = new List<string> (s);
57                 
58                 if (ls [0] != "a")
59                         return 5;
60                         
61                 if (ls [1] != "aa")
62                         return 6;
63                                 
64                 if (ls [2] != "f")
65                         return 7;
66                 
67                 if (ls [3] != "z")
68                         return 7;               
69                 
70                 s = from i in string_array orderby i.Length select i;
71                 
72                 // Multiple orderby
73                 Data[] data = new Data[] {
74                         new Data { ID = 10, Name = "bcd" },
75                         new Data { ID = 20, Name = "Abcd" },
76                         new Data { ID = 20, Name = "Ab" },
77                         new Data { ID = 10, Name = "Zyx" }
78                 };
79                 
80                 var de = from i in data orderby i.ID ascending, i.Name descending select i;
81                 
82                 List<Data> ld = new List<Data> (de);
83                 if (ld [0].Name != "Zyx")
84                         return 10;
85                 
86                 var de2 = from i in data orderby i.ID descending, i.Name ascending select i;
87                 ld = new List<Data> (de2);
88                 if (ld [0].Name != "Ab")
89                         return 11;
90                 
91                 var de3 = from i in data  
92                         where i.ID == 10
93                         orderby i.ID descending, i.Name ascending select i;
94                 ld = new List<Data> (de3);
95                 if (ld [0].Name != "bcd")
96                         return 12;
97                 
98                 var de4 = from i in data
99                         where i.ID == 20
100                         orderby i.Name group i by i.Name;
101                 
102                 var group_order = new List<IGrouping<string, Data>> (de4);
103                 ld = new List<Data>(group_order [0]);
104
105                 if (ld [0].Name != "Ab")
106                         return 13;
107                 
108                 ld = new List<Data>(group_order [1]);
109                 if (ld [0].Name != "Abcd")
110                         return 14;              
111                 
112                 Console.WriteLine ("OK");
113                 return 0;
114         }
115 }