File: gtest-linq-09.cs

package info (click to toggle)
mono 4.6.2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (80 lines) | stat: -rw-r--r-- 1,479 bytes parent folder | download | duplicates (10)
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


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

class Data
{
	public int Key;
	public string Value;
}

class Join
{
	public static int Main ()
	{
		Data[] d1 = new Data[] { new Data () { Key = 1, Value = "First" } };
		Data[] d2 = new Data[] { 
			new Data () { Key = 1, Value = "Second" },
			new Data () { Key = 1, Value = "Third" }
		};

		
		var e = from a in d1
			join b in d2 on a.Key equals b.Key
			select new { Result = a.Value + b.Value };

		var res = e.ToList ();
		if (res.Count != 2)
			return 1;
		
		if (res [0].Result != "FirstSecond")
			return 2;
			
		if (res [1].Result != "FirstThird")
			return 3;
			
		e = from Data a in d1
			join b in d2 on a.Key equals b.Key
			where b.Value == "Second"
			select new { Result = a.Value + b.Value };
			
		res = e.ToList ();
		if (res.Count != 1)
			return 4;
		
		if (res [0].Result != "FirstSecond")
			return 5;		
			
		// Explicitly typed
		e = from Data a in d1
            join Data b in d2 on a.Key equals b.Key
            select new { Result = a.Value + b.Value };
		
		res = e.ToList ();
		if (res.Count != 2)
			return 10;
		
		if (res [0].Result != "FirstSecond")
			return 11;
			
		if (res [1].Result != "FirstThird")
			return 12;
		
		var e2 = from Data a in d1
			join b in d2 on a.Key equals b.Key
			group b by a.Key;

		var res2 = e2.ToList ();
		if (res2.Count != 1)
			return 20;
		
		if (res2 [0].Key != 1)
			return 21;
			
		Console.WriteLine ("OK");
		return 0;
	}
}