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

BitVector32Test.cs « System.Collections.Specialized « Test « System « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 883deed976f17a84de7e630404b5d0d3a0aa30f8 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
// BitVector32Test.cs - NUnit Test Cases for System.Net.BitVector32
//
// Author:
//   Lawrence Pit (loz@cable.a2000.nl)
//

using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Specialized;

namespace MonoTests.System.Collections.Specialized
{
	public class BitVector32Test : TestCase
	{
		public BitVector32Test () :
			base ("[MonoTests.System.Net.BitVector32Test]") {}

		public BitVector32Test (string name) : base (name) {}

		protected override void SetUp () {}

		protected override void TearDown () {}

		public static ITest Suite
		{
			get {
				return new TestSuite (typeof (BitVector32Test));
			}
		}
		
		public void TestConstructors ()
		{
			BitVector32 b = new BitVector32 (31);
		}
		
		public void TestIndexers ()
		{
			BitVector32 b = new BitVector32 (7);
			Assert ("#1", b [0]);
			Assert ("#2", b [1]);
			Assert ("#3", b [2]);
			Assert ("#4", b [4]);
			Assert ("#5", !b [8]);
			Assert ("#6", !b [16]);
			b [8] = true;
			Assert ("#7", b [4]);
			Assert ("#8", b [8]);
			Assert ("#9", !b [16]);
			b [8] = false;
			Assert ("#10", b [4]);
			Assert ("#11", !b [8]);
			Assert ("#12", !b [16]);

			BitVector32.Section s = BitVector32.CreateSection (31);
			s = BitVector32.CreateSection (64, s);
			// Print (s);
			
			// b = new BitVector32 (0x777777);
			BitVector32 b1 = new BitVector32 (0xffff77);
			BitVector32 b2 = new BitVector32 (b1 [s]);
			//Console.WriteLine (b1.ToString ());
			//Console.WriteLine (b2.ToString ());
			AssertEquals ("#14", 123, b1 [s]);
			
			// b1 [s] = 15;
			//Console.WriteLine (b1.ToString ());
		}

		public void TestCreateMask ()
		{
			AssertEquals ("#1", 1, BitVector32.CreateMask ());
			AssertEquals ("#2", 1, BitVector32.CreateMask (0));
			AssertEquals ("#3", 2, BitVector32.CreateMask (1));
			AssertEquals ("#4", 32, BitVector32.CreateMask (16));
			AssertEquals ("#6", -2, BitVector32.CreateMask (Int32.MaxValue));
			AssertEquals ("#5", -4, BitVector32.CreateMask (-2));
			try {
				BitVector32.CreateMask (Int32.MinValue);
				Fail ("#7");
			} catch (InvalidOperationException) {}			
		}
		
		public void TestCreateSection ()
		{
			BitVector32.Section s = BitVector32.CreateSection (1);
			AssertEquals ("#1", (short) 1, s.Mask);

			s = BitVector32.CreateSection (2);
			AssertEquals ("#2", (short) 3, s.Mask);

			s = BitVector32.CreateSection (3);
			AssertEquals ("#3", (short) 3, s.Mask);

			s = BitVector32.CreateSection (5);
			AssertEquals ("#4", (short) 7, s.Mask);
			
			s = BitVector32.CreateSection (20);
			AssertEquals ("#4", (short) 0x1f, s.Mask);

			s = BitVector32.CreateSection (Int16.MaxValue);
			AssertEquals ("#5", (short) 0x7fff, s.Mask);

			s = BitVector32.CreateSection (Int16.MaxValue - 100);
			AssertEquals ("#6", (short) 0x7fff, s.Mask);

			try {
				BitVector32.Section s2 = BitVector32.CreateSection (0);
				Fail ("#7");
			} catch (ArgumentException) {}

			try {
				BitVector32.Section s2 = BitVector32.CreateSection (-1);
				Fail ("#8");
			} catch (ArgumentException) {}

			try {
				BitVector32.Section s2 = BitVector32.CreateSection (Int16.MinValue);
				Fail ("#9");
			} catch (ArgumentException) {}
			
			s = BitVector32.CreateSection (20);
			AssertEquals ("#10a", (short) 0x1f, s.Mask);
			AssertEquals ("#10b", (short) 0x00, s.Offset);			
			s = BitVector32.CreateSection (120, s);
			AssertEquals ("#10c", (short) 0x7f, s.Mask);
			AssertEquals ("#10d", (short) 0x05, s.Offset);					
			s = BitVector32.CreateSection (1000, s);
			AssertEquals ("#10e", (short) 0x3ff, s.Mask);
			AssertEquals ("#10f", (short) 0x0c, s.Offset);			
		}


		private void Print (BitVector32.Section s)
		{
			Console.WriteLine (s.ToString () + " : "+ s.Mask + " : " + s.Offset);
		}
	}        
}