public digital_data(int din) { BitVector32 digitalout_b = new BitVector32(din); // Creates masks to isolate each of the first 6 bit flags. int myBit1 = BitVector32.CreateMask(); int myBit2 = BitVector32.CreateMask(myBit1); int myBit3 = BitVector32.CreateMask(myBit2); int myBit4 = BitVector32.CreateMask(myBit3); int myBit5 = BitVector32.CreateMask(myBit4); int myBit6 = BitVector32.CreateMask(myBit5); //digitalout_b = din; dout1 = digitalout_b[myBit1]; dout2 = digitalout_b[myBit2]; dout3 = digitalout_b[myBit3]; din1 = digitalout_b[myBit4]; din2 = digitalout_b[myBit5]; din3 = digitalout_b[myBit6]; }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; BitVector32 bv32; BitVector32 bvExtra; int data = 0; try { data = 0; Console.WriteLine("1. ctor(BitVector32({0}))", data); strLoc = "Loc_001oo"; iCountTestcases++; bvExtra = new BitVector32(data); if (bvExtra.Data != data) { iCountErrors++; Console.WriteLine("Err_0001a, Data = {0} after ctor({1})", bvExtra.Data, data); } iCountTestcases++; bv32 = new BitVector32(bvExtra); if (bv32.Data != bvExtra.Data) { iCountErrors++; Console.WriteLine("Err_0001b, Data: returned: {0} , expected: {1}", bv32.Data, bvExtra.Data); } data = 1; Console.WriteLine("2. ctor(BitVector32({0}))", data); strLoc = "Loc_002oo"; iCountTestcases++; bvExtra = new BitVector32(data); if (bvExtra.Data != data) { iCountErrors++; Console.WriteLine("Err_0002a, Data = {0} after ctor({1})", bvExtra.Data, data); } iCountTestcases++; bv32 = new BitVector32(bvExtra); if (bv32.Data != bvExtra.Data) { iCountErrors++; Console.WriteLine("Err_0002b, Data: returned: {0} , expected: {1}", bv32.Data, bvExtra.Data); } data = -1; Console.WriteLine("3. ctor(BitVector32({0}))", data); strLoc = "Loc_003oo"; iCountTestcases++; bvExtra = new BitVector32(data); if (bvExtra.Data != data) { iCountErrors++; Console.WriteLine("Err_0003a, Data = {0} after ctor({1})", bvExtra.Data, data); } iCountTestcases++; bv32 = new BitVector32(bvExtra); if (bv32.Data != bvExtra.Data) { iCountErrors++; Console.WriteLine("Err_0003b, Data: returned: {0} , expected: {1}", bv32.Data, bvExtra.Data); } data = 2; Console.WriteLine("4. ctor(BitVector32({0}))", data); strLoc = "Loc_004oo"; iCountTestcases++; bvExtra = new BitVector32(data); if (bvExtra.Data != data) { iCountErrors++; Console.WriteLine("Err_0004a, Data = {0} after ctor({1})", bvExtra.Data, data); } iCountTestcases++; bv32 = new BitVector32(bvExtra); if (bv32.Data != bvExtra.Data) { iCountErrors++; Console.WriteLine("Err_0004b, Data: returned: {0} , expected: {1}", bv32.Data, bvExtra.Data); } data = 10; Console.WriteLine("5. ctor(BitVector32({0}))", data); strLoc = "Loc_005oo"; iCountTestcases++; bvExtra = new BitVector32(data); if (bvExtra.Data != data) { iCountErrors++; Console.WriteLine("Err_0005a, Data = {0} after ctor({1})", bvExtra.Data, data); } iCountTestcases++; bv32 = new BitVector32(bvExtra); if (bv32.Data != bvExtra.Data) { iCountErrors++; Console.WriteLine("Err_0005b, Data: returned: {0} , expected: {1}", bv32.Data, bvExtra.Data); } data = 99; Console.WriteLine("6. ctor(BitVector32({0}))", data); strLoc = "Loc_006oo"; iCountTestcases++; bvExtra = new BitVector32(data); if (bvExtra.Data != data) { iCountErrors++; Console.WriteLine("Err_0006a, Data = {0} after ctor({1})", bvExtra.Data, data); } iCountTestcases++; bv32 = new BitVector32(bvExtra); if (bv32.Data != bvExtra.Data) { iCountErrors++; Console.WriteLine("Err_0006b, Data: returned: {0} , expected: {1}", bv32.Data, bvExtra.Data); } data = -9; Console.WriteLine("7. ctor(BitVector32({0}))", data); strLoc = "Loc_007oo"; iCountTestcases++; bvExtra = new BitVector32(data); if (bvExtra.Data != data) { iCountErrors++; Console.WriteLine("Err_0007a, Data = {0} after ctor({1})", bvExtra.Data, data); } iCountTestcases++; bv32 = new BitVector32(bvExtra); if (bv32.Data != bvExtra.Data) { iCountErrors++; Console.WriteLine("Err_0007b, Data: returned: {0} , expected: {1}", bv32.Data, bvExtra.Data); } data = System.Int32.MinValue; Console.WriteLine("8. ctor(BitVector32({0}))", data); strLoc = "Loc_008oo"; iCountTestcases++; bvExtra = new BitVector32(data); if (bvExtra.Data != data) { iCountErrors++; Console.WriteLine("Err_0008a, Data = {0} after ctor({1})", bvExtra.Data, data); } iCountTestcases++; bv32 = new BitVector32(bvExtra); if (bv32.Data != bvExtra.Data) { iCountErrors++; Console.WriteLine("Err_0008b, Data: returned: {0} , expected: {1}", bv32.Data, bvExtra.Data); } data = System.Int32.MaxValue; Console.WriteLine("9. ctor(BitVector32({0}))", data); strLoc = "Loc_009oo"; iCountTestcases++; bvExtra = new BitVector32(data); if (bvExtra.Data != data) { iCountErrors++; Console.WriteLine("Err_0009a, Data = {0} after ctor({1})", bvExtra.Data, data); } iCountTestcases++; bv32 = new BitVector32(bvExtra); if (bv32.Data != bvExtra.Data) { iCountErrors++; Console.WriteLine("Err_0009b, Data: returned: {0} , expected: {1}", bv32.Data, bvExtra.Data); } data = System.Int32.MinValue / 2; Console.WriteLine("10. ctor(BitVector32({0}))", data); strLoc = "Loc_010oo"; iCountTestcases++; bvExtra = new BitVector32(data); if (bvExtra.Data != data) { iCountErrors++; Console.WriteLine("Err_0010a, Data = {0} after ctor({1})", bvExtra.Data, data); } iCountTestcases++; bv32 = new BitVector32(bvExtra); if (bv32.Data != bvExtra.Data) { iCountErrors++; Console.WriteLine("Err_0010b, Data: returned: {0} , expected: {1}", bv32.Data, bvExtra.Data); } data = System.Int32.MaxValue / 2; Console.WriteLine("11. ctor(BitVector32({0}))", data); strLoc = "Loc_011oo"; iCountTestcases++; bvExtra = new BitVector32(data); if (bvExtra.Data != data) { iCountErrors++; Console.WriteLine("Err_0011a, Data = {0} after ctor({1})", bvExtra.Data, data); } iCountTestcases++; bv32 = new BitVector32(bvExtra); if (bv32.Data != bvExtra.Data) { iCountErrors++; Console.WriteLine("Err_0011b, Data: returned: {0} , expected: {1}", bv32.Data, bvExtra.Data); } DateTime time = DateTime.Now; data = time.DayOfYear + time.Hour + time.Minute + time.Second; System.Random random = new System.Random(data); data = random.Next(System.Int32.MinValue, System.Int32.MaxValue); Console.WriteLine("12. ctor(BitVector32(random data: {0}))", data); strLoc = "Loc_012oo"; iCountTestcases++; bvExtra = new BitVector32(data); if (bvExtra.Data != data) { iCountErrors++; Console.WriteLine("Err_0012a, Data = {0} after ctor({1})", bvExtra.Data, data); } iCountTestcases++; bv32 = new BitVector32(bvExtra); if (bv32.Data != bvExtra.Data) { iCountErrors++; Console.WriteLine("Err_0012b, Data: returned: {0} , expected: {1}", bv32.Data, bvExtra.Data); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public BitVector32(BitVector32 value);
public RelationKind(RelationKind other) { this.kind = new BitVector32(); kind[partner] = other.Pair.Code; kind[aspectType] = (int)other.Pattern; }
public static void EqualsTest() { BitVector32 original = new BitVector32(); Assert.True(original.Equals(original)); Assert.True(new BitVector32().Equals(original)); Assert.True(original.Equals(new BitVector32())); Assert.True(new BitVector32(0).Equals(original)); Assert.True(original.Equals(new BitVector32(0))); BitVector32 other = new BitVector32(int.MaxValue / 2 - 1); Assert.True(other.Equals(other)); Assert.True(new BitVector32(int.MaxValue / 2 - 1).Equals(other)); Assert.True(other.Equals(new BitVector32(int.MaxValue / 2 - 1))); Assert.False(other.Equals(original)); Assert.False(original.Equals(other)); Assert.False(other.Equals(null)); Assert.False(original.Equals(null)); Assert.False(other.Equals(int.MaxValue / 2 - 1)); Assert.False(original.Equals(0)); }
public static void Set_Section_OutOfRangeTest(short maximum, int value) { { BitVector32 data = new BitVector32(); BitVector32.Section section = BitVector32.CreateSection(maximum); // In debug mode, attempting to set a value to a section that is too large triggers an assert. // There is no accompanying check in release mode, however, allowing invalid values to be set. #if DEBUG Exception e = Assert.ThrowsAny<Exception>(() => data[section] = value); Assert.Equal("DebugAssertException", e.GetType().Name); #else data[section] = value; Assert.Equal(maximum & value, data.Data); Assert.NotEqual(value, data.Data); Assert.Equal(maximum & value, data[section]); Assert.NotEqual(value, data[section]); #endif } { BitVector32 data = new BitVector32(); BitVector32.Section nested = BitVector32.CreateSection(maximum, BitVector32.CreateSection(short.MaxValue)); #if DEBUG Exception e = Assert.ThrowsAny<Exception>(() => data[nested] = value); Assert.Equal("DebugAssertException", e.GetType().Name); #else data[nested] = value; Assert.Equal((maximum & value) << 15, data.Data); Assert.NotEqual(value << 15, data.Data); Assert.Equal(maximum & value, data[nested]); Assert.NotEqual(value, data[nested]); #endif } }
public static void Set_Mask_EmptyTest() { BitVector32 nothing = new BitVector32(); nothing[0] = true; Assert.Equal(0, nothing.Data); BitVector32 all = new BitVector32(-1); all[0] = false; Assert.Equal(-1, all.Data); }
public static void Constructor_DataTest(int data) { BitVector32 bv = new BitVector32(data); Assert.NotNull(bv); Assert.Equal(data, bv.Data); // Copy constructor results in item with same data. BitVector32 copied = new BitVector32(bv); Assert.NotNull(bv); Assert.Equal(data, copied.Data); }
public static void EscribirBitsDeInteger(int valor) { BitVector32 bv32 = new BitVector32(valor); System.Console.WriteLine(bv32.ToString()); }
// Constructor public HasEnum32Container() { // constructor receives initial value of vector this._info = new BitVector32(0); }
public HasEnum32Enumerator(BitVector32 container) { this._container = container; this._size = Enum.GetValues(typeof(TEnum)).Length; this._current = -1; }
/// <summary> /// Initializes a new instance of the <see cref="Layer"/> class using the provided reader containing the PSD file data. /// </summary> /// <param name="reader">The reader containing the PSD file data.</param> /// <param name="psdFile">The PSD file to set as the parent.</param> public Layer(BinaryReverseReader reader, PsdFile psdFile) { Children = new List <Layer>(); PsdFile = psdFile; // read the rect Rect rect = new Rect(); rect.y = reader.ReadInt32(); rect.x = reader.ReadInt32(); rect.height = reader.ReadInt32() - rect.y; rect.width = reader.ReadInt32() - rect.x; Rect = rect; // read the channels int channelCount = reader.ReadUInt16(); Channels = new List <Channel>(); SortedChannels = new SortedList <short, Channel>(); for (int index = 0; index < channelCount; ++index) { Channel channel = new Channel(reader, this); Channels.Add(channel); SortedChannels.Add(channel.ID, channel); } // read the header and verify it if (new string(reader.ReadChars(4)) != "8BIM") { throw new IOException("Layer Channelheader error!"); } // read the blend mode key (unused) (defaults to "norm") reader.ReadChars(4); // read the opacity Opacity = reader.ReadByte(); // read the clipping (unused) (< 0 = base, > 0 = non base) reader.ReadByte(); // read all of the flags (protectTrans, visible, obsolete, ver5orLater, pixelDataIrrelevant) flags = new BitVector32(reader.ReadByte()); // skip a padding byte reader.ReadByte(); uint num3 = reader.ReadUInt32(); long position1 = reader.BaseStream.Position; MaskData = new Mask(reader, this); BlendingRangesData = new BlendingRanges(reader); long position2 = reader.BaseStream.Position; // read the name Name = reader.ReadPascalString().Trim(); // read the adjustment info int count = (int)((reader.BaseStream.Position - position2) % 4L); reader.ReadBytes(count); AdjustmentInfo = new List <AdjustmentLayerInfo>(); long num4 = position1 + num3; while (reader.BaseStream.Position < num4) { try { AdjustmentInfo.Add(new AdjustmentLayerInfo(reader, this)); } catch { reader.BaseStream.Position = num4; } } foreach (AdjustmentLayerInfo adjustmentLayerInfo in AdjustmentInfo) { if (adjustmentLayerInfo.Key == "TySh") { ReadTextLayer(adjustmentLayerInfo.DataReader); } else if (adjustmentLayerInfo.Key == "luni") { // read the unicode name BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader; dataReader.ReadBytes(3); dataReader.ReadByte(); Name = dataReader.ReadString().TrimEnd(new char[1]); } } reader.BaseStream.Position = num4; }
/// <summary> /// Overloaded constructor taking another ExecutionEngineCondition object as a reference /// </summary> public ExecutionEngineConditions(ExecutionEngineConditions condition) { state = condition.state; batchSeparator = condition.batchSeparator; }
public RelationKind(PlanetId pA, PlanetId pB, AspectType theType) { this.kind = new BitVector32(0); kind[partner] = PlanetPair.CodeOf(pA, pB); kind[aspectType] = (int)theType; }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; BitVector32.Section section; Int16 maxValue = 0; BitVector32 bv32; int expected = 0; try { maxValue = Int16.MinValue; Console.WriteLine("1. CreateSection({0}) ~ Int16.MinValue", maxValue); strLoc = "Loc_001oo"; iCountTestcases++; try { section = BitVector32.CreateSection(maxValue); iCountErrors++; Console.WriteLine(" Err_0001a, no exception for CreateSection({0})", maxValue); } catch (ArgumentException e) { Console.WriteLine(" Expected exception for CreateSection({0}):{1}", maxValue, e.Message); } catch (Exception ex) { iCountErrors++; Console.WriteLine(" Err_0001b, unexpected exception for CreateSection({0}): {1}", maxValue, ex.ToString()); } maxValue = -1; Console.WriteLine("2. CreateSection({0})", maxValue); strLoc = "Loc_002oo"; iCountTestcases++; try { section = BitVector32.CreateSection(maxValue); iCountErrors++; Console.WriteLine(" Err_0002a, no exception for CreateSection({0})", maxValue); } catch (ArgumentException e) { Console.WriteLine(" Expected exception for CreateSection({0}):{1}", maxValue, e.Message); } catch (Exception ex) { iCountErrors++; Console.WriteLine(" Err_0002b, unexpected exception for CreateSection({0}): {1}", maxValue, ex.ToString()); } maxValue = 0; Console.WriteLine("3. CreateSection({0})", maxValue); strLoc = "Loc_003oo"; iCountTestcases++; try { section = BitVector32.CreateSection(maxValue); iCountErrors++; Console.WriteLine(" Err_0003a, no exception for CreateSection({0})", maxValue); } catch (ArgumentException e) { Console.WriteLine(" Expected exception for CreateSection({0}):{1}", maxValue, e.Message); } catch (Exception ex) { iCountErrors++; Console.WriteLine(" Err_0003b, unexpected exception for CreateSection({0}): {1}", maxValue, ex.ToString()); } maxValue = 1; Console.WriteLine("4. CreateSection({0})", maxValue); strLoc = "Loc_004oo"; iCountTestcases++; section = BitVector32.CreateSection(maxValue); Console.WriteLine(" CreateSection(1): ({0}, {1})", section.Mask, section.Offset); if (section.Mask != maxValue || section.Offset != 0) { iCountErrors++; Console.WriteLine(" Err_0004, CreateSection({0}) returned ({1}, {2})", maxValue, section.Mask, section.Offset); } maxValue = Int16.MaxValue; Console.WriteLine("5. CreateSection({0}) ~ Int16.MaxValue", maxValue); strLoc = "Loc_005oo"; iCountTestcases++; section = BitVector32.CreateSection(maxValue); Console.WriteLine(" CreateSection(Int16.MaxValue): ({0}, {1})", section.Mask, section.Offset); if (section.Mask != maxValue || section.Offset != 0) { iCountErrors++; Console.WriteLine(" Err_0005, CreateSection({0}) returned ({1}, {2})", maxValue, section.Mask, section.Offset); } DateTime time = DateTime.Now; int max = time.DayOfYear + time.Hour + time.Minute + time.Second; System.Random random = new System.Random(max); max = random.Next(1, System.Int16.MaxValue); maxValue = (Int16)max; Console.WriteLine("6. CreateSection({0}) ~ random value", maxValue); strLoc = "Loc_006oo"; iCountTestcases++; section = BitVector32.CreateSection(maxValue); expected = 0; while (maxValue > (int)System.Math.Pow(2, expected)) expected++; Console.WriteLine(" Mask: (real, exp): ({0}, {1})", section.Mask, (int)System.Math.Pow(2, expected) - 1); if (section.Mask != (int)System.Math.Pow(2, expected) - 1 || section.Offset != 0) { iCountErrors++; Console.WriteLine(" Err_0006, CreateSection({0}) returned ({1}, {2}) instead of expected ({3}, {4})", maxValue, section.Mask, section.Offset, (int)System.Math.Pow(2, expected) - 1, 0); } maxValue = 1; Console.WriteLine("7. CreateSection({0}) and apply to BitVector32({0})", maxValue); strLoc = "Loc_007oo"; iCountTestcases++; section = BitVector32.CreateSection(maxValue); bv32 = new BitVector32(maxValue); Console.WriteLine(" - get section value"); if (bv32[section] != maxValue) { iCountErrors++; Console.WriteLine(" Err_0007a, BitVector32[{0}] returned {1} instead of expected {2}", section.ToString(), bv32[section], maxValue); } expected = 0; iCountTestcases++; Console.WriteLine(" - set section value to {0}", expected); bv32[section] = expected; if (bv32[section] != expected || bv32.Data != expected) { iCountErrors++; Console.WriteLine(" Err_0007b, failed to set section to {0}", expected); } expected = 1; iCountTestcases+=5; Console.WriteLine(" - set section value to {0}", expected); bv32[section] = expected; if (bv32[section] != expected || bv32.Data != expected) { iCountErrors++; Console.WriteLine(" Err_0007c, failed to set section to {0}", expected); } maxValue = 6; Console.WriteLine("8. CreateSection({0}) and apply to BitVector32({0})", maxValue); strLoc = "Loc_007oo"; iCountTestcases++; section = BitVector32.CreateSection(maxValue); bv32 = new BitVector32(maxValue); Console.WriteLine(" - get section value"); if (bv32[section] != maxValue) { iCountErrors++; Console.WriteLine(" Err_0008a, BitVector32[{0}] returned {1} instead of expected {2}", section.ToString(), bv32[section], maxValue); } expected = 0; iCountTestcases++; Console.WriteLine(" - set section value to {0}", expected); bv32[section] = expected; if (bv32[section] != expected || bv32.Data != expected) { iCountErrors++; Console.WriteLine(" Err_0008b, failed to set section to {0}", expected); } expected = 1; iCountTestcases++; Console.WriteLine(" - set section value to {0}", expected); bv32[section] = expected; if (bv32[section] != expected || bv32.Data != expected) { iCountErrors++; Console.WriteLine(" Err_0008c, failed to set section to {0}", expected); } expected = 3; iCountTestcases++; Console.WriteLine(" - set section value to {0}", expected); bv32[section] = expected; if (bv32[section] != expected || bv32.Data != expected) { iCountErrors++; Console.WriteLine(" Err_0008d, failed to set section to {0}", expected); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public BitVector64(BitVector32 source) { this.data = source.Data; }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; BitVector32 bv32; int data = 0; int [] bits = { 0, 1, 2, 3, 7, 15, 16, Int16.MaxValue, Int32.MaxValue - 1, Int32.MinValue, Int16.MinValue, -1 }; try { Console.WriteLine("1. default ctor"); strLoc = "Loc_001oo"; bv32 = new BitVector32(); Console.WriteLine(" " + bv32.ToString()); iCountTestcases++; if (bv32.Data != 0) { iCountErrors++; Console.WriteLine("Err_0001, Data = {0} after default ctor", bv32.Data); } bool expected = false; for (int i = 0; i < bits.Length; i++) { iCountTestcases++; bv32[bits[i]] = true; if (i==9 || i == 10 || i == 11) expected = false; else expected = true; if (bv32[bits[i]] != expected) { iCountErrors++; Console.WriteLine("Err_0001_{0}a, bit[{3}]: returned {1} instead of {2}", i, bv32[bits[i]], true, bits[i]); } iCountTestcases++; if (bv32.Data != bits[i]) { iCountErrors++; Console.WriteLine("Err_0001_{0}b, Data returned {1} instead of {2}", i, bv32.Data, bits[i]); } iCountTestcases++; bv32[bits[i]] = false; if (i==0) expected = true; else expected = false; if (bv32[bits[i]] != expected) { iCountErrors++; Console.WriteLine("Err_0001_{0}c, bit[{3}]: returned {1} instead of {2}", i, bv32[bits[i]], expected, bits[i]); } iCountTestcases++; if (bv32.Data != 0) { iCountErrors++; Console.WriteLine("Err_0001_{0}d, Data returned {1} instead of {2}", i, bv32.Data, 0); } } data = -1; Console.WriteLine("2. BitVector32({0})", data); strLoc = "Loc_002oo"; bv32 = new BitVector32(data); Console.WriteLine(" " + bv32.ToString()); iCountTestcases++; if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0002, Data = {0} ", bv32.Data); } for (int i = 0; i < bits.Length; i++) { iCountTestcases++; bv32[bits[i]] = false; if (i==0) expected = true; else expected = false; if (bv32[bits[i]] != expected) { iCountErrors++; Console.WriteLine("Err_0002_{0}a, bit[{3}]: returned {1} instead of {2}", i, bv32[bits[i]], expected, bits[i]); } iCountTestcases++; if (bv32.Data != ~bits[i]) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, Data returned {1} instead of {2}", i, bv32.Data, ~bits[i]); } if (i==9 || i == 10 || i == 11) expected = false; else expected = true; iCountTestcases++; bv32[bits[i]] = true; if (bv32[bits[i]] != expected) { iCountErrors++; Console.WriteLine("Err_0002_{0}c, bit[{3}]: returned {1} instead of {2}", i, bv32[bits[i]], true, bits[i]); } iCountTestcases++; if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0002_{0}d, Data returned {1} instead of {2}", i, bv32.Data, data); } } for (int i = 0; i < bits.Length; i++) { int ind = i+3; data = bits[i]; Console.WriteLine((ind).ToString() + ". BitVector32({0})", data); strLoc = "Loc_00" + ind + "oo"; bv32 = new BitVector32(data); Console.WriteLine(" " + bv32.ToString()); iCountTestcases++; if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_000{1}, Data = {0} ", bv32.Data, ind); } iCountTestcases++; bv32[bits[i]] = false; if (i==0) expected = true; else expected = false; if (bv32[bits[i]] != expected) { iCountErrors++; Console.WriteLine("Err_000{4}_{0}a, bit[{3}]: returned {1} instead of {2}", i, bv32[bits[i]], expected, bits[i], ind); } iCountTestcases++; if (bv32.Data != 0) { iCountErrors++; Console.WriteLine("Err_000{4}_{0}b, Data returned {1} instead of {2}", i, bv32.Data, 0, ind); } iCountTestcases++; bv32[bits[i]] = true; if (i==9 || i == 10 || i == 11) expected = false; else expected = true; if (bv32[bits[i]] != expected) { iCountErrors++; Console.WriteLine("Err_000{4}_{0}c, bit[{3}]: returned {1} instead of {2}", i, bv32[bits[i]], true, bits[i], ind); } iCountTestcases++; if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_000{3}_{0}d, Data returned {1} instead of {2}", i, bv32.Data, data, ind); } } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine(""); Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine(""); Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
internal static AutoSizeMode GetAutoSizeMode(IArrangedElement element) { BitVector32 state = GetLayoutState(element); return(state[_autoSizeModeSection] == 0 ? AutoSizeMode.GrowOnly : AutoSizeMode.GrowAndShrink); }
public static void Get_Mask_NoneSetTest() { BitVector32 none = new BitVector32(); int mask = 0; for (int count = 0; count < 32; count++) { mask = BitVector32.CreateMask(mask); Assert.False(none[mask]); } Assert.Equal(int.MinValue, mask); }
internal static void SetLayoutState(IArrangedElement element, BitVector32 state) { element.Properties.SetInteger(_layoutStateProperty, state.Data); }
public static void Set_Mask_Multiple_UnsetTest(int start, int expected, int[] maskPositions) { int mask = maskPositions.Sum(x => 1 << (x - 1)); BitVector32 set = new BitVector32(); set[mask] = true; for (int bit = 0; bit < 32; bit++) { bool willUnset = maskPositions.Contains(bit + 1); Assert.Equal(willUnset, set[1 << bit]); set[1 << bit] = false; Assert.False(set[1 << bit]); } Assert.Equal(set, new BitVector32()); }
public void Save(Stream OutStream, PaletteType paletteType, DitherType ditherType, int colorCount) { using (var Writer = new BinaryWriter(OutStream)) { //Header Writer.Write(FileType.ToCharArray()); Writer.Write(FileVersion.ToCharArray()); //Logical Screen Descriptor var w = Frames[0].Image.Width; var h = Frames[0].Image.Height; Writer.Write((short)(DefaultWidth == 0 ? w : DefaultWidth)); // Initial Logical Width Writer.Write((short)(DefaultHeight == 0 ? h : DefaultHeight)); // Initial Logical Height byte gctInfo = 0; if (paletteType != PaletteType.Optimal) //use a global colortable { using (var gifStream = new MemoryStream()) { var bitmap = new Bitmap(Frames[0].Image); bitmap.ChangeTo8bppIndexed(paletteType, ditherType, colorCount); bitmap.Save(gifStream, ImageFormat.Gif); gifStream.Position = SourceGlobalColorInfoPosition; gctInfo = (byte)gifStream.ReadByte(); var bv = new BitVector32(gctInfo); var sizeSection = BitVector32.CreateSection(7); SourceColorBlockLength = (1 << (bv[sizeSection] + 1)) * 3; SourceGraphicControlExtensionPosition = SourceColorBlockLength + 13; SourceImageBlockPosition = SourceGraphicControlExtensionPosition; Writer.Write(gctInfo); // Global Color Table Info Writer.Write((byte)0); // Background Color Index Writer.Write((byte)0); // Pixel aspect ratio WriteColorTable(gifStream, Writer); } } else //local colortables will be used for each frame { Writer.Write(gctInfo); // Global Color Table Info Writer.Write((byte)0); // Background Color Index Writer.Write((byte)0); // Pixel aspect ratio } //Netscape extension for looping animations unchecked { Writer.Write((short)ApplicationExtensionBlockIdentifier); }; Writer.Write((byte)ApplicationBlockSize); Writer.Write(NetscapeIdentification.ToCharArray()); Writer.Write((byte)3); // Application block length Writer.Write((byte)1); Writer.Write((short)Repeat); // Repeat count for images. Writer.Write((byte)0); // terminator // vvvv Extension Header unchecked { Writer.Write((short)ApplicationExtensionBlockIdentifier); }; Writer.Write((byte)ApplicationBlockSize); Writer.Write(VVVVIdentification.ToCharArray()); Writer.Write((byte)1); // Application block length Writer.Write((byte)0); // dummy Writer.Write((byte)0); // terminator //individual frames for (int i = 0; i < Count; ++i) { var frame = Frames[i]; { using (var gifStream = new MemoryStream()) { var bitmap = new Bitmap(frame.Image); if (bitmap.ChangeTo8bppIndexed(paletteType, ditherType, colorCount) == 0) { bitmap.Save(gifStream, ImageFormat.Gif); } else { frame.Image.Save(gifStream, ImageFormat.Gif); } WriteGraphicControlBlock(gifStream, Writer, frame.Delay); WriteImageBlock(gifStream, Writer, paletteType == PaletteType.Optimal, frame.XOffset, frame.YOffset, bitmap.Width, bitmap.Height); } } } // Complete File Writer.Write(FileTrailer); } }
public static void Section_Unequal_EqualsTest(BitVector32.Section left, BitVector32.Section right) { Assert.False(left.Equals(right)); Assert.False(right.Equals(left)); Assert.False(left.Equals((object)right)); Assert.False(right.Equals((object)left)); Assert.False(left.Equals(new object())); Assert.False(left == right); Assert.False(right == left); Assert.True(left != right); Assert.True(right != left); }
public Layer(PsdBinaryReader reader, PsdFile psdFile) : this(psdFile) { Rect = reader.ReadRectangle(); //----------------------------------------------------------------------- // Read channel headers. Image data comes later, after the layer header. int numberOfChannels = reader.ReadUInt16(); for (int channel = 0; channel < numberOfChannels; channel++) { var ch = new Channel(reader, this); Channels.Add(ch); } //----------------------------------------------------------------------- // var signature = reader.ReadAsciiChars(4); if (signature != "8BIM") { throw (new PsdInvalidException("Invalid signature in layer header.")); } BlendModeKey = reader.ReadAsciiChars(4); Opacity = reader.ReadByte(); Clipping = reader.ReadBoolean(); var flagsByte = reader.ReadByte(); flags = new BitVector32(flagsByte); reader.ReadByte(); //padding //----------------------------------------------------------------------- // This is the total size of the MaskData, the BlendingRangesData, the // Name and the AdjustmentLayerInfo. var extraDataSize = reader.ReadUInt32(); var extraDataStartPosition = reader.BaseStream.Position; Masks = new MaskInfo(reader, this); BlendingRangesData = new BlendingRanges(reader, this); Name = reader.ReadPascalString(4); //----------------------------------------------------------------------- // Process Additional Layer Information long adjustmentLayerEndPos = extraDataStartPosition + extraDataSize; while (reader.BaseStream.Position < adjustmentLayerEndPos) { var layerInfo = LayerInfoFactory.Load(reader); AdditionalInfo.Add(layerInfo); } foreach (var adjustmentInfo in AdditionalInfo) { switch (adjustmentInfo.Key) { case "luni": Name = ((LayerUnicodeName)adjustmentInfo).Name; break; } } }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; BitVector32 bv32; BitVector32 bv32_1; string str = ""; string str_1 = ""; int data = 0; try { Console.WriteLine("1. two default structs"); strLoc = "Loc_001oo"; iCountTestcases++; bv32 = new BitVector32(); bv32_1 = new BitVector32(); str = bv32.ToString(); str_1 = bv32_1.ToString(); if (String.Compare(str, str_1) != 0) { iCountErrors++; Console.WriteLine("Err_0001, ToString() of two default structs: \"{0}\" != \"{1}\"", str, str_1); } Console.WriteLine("2. two random vectors"); DateTime time = DateTime.Now; data = time.DayOfYear + time.Hour + time.Minute + time.Second; System.Random random = new System.Random(data); data = random.Next(System.Int32.MinValue, System.Int32.MaxValue); iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); str = bv32.ToString(); str_1 = bv32_1.ToString(); if (String.Compare(str, str_1) != 0) { iCountErrors++; Console.WriteLine("Err_0002, ToString() of two equal vectors: \"{0}\" != \"{1}\"", str, str_1); } Console.WriteLine("3. two different vectors"); strLoc = "Loc_003oo"; iCountTestcases++; bv32 = new BitVector32(data); if (data < Int32.MaxValue) data++; else data--; bv32_1 = new BitVector32(data); str = bv32.ToString(); str_1 = bv32_1.ToString(); if (String.Compare(str, str_1) == 0) { iCountErrors++; Console.WriteLine("Err_0003, ToString() of two different vectors: \"{0}\" == \"{1}\"", str, str_1); } Console.WriteLine("4. same vector - default struct"); strLoc = "Loc_004oo"; iCountTestcases++; bv32 = new BitVector32(); str = bv32.ToString(); str_1 = bv32.ToString(); if (String.Compare(str, str_1) != 0) { iCountErrors++; Console.WriteLine("Err_0004, ToString() of the same default struct: \"{0}\" != \"{1}\"", str, str_1); } Console.WriteLine("5. same vector"); strLoc = "Loc_005oo"; iCountTestcases++; bv32 = new BitVector32(data); str = bv32.ToString(); str_1 = bv32.ToString(); if (String.Compare(str, str_1) != 0) { iCountErrors++; Console.WriteLine("Err_0005, ToString() of the same vector: \"{0}\" != \"{1}\"", str, str_1); } data = 0; Console.WriteLine("6. two vectors({0})", data); strLoc = "Loc_006oo"; iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); str = bv32.ToString(); str_1 = bv32_1.ToString(); if (String.Compare(str, str_1) != 0) { iCountErrors++; Console.WriteLine("Err_0006, ToString() of two {2}-vectors: \"{0}\" != \"{1}\"", str, str_1, data); } data = 1; Console.WriteLine("7. two vectors({0})", data); strLoc = "Loc_007oo"; iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); str = bv32.ToString(); str_1 = bv32_1.ToString(); if (String.Compare(str, str_1) != 0) { iCountErrors++; Console.WriteLine("Err_0007, ToString() of two {2}-vectors: \"{0}\" != \"{1}\"", str, str_1, data); } data = -1; Console.WriteLine("8. two vectors({0})", data); strLoc = "Loc_008oo"; iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); str = bv32.ToString(); str_1 = bv32_1.ToString(); if (String.Compare(str, str_1) != 0) { iCountErrors++; Console.WriteLine("Err_0008, ToString() of two {2}-vectors: \"{0}\" != \"{1}\"", str, str_1, data); } data = Int32.MaxValue; Console.WriteLine("9. two vectors({0})", data); strLoc = "Loc_009oo"; iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); str = bv32.ToString(); str_1 = bv32_1.ToString(); if (String.Compare(str, str_1) != 0) { iCountErrors++; Console.WriteLine("Err_0009, ToString() of two {2}-vectors: \"{0}\" != \"{1}\"", str, str_1, data); } data = Int32.MinValue; Console.WriteLine("10. two vectors({0})", data); strLoc = "Loc_010oo"; iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); str = bv32.ToString(); str_1 = bv32_1.ToString(); if (String.Compare(str, str_1) != 0) { iCountErrors++; Console.WriteLine("Err_0010, ToString() of two {2}-vectors: \"{0}\" != \"{1}\"", str, str_1, data); } Console.WriteLine("11. contains \"BitVector32\""); strLoc = "Loc_011oo"; iCountTestcases++; time = DateTime.Now; data = time.DayOfYear + time.Hour + time.Minute + time.Second; random = new System.Random(data); data = random.Next(System.Int32.MinValue, System.Int32.MaxValue); bv32 = new BitVector32(data); str = bv32.ToString(); Console.WriteLine("ToString() returns: " + str); if (str.IndexOf("BitVector32") == -1) { iCountErrors++; Console.WriteLine("Err_0011, ToString() doesn't contain \"BitVector32\""); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
/// <inheritdoc /> public int ValidateAndGetLength(BitVector32 value, ref NpgsqlLengthCache?lengthCache, NpgsqlParameter?parameter) => value.Data == 0 ? 4 : 8;
public static string ToString(BitVector32.Section value);
/// <summary> /// Data used for testing equal sections. /// </summary> /// Format is: /// 1. Section left /// 2. Section right /// <returns>Row of data</returns> public static IEnumerable <object[]> Section_Equal_Data() { BitVector32.Section original = BitVector32.CreateSection(16); BitVector32.Section nested = BitVector32.CreateSection(16, original); yield return(new object[] { original, original }); yield return(new object[] { original, BitVector32.CreateSection(16) }); yield return(new object[] { BitVector32.CreateSection(16), original }); // Since the max value is changed to an inclusive mask, equal to mask max value yield return(new object[] { original, BitVector32.CreateSection(31) }); yield return(new object[] { nested, nested }); yield return(new object[] { nested, BitVector32.CreateSection(16, original) }); yield return(new object[] { BitVector32.CreateSection(16, original), nested }); yield return(new object[] { nested, BitVector32.CreateSection(31, original) }); yield return(new object[] { nested, BitVector32.CreateSection(16, BitVector32.CreateSection(16)) }); yield return(new object[] { BitVector32.CreateSection(16, BitVector32.CreateSection(16)), nested }); yield return(new object[] { nested, BitVector32.CreateSection(31, BitVector32.CreateSection(16)) }); // Because it only stores the offset, and not the previous section, later sections may be equal yield return(new object[] { nested, BitVector32.CreateSection(16, BitVector32.CreateSection(8, BitVector32.CreateSection(1))) }); yield return(new object[] { BitVector32.CreateSection(16, BitVector32.CreateSection(8, BitVector32.CreateSection(1))), nested }); }
public int this[BitVector32.Section section] { get; set; }
public static void Mask_DefaultTest() { Assert.Equal(1, BitVector32.CreateMask()); Assert.Equal(1, BitVector32.CreateMask(0)); }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; BitVector32 bv32; int data = 0; int [] bits = { 0, 1, 2, 3, 7, 15, 16, Int16.MaxValue, Int32.MaxValue - 1, Int32.MinValue, Int16.MinValue, -1 }; try { Console.WriteLine("1. default ctor"); strLoc = "Loc_001oo"; bv32 = new BitVector32(); Console.WriteLine(" " + bv32.ToString()); iCountTestcases++; if (bv32.Data != 0) { iCountErrors++; Console.WriteLine("Err_0001, Data = {0} after default ctor", bv32.Data); } bool expected = false; for (int i = 0; i < bits.Length; i++) { iCountTestcases++; if (i == 0) expected = true; else expected = false; if (bv32[bits[i]] != expected) { iCountErrors++; Console.WriteLine("Err_0001_{0}, bit[{3}]: returned {1} instead of {2}", i, bv32[bits[i]], expected, bits[i]); } } data = -1; Console.WriteLine("2. BitVector32({0})", data); strLoc = "Loc_002oo"; bv32 = new BitVector32(data); Console.WriteLine(" " + bv32.ToString()); iCountTestcases++; if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0002, Data = {0} ", bv32.Data); } for (int i = 0; i < bits.Length; i++) { iCountTestcases++; if (i == 9 || i == 10 || i == 11) expected = false; else expected = true; if (bv32[bits[i]] != expected) { iCountErrors++; string temp = "Err_0002_" + i; Console.WriteLine("{0}: bit[{3}]: returned {1} instead of {2}", temp, bv32[bits[i]], expected, bits[i]); } } data = Int32.MaxValue; Console.WriteLine("3. BitVector32({0}) - Int32.MaxValue", data); strLoc = "Loc_003oo"; bv32 = new BitVector32(data); Console.WriteLine(" " + bv32.ToString()); iCountTestcases++; if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0003, Data = {0} ", bv32.Data); } for (int i = 0; i < bits.Length; i++) { iCountTestcases++; if (i == (bits.Length-1) || i == (bits.Length-2) || i == (bits.Length-3)) expected = false; else expected = true; if (bv32[bits[i]] != expected) { iCountErrors++; string temp = "Err_0003_" + i; Console.WriteLine("{0}: bit[{3}]: returned {1} instead of {2}", temp, bv32[bits[i]], expected, bits[i]); } } data = Int32.MinValue; Console.WriteLine("4. BitVector32({0}) - Int32.MinValue", data); strLoc = "Loc_004oo"; bv32 = new BitVector32(data); Console.WriteLine(" " + bv32.ToString()); iCountTestcases++; if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0004, Data = {0} ", bv32.Data); } for (int i = 0; i < bits.Length; i++) { iCountTestcases++; if (i == 0) expected = true; else expected = false; if (bv32[bits[i]] != expected) { iCountErrors++; string temp = "Err_0004_" + i; Console.WriteLine("{0}: bit[{3}]: returned {1} instead of {2}", temp, bv32[bits[i]], expected, bits[i]); } } data = 1; Console.WriteLine("5. BitVector32({0})", data); strLoc = "Loc_005oo"; bv32 = new BitVector32(data); Console.WriteLine(" " + bv32.ToString()); iCountTestcases++; if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0005, Data = {0} ", bv32.Data); } for (int i = 0; i < bits.Length; i++) { iCountTestcases++; if (i == 0 || i == 1) expected = true; else expected = false; if (bv32[bits[i]] != expected) { iCountErrors++; string temp = "Err_0005_" + i; Console.WriteLine("{0}: bit[{3}]: returned {1} instead of {2}", temp, bv32[bits[i]], expected, bits[i]); } } data = 2; Console.WriteLine("6. BitVector32({0})", data); strLoc = "Loc_006oo"; bv32 = new BitVector32(data); Console.WriteLine(" " + bv32.ToString()); iCountTestcases++; if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0006, Data = {0} ", bv32.Data); } for (int i = 0; i < bits.Length; i++) { iCountTestcases++; if (i == 0 || i == 2) expected = true; else expected = false; if (bv32[bits[i]] != expected) { iCountErrors++; string temp = "Err_0006_" + i; Console.WriteLine("{0}: bit[{3}]: returned {1} instead of {2}", temp, bv32[bits[i]], expected, bits[i]); } } data = 3; Console.WriteLine("6. BitVector32({0})", data); strLoc = "Loc_006oo"; bv32 = new BitVector32(data); Console.WriteLine(" " + bv32.ToString()); iCountTestcases++; if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0006, Data = {0} ", bv32.Data); } for (int i = 0; i < bits.Length; i++) { iCountTestcases++; if (i < 4) expected = true; else expected = false; if (bv32[bits[i]] != expected) { iCountErrors++; string temp = "Err_0006_" + i; Console.WriteLine("{0}: bit[{3}]: returned {1} instead of {2}", temp, bv32[bits[i]], expected, bits[i]); } } data = 7; Console.WriteLine("7. BitVector32({0})", data); strLoc = "Loc_007oo"; bv32 = new BitVector32(data); Console.WriteLine(" " + bv32.ToString()); iCountTestcases++; if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0007, Data = {0} ", bv32.Data); } for (int i = 0; i < bits.Length; i++) { iCountTestcases++; if (i < 5) expected = true; else expected = false; if (bv32[bits[i]] != expected) { iCountErrors++; string temp = "Err_0007_" + i; Console.WriteLine("{0}: bit[{3}]: returned {1} instead of {2}", temp, bv32[bits[i]], expected, bits[i]); } } data = Int16.MaxValue; Console.WriteLine("8. BitVector32({0}) - Int16.MaxValue", data); strLoc = "Loc_008oo"; bv32 = new BitVector32(data); Console.WriteLine(" " + bv32.ToString()); iCountTestcases++; if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0008, Data = {0} ", bv32.Data); } for (int i = 0; i < bits.Length; i++) { iCountTestcases++; if (i < 8) expected = true; else expected = false; if (bv32[bits[i]] != expected) { iCountErrors++; string temp = "Err_0008_" + i; Console.WriteLine("{0}: bit[{3}]: returned {1} instead of {2}", temp, bv32[bits[i]], expected, bits[i]); } } data = Int16.MinValue; Console.WriteLine("9. BitVector32({0}) - Int16.MomValue", data); strLoc = "Loc_009oo"; bv32 = new BitVector32(data); Console.WriteLine(" " + bv32.ToString()); iCountTestcases++; if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0009, Data = {0} ", bv32.Data); } for (int i = 0; i < bits.Length; i++) { iCountTestcases++; if (i == 0) expected = true; else expected = false; if (bv32[bits[i]] != expected) { iCountErrors++; string temp = "Err_0009_" + i; Console.WriteLine("{0}: bit[{3}]: returned {1} instead of {2}", temp, bv32[bits[i]], expected, bits[i]); } } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine(""); Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine(""); Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public static void Mask_LastTest() { Assert.Throws <InvalidOperationException>(() => BitVector32.CreateMask(int.MinValue)); }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; BitVector32 bv32; BitVector32 bv32Temp; try { Console.WriteLine("--- default ctor ---"); strLoc = "Loc_001oo"; iCountTestcases++; bv32 = new BitVector32(); Console.WriteLine("1. check Data"); if (bv32.Data != 0) { iCountErrors++; Console.WriteLine("Err_0001, Data = {0} after default ctor", bv32.Data); } iCountTestcases++; Console.WriteLine("2. check returned Type"); string type = bv32.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + type); if (type.IndexOf("BitVector32") == -1) { iCountErrors++; Console.WriteLine("Err_0002: returned type doesn't contain \"BitVector32\""); } bv32Temp = new BitVector32(3); string type1 = bv32Temp.GetType().ToString().Trim(); if (String.Compare(type, type1) != 0) { iCountErrors++; Console.WriteLine("Err_0003: returned types of two vectors differ"); } iCountTestcases++; Console.WriteLine("3. call ToString()"); string result = bv32.ToString(); Console.WriteLine(" ToString(): " + result); if (result.IndexOf("BitVector32") == -1) { iCountErrors++; Console.WriteLine("Err_0004: ToString() doesn't contain \"BitVector32\""); } iCountTestcases++; Console.WriteLine("4. Item(1)"); bool item = bv32[1]; Console.WriteLine(" Item(1): " + item); if (item) { iCountErrors++; Console.WriteLine("Err_0005: Item(0) returned {0} instead of {1}", item, false); } iCountTestcases++; Console.WriteLine("5. Equals"); bv32Temp = new BitVector32(); if (! bv32.Equals(bv32Temp) ) { iCountErrors++; Console.WriteLine("Err_0006: two default vectors are not equal"); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public static void CreateSectionTest(short maximum, short mask) { BitVector32.Section section = BitVector32.CreateSection(maximum); Assert.Equal(0, section.Offset); Assert.Equal(mask, section.Mask); }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; BitVector32 bv32; int data = 0; try { Console.WriteLine("1. default ctor"); strLoc = "Loc_001oo"; iCountTestcases++; bv32 = new BitVector32(); if (bv32.Data != 0) { iCountErrors++; Console.WriteLine("Err_0001, Data = {0} after default ctor", bv32.Data); } data = 0; Console.WriteLine("2. ctor({0})", data); strLoc = "Loc_002oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0002, Data = {0} after ctor({1})", bv32.Data, data); } data = 1; Console.WriteLine("3. ctor({0})", data); strLoc = "Loc_003oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0003, Data = {0} after ctor({1})", bv32.Data, data); } data = -1; Console.WriteLine("4. ctor({0})", data); strLoc = "Loc_004oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0004, Data = {0} after ctor({1})", bv32.Data, data); } data = 2; Console.WriteLine("5. ctor({0})", data); strLoc = "Loc_005oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0005, Data = {0} after ctor({1})", bv32.Data, data); } data = 10; Console.WriteLine("6. ctor({0})", data); strLoc = "Loc_006oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0006, Data = {0} after ctor({1})", bv32.Data, data); } data = 99; Console.WriteLine("7. ctor({0})", data); strLoc = "Loc_007oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0007, Data = {0} after ctor({1})", bv32.Data, data); } data = -9; Console.WriteLine("8. ctor({0})", data); strLoc = "Loc_008oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0008, Data = {0} after ctor({1})", bv32.Data, data); } data = System.Int32.MinValue; Console.WriteLine("9. ctor({0})", data); strLoc = "Loc_009oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0009, Data = {0} after ctor({1})", bv32.Data, data); } data = System.Int32.MaxValue; Console.WriteLine("10. ctor({0})", data); strLoc = "Loc_010oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0010, Data = {0} after ctor({1})", bv32.Data, data); } data = System.Int32.MinValue / 2; Console.WriteLine("11. ctor({0})", data); strLoc = "Loc_011oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0011, Data = {0} after ctor({1})", bv32.Data, data); } data = System.Int32.MaxValue / 2; Console.WriteLine("12. ctor({0})", data); strLoc = "Loc_012oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0012, Data = {0} after ctor({1})", bv32.Data, data); } DateTime time = DateTime.Now; data = time.DayOfYear + time.Hour + time.Minute + time.Second; System.Random random = new System.Random(data); data = random.Next(System.Int32.MinValue, System.Int32.MaxValue); Console.WriteLine("13. ctor(random data: {0})", data); strLoc = "Loc_013oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0013, Data = {0} after ctor({1})", bv32.Data, data); } data = 7; Console.WriteLine("14. access Data on BitVector32({0})", data); strLoc = "Loc_014oo"; iCountTestcases++; bv32 = new BitVector32(data); Console.WriteLine(" a. check Data"); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0014a, Data = {0} after ctor({1})", bv32.Data, data); } iCountTestcases++; int mask = BitVector32.CreateMask(); Console.WriteLine(" b. access via Mask " + mask); strLoc = "Loc_014oo"; if ((bv32.Data & mask) != mask) { iCountErrors++; Console.WriteLine("Err_0014b, {0} & {1} != {1}", bv32.Data, mask); } iCountTestcases++; BitVector32.Section sect = BitVector32.CreateSection(1); Console.WriteLine(" c. access via Section {0}", sect.ToString()); Console.WriteLine(" - get section value"); strLoc = "Loc_015oo"; if ((bv32[sect]) != 1) { iCountErrors++; Console.WriteLine("Err_0014c, bv32[{0}] != {1}", sect, 1); } Console.WriteLine(" - set section value and verify Data"); bv32[sect] = 0; if (bv32.Data != 6) { iCountErrors++; Console.WriteLine("Err_0014c, Data: {0} != {1}", bv32.Data, 6); } iCountTestcases++; strLoc = "Loc_016oo"; sect = BitVector32.CreateSection(5); Console.WriteLine(" d. access via Section {0}", sect.ToString()); Console.WriteLine(" - get section value"); if ((bv32[sect]) != bv32.Data) { iCountErrors++; Console.WriteLine("Err_0014d, bv32[{0}] != {1}", sect, bv32.Data); } Console.WriteLine(" - set section value and verify Data"); bv32[sect] = 0; if (bv32.Data != 0) { iCountErrors++; Console.WriteLine("Err_0014e, Data: {0} != {1}", bv32.Data, 0); } data = -1; Console.WriteLine("15. access Data on BitVector32({0})", data); strLoc = "Loc_017oo"; iCountTestcases++; bv32 = new BitVector32(data); Console.WriteLine(" a. check Data"); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0015a, Data = {0} after ctor({1})", bv32.Data, data); } iCountTestcases++; strLoc = "Loc_018oo"; sect = BitVector32.CreateSection(1); sect = BitVector32.CreateSection(Int16.MaxValue, sect); sect = BitVector32.CreateSection(Int16.MaxValue, sect); sect = BitVector32.CreateSection(1, sect); Console.WriteLine(" b. access via Section: {0} - offset {1} - sign bit", sect.ToString(), (int)sect.Offset); Console.WriteLine(" " + bv32.ToString()); bv32[sect] = 0; if (bv32.Data != Int32.MaxValue) { iCountErrors++; Console.WriteLine("Err_0015b, Data: {0} != {1}", bv32.Data, Int32.MaxValue); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public static void CreateSection_InvalidMaximumTest(short maxvalue) { AssertExtensions.Throws <ArgumentException>("maxValue", () => BitVector32.CreateSection(maxvalue)); BitVector32.Section valid = BitVector32.CreateSection(1); AssertExtensions.Throws <ArgumentException>("maxValue", () => BitVector32.CreateSection(maxvalue, valid)); }
public static void Get_Mask_AllSetTest() { BitVector32 all = new BitVector32(-1); int mask = 0; for (int count = 0; count < 32; count++) { mask = BitVector32.CreateMask(mask); Assert.True(all[mask]); } Assert.Equal(int.MinValue, mask); }
public static void ToStringTest(int data, string expected) { Assert.Equal(expected, new BitVector32(data).ToString()); Assert.Equal(expected, BitVector32.ToString(new BitVector32(data))); }
public static void Get_Mask_SomeSetTest() { // Constructs data with every even bit set. int data = Enumerable.Range(0, 16).Sum(x => 1 << (x * 2)); BitVector32 some = new BitVector32(data); int mask = 0; for (int index = 0; index < 32; index++) { mask = BitVector32.CreateMask(mask); Assert.Equal(index % 2 == 0, some[mask]); } Assert.Equal(int.MinValue, mask); }
/// <summary> /// Data used for testing setting/unsetting via sections. /// </summary> /// Format is: /// 1. value /// 2. section /// <returns>Row of data</returns> public static IEnumerable <object[]> Section_Set_Data() { yield return(new object[] { 0, BitVector32.CreateSection(1) }); yield return(new object[] { 1, BitVector32.CreateSection(1) }); yield return(new object[] { 0, BitVector32.CreateSection(short.MaxValue) }); yield return(new object[] { short.MaxValue, BitVector32.CreateSection(short.MaxValue) }); yield return(new object[] { 0, BitVector32.CreateSection(1, BitVector32.CreateSection(byte.MaxValue)) }); yield return(new object[] { 1, BitVector32.CreateSection(1, BitVector32.CreateSection(byte.MaxValue)) }); yield return(new object[] { 0, BitVector32.CreateSection(short.MaxValue, BitVector32.CreateSection(byte.MaxValue)) }); yield return(new object[] { short.MaxValue, BitVector32.CreateSection(short.MaxValue, BitVector32.CreateSection(byte.MaxValue)) }); yield return(new object[] { 16, BitVector32.CreateSection(short.MaxValue) }); yield return(new object[] { 16, BitVector32.CreateSection(short.MaxValue, BitVector32.CreateSection(byte.MaxValue)) }); yield return(new object[] { 31, BitVector32.CreateSection(short.MaxValue) }); yield return(new object[] { 31, BitVector32.CreateSection(short.MaxValue, BitVector32.CreateSection(byte.MaxValue)) }); yield return(new object[] { 16, BitVector32.CreateSection(byte.MaxValue) }); yield return(new object[] { 16, BitVector32.CreateSection(byte.MaxValue, BitVector32.CreateSection(byte.MaxValue, BitVector32.CreateSection(short.MaxValue))) }); yield return(new object[] { 31, BitVector32.CreateSection(byte.MaxValue) }); yield return(new object[] { 31, BitVector32.CreateSection(byte.MaxValue, BitVector32.CreateSection(byte.MaxValue, BitVector32.CreateSection(short.MaxValue))) }); }
public static void Set_Mask_UnsetAllTest() { BitVector32 flip = new BitVector32(-1); int mask = 0; for (int bit = 1; bit < 32 + 1; bit++) { mask = BitVector32.CreateMask(mask); BitVector32 single = new BitVector32(1 << (bit - 1)); Assert.True(single[mask]); single[mask] = false; Assert.False(single[mask]); Assert.Equal(0, single.Data); flip[mask] = false; } Assert.Equal(0, flip.Data); Assert.Equal(int.MinValue, mask); }
/// <summary> /// Force it to update the client masks /// </summary> private void UpdateMasks() { UpdateInterval = 0; var allTalk = ServerAllTalk.Float != 0; for (var iClient = 0; iClient < MaxPlayers; ++iClient) { var pEnt = PlayerUtils.PlayerByIndex(iClient + 1); if (pEnt == null || !pEnt.IsPlayer()) { continue; } var data = Players[iClient]; // Request the state of their "VModEnable" cvar. if (data.WantEnable) { var message = NetMessage.Begin(MsgDest.One, "ReqState", pEnt.Edict()); message.End(); } var pPlayer = (BasePlayer)pEnt; var gameRulesMask = new BitVector32(); if (data.EnableVoice) { // Build a mask of who they can hear based on the game rules. for (var iOtherClient = 0; iOtherClient < MaxPlayers; ++iOtherClient) { var pOtherPlayer = (BasePlayer)PlayerUtils.PlayerByIndex(iOtherClient + 1); if (pOtherPlayer != null && (allTalk || Helper.CanPlayerHearPlayer(pPlayer, pOtherPlayer))) { gameRulesMask[iOtherClient] = true; } } } // If this is different from what the client has, send an update. if (!Utils.BitVectorsEqual(ref gameRulesMask, ref data.SentGameRulesMasks) || !Utils.BitVectorsEqual(ref data.BanMasks, ref data.SentBanMasks)) { data.SentGameRulesMasks = gameRulesMask; data.SentBanMasks = data.BanMasks; var message = NetMessage.Begin(MsgDest.One, "VoiceMask", pPlayer.Edict()); for (var dw = 0; dw < VOICE_MAX_PLAYERS_DW; ++dw) { message.WriteLong(gameRulesMask.Data); message.WriteLong(data.BanMasks.Data); } message.End(); } // Tell the engine. for (int iOtherClient = 0; iOtherClient < MaxPlayers; ++iOtherClient) { var canHear = gameRulesMask[iOtherClient] && !data.BanMasks[iOtherClient]; Engine.Server.SetClientListening(iClient + 1, iOtherClient + 1, canHear); } } }
public static void Set_SectionTest(int value, BitVector32.Section section) { BitVector32 empty = new BitVector32(); empty[section] = value; Assert.Equal(value, empty[section]); Assert.Equal(value << section.Offset, empty.Data); BitVector32 full = new BitVector32(-1); full[section] = value; Assert.Equal(value, full[section]); int offsetMask = section.Mask << section.Offset; Assert.Equal((-1 & ~offsetMask) | (value << section.Offset), full.Data); }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; BitVector32 bv32; BitVector32 bv32_1; int data = 0; try { Console.WriteLine("1. two default structs"); strLoc = "Loc_001oo"; iCountTestcases++; bv32 = new BitVector32(); bv32_1 = new BitVector32(); if (!bv32.Equals(bv32_1)) { iCountErrors++; Console.WriteLine("Err_0001, two default structs are not equal"); } Console.WriteLine("2. two random vectors"); DateTime time = DateTime.Now; data = time.DayOfYear + time.Hour + time.Minute + time.Second; System.Random random = new System.Random(data); data = random.Next(System.Int32.MinValue, System.Int32.MaxValue); iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); if (!bv32.Equals(bv32_1)) { iCountErrors++; Console.WriteLine("Err_0002, two vectores with random data are not equal"); } Console.WriteLine("3. vector and null"); strLoc = "Loc_003oo"; iCountTestcases++; if (bv32.Equals(null)) { iCountErrors++; Console.WriteLine("Err_0003, vector and null are equal"); } Console.WriteLine("4. two different vectors"); strLoc = "Loc_004oo"; iCountTestcases++; bv32 = new BitVector32(data); if (data < Int32.MaxValue) { data++; } else { data--; } bv32_1 = new BitVector32(data); if (bv32.Equals(bv32_1)) { iCountErrors++; Console.WriteLine("Err_0004, two different vectors are equal"); } Console.WriteLine("5. vector and non-vector-object"); strLoc = "Loc_005oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Equals(data)) { iCountErrors++; Console.WriteLine("Err_0005, vector and non-vector-object are equal"); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! strLoc==" + strLoc + ", exc_general==\n" + exc_general.ToString()); } if (iCountErrors == 0) { Console.WriteLine("Pass. " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases); return(true); } else { Console.WriteLine("Fail! " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums); return(false); } }
// Regardless of mask size, values will be truncated if they hang off the end public static void Set_Section_OverflowTest(int value) { BitVector32 data = new BitVector32(); BitVector32.Section offset = BitVector32.CreateSection(short.MaxValue, BitVector32.CreateSection(short.MaxValue)); BitVector32.Section final = BitVector32.CreateSection(short.MaxValue, offset); data[final] = value; Assert.Equal((3 & value) << 30, data.Data); Assert.NotEqual(value, data.Data); Assert.Equal(3 & value, data[final]); Assert.NotEqual(value, data[final]); }
public static BitVector32.Section CreateSection(short maxValue, BitVector32.Section previous);
public static void Section_GetHashCodeTest(BitVector32.Section left, BitVector32.Section right) { Assert.Equal(left.GetHashCode(), left.GetHashCode()); Assert.Equal(left.GetHashCode(), right.GetHashCode()); }
public static string ToString(BitVector32 value);
public static void GetHashCodeTest() { BitVector32 original = new BitVector32(); Assert.Equal(original.GetHashCode(), original.GetHashCode()); Assert.Equal(new BitVector32().GetHashCode(), original.GetHashCode()); Assert.Equal(new BitVector32(0).GetHashCode(), original.GetHashCode()); BitVector32 other = new BitVector32(int.MaxValue / 2 - 1); Assert.Equal(other.GetHashCode(), other.GetHashCode()); Assert.Equal(new BitVector32(int.MaxValue / 2 - 1).GetHashCode(), other.GetHashCode()); }
public bool Equals(BitVector32.Section obj);
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; BitVector32 bv32; int data = 0; BitVector32.Section [] sect = new BitVector32.Section [6]; sect[0] = BitVector32.CreateSection(1); sect[1] = BitVector32.CreateSection(1, sect[0]); sect[2] = BitVector32.CreateSection(7); sect[3] = BitVector32.CreateSection(Int16.MaxValue); sect[4] = BitVector32.CreateSection(Int16.MaxValue, sect[3]); sect[5] = BitVector32.CreateSection(1, sect[4]); sect[5] = BitVector32.CreateSection(1, sect[5]); try { Console.WriteLine("- default ctor"); strLoc = "Loc_001oo"; bv32 = new BitVector32(); Console.WriteLine(bv32.ToString()); iCountTestcases++; if (bv32.Data != 0) { iCountErrors++; Console.WriteLine("Err_0001, Data = {0} after default ctor", bv32.Data); } Console.WriteLine("1. set all sections to max value"); for (int i = 0; i < sect.Length; i++) { iCountTestcases++; bv32[sect[i]] = (int)sect[i].Mask; if (bv32[sect[i]] != (int)sect[i].Mask ) { iCountErrors++; string temp = "Err_0001_" + i; if (i == sect.Length - 1) temp += " - Error - section for last bit"; Console.WriteLine("{0} returned {1} instead of {2}", temp, bv32[sect[i]], (int)sect[i].Mask); } } Console.WriteLine("2. set all sections to 0"); for (int i = 0; i < sect.Length; i++) { iCountTestcases++; bv32[sect[i]] = 0; if (bv32[sect[i]] != 0 ) { iCountErrors++; Console.WriteLine("Err_0002_{0}, returned {1} instead of {2}", i, bv32[sect[i]], 0); } } Console.WriteLine("3. set all sections to 1"); for (int i = 0; i < sect.Length; i++) { iCountTestcases++; bv32[sect[i]] = 1; if (bv32[sect[i]] != 1 ) { iCountErrors++; string temp = "Err_0003_" + i; if (i == sect.Length - 1) temp += " - Error - section for last bit"; Console.WriteLine("{0} returned {1} instead of {2}", temp, bv32[sect[i]], 1); } } Console.WriteLine("4. set to (max/2) where valid"); for (int i = 0; i < sect.Length; i++) { iCountTestcases++; if (((int)sect[i].Mask) > 3) { data = ((int)sect[i].Mask) / 2; bv32[sect[i]] = data; if (bv32[sect[i]] != data ) { iCountErrors++; string temp = "Err_0004_" + i; Console.WriteLine("{0} returned {1} instead of {2}", temp, bv32[sect[i]], data); } } } # if retail Console.WriteLine("5. set all to -1"); for (int i = 0; i < sect.Length; i++) { iCountTestcases++; try { bv32[sect[i]] = -1; if (bv32[sect[i]] != sect[i].Mask ) { iCountErrors++; string temp = "Err_0005a_" + i; Console.WriteLine(temp + ": didn't set section to " + sect[i].Mask); } } catch (Exception e) { iCountErrors++; string temp = "Err_0005b_" + i; Console.WriteLine(temp + ": unexpected exception - according to spec should not throw"); Console.WriteLine(e.ToString()); } } Console.WriteLine("6. set all to (max + 1)"); for (int i = 0; i < sect.Length; i++) { iCountTestcases++; try { int exp = (int)(sect[i].Mask) + 1; bv32[sect[i]] = exp; exp = sect[i].Mask & exp; if (bv32[sect[i]] != exp ) { iCountErrors++; string temp = "Err_0006a_" + i; Console.WriteLine(temp + ": didn't set section to " + exp); } } catch (Exception e) { iCountErrors++; string temp = "Err_0006b_" + i; Console.WriteLine(temp + ": unexpected exception - according to spec should not throw"); Console.WriteLine(e.ToString()); } } #endif } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine(""); Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine(""); Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public void Delete() { _chunk.DeleteEntry(_id & 0xFFFF); _flags = new BitVector32(0x22); _memAddress = 0; }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; BitVector32 bv32; int data = 0; int mask = 0; try { Console.WriteLine("1. Create first Mask"); strLoc = "Loc_001oo"; iCountTestcases++; mask = BitVector32.CreateMask(); Console.WriteLine(" first mask: " + mask); if (mask != 1) { iCountErrors++; Console.WriteLine("Err_0001b, Created Mask: {0} , expected: {1}", mask, 1); } Console.WriteLine("2. Create multiple first Masks"); strLoc = "Loc_002oo"; iCountTestcases++; mask = BitVector32.CreateMask(); int cnt = 50; int mask1 = 0; for (int i = 0; i < cnt; i++) { mask1 = BitVector32.CreateMask(); if (mask1 != mask) { iCountErrors++; string err = "Err_0002" + (i+1).ToString(); Console.WriteLine(err + ", Created Mask: {0} , expected: {1}", mask1, mask); } } data = 0; Console.WriteLine("3. Apply first Mask to BitVector32({0})", data); strLoc = "Loc_003oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0003a, Data: returned: {0} , expected: {1}", bv32.Data, data); } iCountTestcases++; mask = BitVector32.CreateMask(); if (mask != 1) { iCountErrors++; Console.WriteLine("Err_0003b, Created Mask: {0} , expected: {1}", mask, 1); } iCountTestcases++; if ((bv32.Data & mask) != 0) { iCountErrors++; Console.WriteLine("Err_0003c, {0} & {1} returned {2}, expected {3}", bv32.Data, mask, (bv32.Data & mask), 0); } iCountTestcases++; if ((bv32.Data | mask) != 1) { iCountErrors++; Console.WriteLine("Err_0003d, {0} | {1} returned {2}, expected {3}", bv32.Data, mask, (bv32.Data | mask), 1); } data = 1; Console.WriteLine("4. Apply first Mask to BitVector32({0})", data); strLoc = "Loc_004oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Data != data) { iCountErrors++; Console.WriteLine("Err_0004a, Data: returned: {0} , expected: {1}", bv32.Data, data); } iCountTestcases++; if ((bv32.Data & mask) != 1) { iCountErrors++; Console.WriteLine("Err_0004b, {0} & {1} returned {2}, expected {3}", bv32.Data, mask, (bv32.Data & mask), 1); } iCountTestcases++; if ((bv32.Data | mask) != 1) { iCountErrors++; Console.WriteLine("Err_0003d, {0} | {1} returned {2}, expected {3}", bv32.Data, mask, (bv32.Data | mask), 1); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }