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

test-43.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7d8deffe81213ec53c063e3c70fa6812d975b65e (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
//
// This test is used for testing the foreach array support
//
using System;

class X {

	static int test_single (int [] a)
	{
		int total = 0;

		foreach (int i in a)
			total += i;

		return total;
	}

	static int test_continue (int [] a)
	{
		int total = 0;
		int j = 0;
		
		foreach (int i in a){
			j++;
			if (j == 5)
				continue;
			total += i;
		}

		return total;
	}

	static int test_break (int [] a)
	{
		int total = 0;
		int j = 0;

		foreach (int i in a){
			j++;
			if (j == 5)
				break;
			total += i;
		}

		return total;
	}
	
	static int Main ()
	{
		int [] a = new int [10];
		int [] b = new int [2];

		for (int i = 0; i < 10; i++)
			a [i] = 10 + i;

		for (int j = 0; j < 2; j++)
			b [j] = 50 + j;

		if (test_single (a) != 145)
			return 1;

		if (test_single (b) != 101)
			return 2;

		if (test_continue (a) != 131){
			Console.WriteLine ("Expecting: 131, got " + test_continue (a));
			return 3;
		}

		if (test_break (a) != 46){
			Console.WriteLine ("Expecting: 46, got " + test_break (a));
			return 4;
		}
		
		return 0;
	}
}