2 // BitVector32Test.cs - NUnit Test Cases for System.Net.BitVector32
5 // Lawrence Pit (loz@cable.a2000.nl)
6 // Martin Willemoes Hansen (mwh@sysrq.dk)
8 // (C) 2003 Martin Willemoes Hansen
11 using NUnit
.Framework
;
13 using System
.Collections
;
14 using System
.Collections
.Specialized
;
16 namespace MonoTests
.System
.Collections
.Specialized
19 public class BitVector32Test
22 public void Constructors ()
24 BitVector32 b
= new BitVector32 (31);
28 public void Indexers ()
30 BitVector32 b
= new BitVector32 (7);
31 Assertion
.Assert ("#1", b
[0]);
32 Assertion
.Assert ("#2", b
[1]);
33 Assertion
.Assert ("#3", b
[2]);
34 Assertion
.Assert ("#4", b
[4]);
35 Assertion
.Assert ("#5", !b
[8]);
36 Assertion
.Assert ("#6", !b
[16]);
38 Assertion
.Assert ("#7", b
[4]);
39 Assertion
.Assert ("#8", b
[8]);
40 Assertion
.Assert ("#9", !b
[16]);
42 Assertion
.Assert ("#10", b
[4]);
43 Assertion
.Assert ("#11", !b
[8]);
44 Assertion
.Assert ("#12", !b
[16]);
46 BitVector32
.Section s
= BitVector32
.CreateSection (31);
47 s
= BitVector32
.CreateSection (64, s
);
50 // b = new BitVector32 (0x777777);
51 BitVector32 b1
= new BitVector32 (0xffff77);
52 BitVector32 b2
= new BitVector32 (b1
[s
]);
53 //Console.WriteLine (b1.ToString ());
54 //Console.WriteLine (b2.ToString ());
55 Assertion
.AssertEquals ("#14", 123, b1
[s
]);
58 //Console.WriteLine (b1.ToString ());
62 public void CreateMask ()
64 Assertion
.AssertEquals ("#1", 1, BitVector32
.CreateMask ());
65 Assertion
.AssertEquals ("#2", 1, BitVector32
.CreateMask (0));
66 Assertion
.AssertEquals ("#3", 2, BitVector32
.CreateMask (1));
67 Assertion
.AssertEquals ("#4", 32, BitVector32
.CreateMask (16));
68 Assertion
.AssertEquals ("#6", -2, BitVector32
.CreateMask (Int32
.MaxValue
));
69 Assertion
.AssertEquals ("#5", -4, BitVector32
.CreateMask (-2));
71 BitVector32
.CreateMask (Int32
.MinValue
);
72 Assertion
.Fail ("#7");
73 } catch (InvalidOperationException
) {}
77 public void CreateSection ()
79 BitVector32
.Section s
= BitVector32
.CreateSection (1);
80 Assertion
.AssertEquals ("#1", (short) 1, s
.Mask
);
82 s
= BitVector32
.CreateSection (2);
83 Assertion
.AssertEquals ("#2", (short) 3, s
.Mask
);
85 s
= BitVector32
.CreateSection (3);
86 Assertion
.AssertEquals ("#3", (short) 3, s
.Mask
);
88 s
= BitVector32
.CreateSection (5);
89 Assertion
.AssertEquals ("#4", (short) 7, s
.Mask
);
91 s
= BitVector32
.CreateSection (20);
92 Assertion
.AssertEquals ("#4", (short) 0x1f, s
.Mask
);
94 s
= BitVector32
.CreateSection (Int16
.MaxValue
);
95 Assertion
.AssertEquals ("#5", (short) 0x7fff, s
.Mask
);
97 s
= BitVector32
.CreateSection (Int16
.MaxValue
- 100);
98 Assertion
.AssertEquals ("#6", (short) 0x7fff, s
.Mask
);
101 BitVector32
.Section s2
= BitVector32
.CreateSection (0);
102 Assertion
.Fail ("#7");
103 } catch (ArgumentException
) {}
106 BitVector32
.Section s2
= BitVector32
.CreateSection (-1);
107 Assertion
.Fail ("#8");
108 } catch (ArgumentException
) {}
111 BitVector32
.Section s2
= BitVector32
.CreateSection (Int16
.MinValue
);
112 Assertion
.Fail ("#9");
113 } catch (ArgumentException
) {}
115 s
= BitVector32
.CreateSection (20);
116 Assertion
.AssertEquals ("#10a", (short) 0x1f, s
.Mask
);
117 Assertion
.AssertEquals ("#10b", (short) 0x00, s
.Offset
);
118 s
= BitVector32
.CreateSection (120, s
);
119 Assertion
.AssertEquals ("#10c", (short) 0x7f, s
.Mask
);
120 Assertion
.AssertEquals ("#10d", (short) 0x05, s
.Offset
);
121 s
= BitVector32
.CreateSection (1000, s
);
122 Assertion
.AssertEquals ("#10e", (short) 0x3ff, s
.Mask
);
123 Assertion
.AssertEquals ("#10f", (short) 0x0c, s
.Offset
);
127 public void TestNegativeIndexer ()
129 BitVector32 bv
= new BitVector32 (-1);
130 Assertion
.AssertEquals ("#11a", false, bv
[Int32
.MinValue
]);
134 public void TestSectionIndexer ()
136 BitVector32 bv
= new BitVector32 (-1);
137 BitVector32
.Section sect
= BitVector32
.CreateSection (1);
138 sect
= BitVector32
.CreateSection (Int16
.MaxValue
, sect
);
139 sect
= BitVector32
.CreateSection (Int16
.MaxValue
, sect
);
140 sect
= BitVector32
.CreateSection (1, sect
);
143 Assertion
.AssertEquals ("#12a", Int32
.MaxValue
, bv
.Data
);
146 [Test
, ExpectedException (typeof (ArgumentException
))]
147 public void TestCreateSection1 ()
149 BitVector32
.Section section
= BitVector32
.CreateSection (Int16
.MaxValue
);
150 section
= BitVector32
.CreateSection (0, section
);
153 [Test
, ExpectedException (typeof (ArgumentException
))]
154 public void TestCreateSection2 ()
156 BitVector32
.Section section
= BitVector32
.CreateSection (Int16
.MaxValue
);
157 section
= BitVector32
.CreateSection (-1, section
);
160 [Test
, ExpectedException (typeof (ArgumentException
))]
161 public void TestCreateSection3 ()
163 BitVector32
.Section section
= BitVector32
.CreateSection (Int16
.MaxValue
);
164 section
= BitVector32
.CreateSection (Int16
.MinValue
, section
);
167 private void Print (BitVector32
.Section s
)
169 Console
.WriteLine (s
.ToString () + " : "+ s
.Mask
+ " : " + s
.Offset
);