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

gtest-collectioninit-01.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a39aa33b1fb2e81455d6937482814db87d037bd0 (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
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
81
82
83
84
85
86
87
88
89
90
91
92

// Tests collection initialization

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

public class Test
{
	class Wrap
	{
		ArrayList numbers = new ArrayList ();
		public int Id;
		public Wrap Next;
		
		public Wrap ()
		{
			Next = new Wrap (100);
		}
		
		public Wrap (int i)
		{
			Next = this;
		}
		
		public ArrayList Numbers { 
			get { 
				return numbers;
			}
		}
	}
	
	static void TestList (List<int> list, int expectedCount)
	{
		if (list.Count != expectedCount)
			throw new ApplicationException (expectedCount.ToString ());
		
		foreach (int i in list)
			Console.WriteLine (i);
	}
	
	public static int Main ()
	{
		ArrayList collection = new ArrayList { "Foo", null, 1 };
		if (collection.Count != 3)
			return 1;
			
		if ((string)collection [0] != "Foo")
			return 2;
			
		if ((int)collection [2] != 1)
			return 3;
					
		List<string> generic_collection = new List<string> { "Hello", "World" };
		foreach (string s in generic_collection)
			if (s.Length != 5)
				return 4;
		
		List<Wrap> a = null;
		a = new List<Wrap> () {		
			new Wrap (0) {
				Id = 0,
				Numbers = { 5, 10 },
				Next = { Id = 55 }
			},
			new Wrap {
				Id = 1,
				Numbers = { collection, }
			},
			new Wrap {
				Id = 2,
				Numbers = { },
			},
			null
		};
		
		if (a.Count != 4)
			return 5;
		
		if ((int)a [0].Numbers [1] != 10)
			return 6;
		
		new List<int> { 1, 2, 3, 4 };
		TestList (new List<int> { 1, 2, 3, 4 }, 4);
		
		new List<int> { };
		
		Console.WriteLine ("OK");
		return 0;
	}
}