public void WhiningSpinner_CheckEncodeAndDecode() { Tick t1 = new Tick(); Tick t2 = new Tick(); Tick t3 = new Tick(); Tick t4 = new Tick(); List <Tick> ticks = new List <Tick> { t1, t2, t3 }; WhiningTwine e1 = new WhiningTwine(10, ticks, t4); Assert.AreEqual(10, e1.CreatorId); Assert.IsNotNull(e1.Ticks); Assert.AreEqual(3, e1.Ticks.Count); Assert.AreSame(t1, e1.Ticks[0]); Assert.AreSame(t2, e1.Ticks[1]); Assert.AreSame(t3, e1.Ticks[2]); Assert.AreSame(t4, e1.RequestTick); ByteList bytes = new ByteList(); e1.Encode(bytes); WhiningTwine e2 = WhiningTwine.Create(bytes); Assert.AreEqual(e1.CreatorId, e2.CreatorId); Assert.AreEqual(e1.Ticks.Count, e2.Ticks.Count); Assert.AreEqual(e1.Ticks[0].LogicalClock, e2.Ticks[0].LogicalClock); Assert.AreEqual(e1.Ticks[0].HashCode, e2.Ticks[0].HashCode); Assert.AreEqual(e1.Ticks[1].LogicalClock, e2.Ticks[1].LogicalClock); Assert.AreEqual(e1.Ticks[1].HashCode, e2.Ticks[1].HashCode); Assert.AreEqual(e1.Ticks[2].LogicalClock, e2.Ticks[2].LogicalClock); Assert.AreEqual(e1.Ticks[2].HashCode, e2.Ticks[2].HashCode); Assert.AreEqual(e1.RequestTick.LogicalClock, e2.RequestTick.LogicalClock); Assert.AreEqual(e1.RequestTick.HashCode, e2.RequestTick.HashCode); bytes.Clear(); e1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { e2 = WhiningTwine.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); e1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { e2 = WhiningTwine.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
public void AgentInfo_CheckEncodeAndDecode() { EndPoint ep = new EndPoint("129.123.7.24:1345"); AgentInfo info1 = new AgentInfo(20, AgentInfo.PossibleAgentType.WhiningSpinner, ep) { ANumber = "A00001", FirstName = "Joe", LastName = "Jones", Location = new FieldLocation(10, 20, false), Strength = 1200.5, Speed = 1500.0 }; ByteList bytes = new ByteList(); info1.Encode(bytes); AgentInfo info2 = AgentInfo.Create(bytes); Assert.AreEqual(info1.Id, info2.Id); Assert.AreEqual(info1.AgentType, info2.AgentType); Assert.AreEqual(info1.ANumber, info2.ANumber); Assert.AreEqual(info1.FirstName, info2.FirstName); Assert.AreEqual(info1.LastName, info2.LastName); Assert.AreEqual(info1.Strength, info2.Strength); Assert.AreEqual(info1.Speed, info2.Speed); Assert.AreEqual(info1.Points, info2.Points); Assert.AreEqual(info1.Location.X, info2.Location.X); Assert.AreEqual(info1.Location.Y, info2.Location.Y); Assert.AreEqual(info1.CommunicationEndPoint.Address, info2.CommunicationEndPoint.Address); Assert.AreEqual(info1.CommunicationEndPoint.Port, info2.CommunicationEndPoint.Port); bytes.Clear(); info1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { info2 = AgentInfo.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); info1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { info2 = AgentInfo.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
public void Bomb_CheckEncodeAndDecode() { Tick t1 = new Tick(); List <Excuse> eList = new List <Excuse> { CreateExcuse(10), CreateExcuse(11), CreateExcuse(12) }; List <WhiningTwine> wtList = new List <WhiningTwine> { CreateTwine(20), CreateTwine(21), CreateTwine(22) }; Bomb b1 = new Bomb(1, eList, wtList, t1); Assert.AreEqual(1, b1.CreatorId); Assert.AreSame(eList, b1.Excuses); Assert.AreSame(wtList, b1.Twine); Assert.AreSame(t1, b1.BuiltOnTick); ByteList bytes = new ByteList(); b1.Encode(bytes); Bomb b2 = Bomb.Create(bytes); Assert.AreEqual(b1.CreatorId, b2.CreatorId); Assert.AreEqual(b1.Excuses.Count, b2.Excuses.Count); Assert.AreEqual(b1.Twine.Count, b2.Twine.Count); Assert.AreEqual(b1.BuiltOnTick.LogicalClock, b2.BuiltOnTick.LogicalClock); Assert.AreEqual(b1.BuiltOnTick.HashCode, b2.BuiltOnTick.HashCode); bytes.Clear(); b1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { b2 = Bomb.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); b1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { b2 = Bomb.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
public void TickTester_CheckEncodeDecode() { Tick tick1 = new Tick(10); tick1.LogicalClock = 100; ByteList bytes = new ByteList(); tick1.Encode(bytes); Tick tick2 = Tick.Create(bytes); Assert.AreEqual(10, tick1.ForAgentId); Assert.AreEqual(tick1.LogicalClock, tick2.LogicalClock); tick1.LogicalClock = 0; bytes = new ByteList(); tick1.Encode(bytes); tick2 = Tick.Create(bytes); Assert.AreEqual(tick1.LogicalClock, tick2.LogicalClock); tick1.LogicalClock = Int32.MaxValue; bytes = new ByteList(); tick1.Encode(bytes); tick2 = Tick.Create(bytes); Assert.AreEqual(tick1.ForAgentId, tick1.ForAgentId); Assert.AreEqual(tick1.LogicalClock, tick2.LogicalClock); bytes.Clear(); tick1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { tick2 = Tick.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); tick1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { tick2 = Tick.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
public void AckNak_CheckEncodeDecode() { Tick t1 = new Tick(); AckNak m1 = new AckNak(Reply.PossibleStatus.Success, 10, t1, "Test Message", "Test Note"); Assert.AreEqual(Reply.PossibleTypes.AckNak, m1.ReplyType); Assert.AreEqual(Reply.PossibleStatus.Success, m1.Status); Assert.AreEqual(10, m1.IntResult); Assert.AreSame(t1, m1.ObjResult); Assert.AreEqual("Test Message", m1.Message); Assert.AreEqual("Test Note", m1.Note); ByteList bytes = new ByteList(); m1.Encode(bytes); AckNak m2 = AckNak.Create(bytes); Assert.AreEqual(m1.Status, m2.Status); Assert.AreEqual(m1.IntResult, m2.IntResult); Assert.AreEqual(((Tick)m1.ObjResult).LogicalClock, ((Tick)m2.ObjResult).LogicalClock); Assert.AreEqual(m1.Message, m2.Message); Assert.AreEqual(m1.Note, m2.Note); bytes.Clear(); m1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { m2 = AckNak.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); m1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { m2 = AckNak.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
public void Reset() { Interlocked.Exchange(ref lengt, -1); Interlocked.Exchange(ref Vlent, 0); Interlocked.Exchange(ref current, 0); ByteList.Clear(); }
internal byte[] GetData() { try { byte[] data = ByteList.ToArray(); if (data.Length >= 4) { int length = BitConverter.ToInt32(data, 0); if (length == ByteList.Count) { Reset(); ByteList.Clear(); return(data); } else { return(null); } } else { return(null); } } catch { Reset(); ByteList.Clear(); return(null); } }
public void AgentList_CheckEncodeAndDecode() { AgentInfo info1 = new AgentInfo(10, AgentInfo.PossibleAgentType.ExcuseGenerator); AgentInfo info2 = new AgentInfo(11, AgentInfo.PossibleAgentType.WhiningSpinner); AgentInfo info3 = new AgentInfo(12, AgentInfo.PossibleAgentType.BrilliantStudent); AgentList list1 = new AgentList(); list1.Add(info1); list1.Add(info2); list1.Add(info3); ByteList bytes = new ByteList(); list1.Encode(bytes); AgentList list2 = AgentList.Create(bytes); Assert.AreEqual(3, list2.Count); Assert.AreEqual(10, list2[0].Id); Assert.AreEqual(11, list2[1].Id); Assert.AreEqual(12, list2[2].Id); bytes.Clear(); list1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { list2 = AgentList.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); list1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { list2 = AgentList.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
public void JoinGame_EncodingAndDecoding() { AgentInfo agentInfo = new AgentInfo(1001, AgentInfo.PossibleAgentType.BrilliantStudent) { ANumber = "A0001", FirstName = "Joe", LastName = "Jone" }; JoinGame jg1 = new JoinGame(10, agentInfo); Assert.AreEqual(10, jg1.GameId); Assert.AreSame(agentInfo, jg1.AgentInfo); ByteList bytes = new ByteList(); jg1.Encode(bytes); JoinGame jg2 = JoinGame.Create(bytes); Assert.AreEqual(jg1.GameId, jg2.GameId); bytes.Clear(); jg1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { jg2 = JoinGame.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); jg1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { jg2 = JoinGame.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
public void EndPoint_CheckEncodeAndDecode() { Common.EndPoint ep1 = new Common.EndPoint(3255420, 3004); Assert.AreEqual(3255420, ep1.Address); Assert.AreEqual(3004, ep1.Port); ByteList bytes = new ByteList(); ep1.Encode(bytes); Common.EndPoint ep2 = Common.EndPoint.Create(bytes); Assert.AreEqual(ep1.Address, ep2.Address); Assert.AreEqual(ep1.Port, ep2.Port); bytes.Clear(); ep1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { ep2 = Common.EndPoint.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); ep1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { ep2 = Common.EndPoint.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
internal void InserByteArray(byte[] data) { if (SecondIn) { ByteList.Clear(); SecondIn = false; } if (FirstIn) { SecondIn = true; FirstIn = false; } ByteList.AddRange(data); }
public byte[] GetData(int ml) { if (ByteList.Count < ml) { return(null); } int res = 0; for (int i = 0; i < ml; i++) { int temp = (( int )ByteList[Current + i]) & 0xff; temp <<= i * 8; res = res + temp; } if (res <= 0) { Reset(); ByteList.Clear(); return(null); } if (res > (ByteList.Count - Current)) { return(null); } byte[] data = new byte[res]; ByteList.CopyTo(Current, data, 0, data.Length); Current += res; if (Current == ByteList.Count) { Reset(); ByteList.Clear(); } return(data); }
public void PlayingFieldLayout_CheckEncodeAndDecode() { PlayingFieldLayout pfl1 = new PlayingFieldLayout(20, 30); Assert.AreEqual(20, pfl1.Width); Assert.AreEqual(30, pfl1.Height); Assert.IsNotNull(pfl1.SidewalkSquares); List <FieldLocation> flList = new List <FieldLocation> { new FieldLocation(1, 1), new FieldLocation(2, 1) }; pfl1.SidewalkSquares = flList; Assert.AreSame(flList, pfl1.SidewalkSquares); ByteList bytes = new ByteList(); pfl1.Encode(bytes); PlayingFieldLayout pfl2 = PlayingFieldLayout.Create(bytes); Assert.AreEqual(pfl1.Width, pfl2.Width); Assert.AreEqual(pfl1.Height, pfl2.Height); Assert.IsNotNull(pfl2.SidewalkSquares); Assert.AreEqual(pfl1.SidewalkSquares.Count, pfl1.SidewalkSquares.Count); bytes.Clear(); pfl1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { pfl2 = PlayingFieldLayout.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); pfl1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { pfl2 = PlayingFieldLayout.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } pfl1 = new PlayingFieldLayout(100, 100); SetUpSidewalks(pfl1); Assert.AreEqual(100, pfl1.Width); Assert.AreEqual(100, pfl1.Height); Assert.IsNotNull(pfl1.SidewalkSquares); bytes = new ByteList(); pfl1.Encode(bytes); pfl2 = PlayingFieldLayout.Create(bytes); Assert.AreEqual(pfl1.Width, pfl2.Width); Assert.AreEqual(pfl1.Height, pfl2.Height); Assert.IsNotNull(pfl2.SidewalkSquares); Assert.AreEqual(pfl1.SidewalkSquares.Count, pfl1.SidewalkSquares.Count); pfl1 = new PlayingFieldLayout(200, 300); SetUpSidewalks(pfl1); Assert.AreEqual(200, pfl1.Width); Assert.AreEqual(300, pfl1.Height); Assert.IsNotNull(pfl1.SidewalkSquares); bytes = new ByteList(); pfl1.Encode(bytes); pfl2 = PlayingFieldLayout.Create(bytes); Assert.AreEqual(pfl1.Width, pfl2.Width); Assert.AreEqual(pfl1.Height, pfl2.Height); Assert.IsNotNull(pfl2.SidewalkSquares); Assert.AreEqual(pfl1.SidewalkSquares.Count, pfl1.SidewalkSquares.Count); }
public void GameConfiguration_CheckEncodeAndDecode() { GameConfiguration gc1 = new GameConfiguration(); gc1.PlayingFieldWidth = 50; gc1.PlayingFieldHeight = 51; gc1.BrilliantStudentRegistrationMin = 10; gc1.BrilliantStudentRegistrationMax = 11; gc1.BrilliantStudentInitialStrength = 2.1F; gc1.BrilliantStudentBaseSpeed = 2.2F; gc1.BrilliantStudentSidewalkSpeedMultiplier = 2.3F; gc1.BrilliantStudentDeathToZombieDelay = 2.4F; gc1.ExcuseGeneratorRegistrationMin = 12; gc1.ExcuseGeneratorRegistrationMax = 13; gc1.ExcuseGeneratorInitialStrength = 2.5F; gc1.NumberOfTicksRequiredToBuildTwine = 3; gc1.WhiningSpinnerRegistrationMin = 14; gc1.WhiningSpinnerRegistrationMax = 15; gc1.WhiningSpinnerInitialStrength = 2.8F; gc1.NumberOfTicksRequiredToBuildTwine = 2; gc1.ZombieInitialStrengthMin = 16; gc1.ZombieInitialStrengthMax = 17; gc1.ZombieInitialSpeedMax = 3.1F; gc1.ZombieInitialSpeedMin = 3.2F; gc1.ZombieSidewalkSpeedMultiplier = 3.3F; gc1.ZombieCreationRate = 3.4F; gc1.ZombieCreationAcceleration = 3.5F; gc1.ZombieEatingRate = 3.6F; gc1.ZombieStrengthIncreaseForEatingStudent = 3.7F; gc1.ZombieStrengthIncreaseForExcuseGenerator = 3.8F; gc1.ZombieStrengthIncreaseForWhiningSpinner = 3.9F; gc1.MaxEatingDistance = 0.5F; gc1.MaxEatingDistance = 4.5F; gc1.RefereeRegistrationMin = 22; gc1.RefereeRegistrationMax = 23; gc1.BombExcuseDamage = 18; gc1.BombTwinePerSquareOfDistance = 4.0F; gc1.BombDamageDiffusionFactor = 4.1F; gc1.TickLifetime = 19; gc1.TicksToStrengthRatio = 4.2F; ByteList bytes = new ByteList(); gc1.Encode(bytes); GameConfiguration gc2 = GameConfiguration.Create(bytes); Assert.AreEqual(gc1.PlayingFieldWidth, gc2.PlayingFieldWidth); Assert.AreEqual(gc1.PlayingFieldHeight, gc2.PlayingFieldHeight); Assert.AreEqual(gc1.BrilliantStudentRegistrationMin, gc2.BrilliantStudentRegistrationMin); Assert.AreEqual(gc1.BrilliantStudentRegistrationMax, gc2.BrilliantStudentRegistrationMax); Assert.AreEqual(gc1.BrilliantStudentInitialStrength, gc2.BrilliantStudentInitialStrength); Assert.AreEqual(gc1.BrilliantStudentBaseSpeed, gc2.BrilliantStudentBaseSpeed); Assert.AreEqual(gc1.BrilliantStudentSidewalkSpeedMultiplier, gc2.BrilliantStudentSidewalkSpeedMultiplier); Assert.AreEqual(gc1.BrilliantStudentDeathToZombieDelay, gc2.BrilliantStudentDeathToZombieDelay); Assert.AreEqual(gc1.ExcuseGeneratorRegistrationMin, gc2.ExcuseGeneratorRegistrationMin); Assert.AreEqual(gc1.ExcuseGeneratorRegistrationMax, gc2.ExcuseGeneratorRegistrationMax); Assert.AreEqual(gc1.ExcuseGeneratorInitialStrength, gc2.ExcuseGeneratorInitialStrength); Assert.AreEqual(gc1.NumberOfTicksRequiredToBuildAnExcuse, gc2.NumberOfTicksRequiredToBuildAnExcuse); Assert.AreEqual(gc1.WhiningSpinnerRegistrationMin, gc2.WhiningSpinnerRegistrationMin); Assert.AreEqual(gc1.WhiningSpinnerRegistrationMax, gc2.WhiningSpinnerRegistrationMax); Assert.AreEqual(gc1.WhiningSpinnerInitialStrength, gc2.WhiningSpinnerInitialStrength); Assert.AreEqual(gc1.NumberOfTicksRequiredToBuildTwine, gc2.NumberOfTicksRequiredToBuildTwine); Assert.AreEqual(gc1.ZombieInitialStrengthMin, gc2.ZombieInitialStrengthMin); Assert.AreEqual(gc1.ZombieInitialStrengthMax, gc2.ZombieInitialStrengthMax); Assert.AreEqual(gc1.ZombieInitialSpeedMax, gc2.ZombieInitialSpeedMax); Assert.AreEqual(gc1.ZombieInitialSpeedMin, gc2.ZombieInitialSpeedMin); Assert.AreEqual(gc1.ZombieSidewalkSpeedMultiplier, gc2.ZombieSidewalkSpeedMultiplier); Assert.AreEqual(gc1.ZombieCreationRate, gc2.ZombieCreationRate); Assert.AreEqual(gc1.ZombieCreationAcceleration, gc2.ZombieCreationAcceleration); Assert.AreEqual(gc1.ZombieEatingRate, gc2.ZombieEatingRate); Assert.AreEqual(gc1.ZombieStrengthIncreaseForEatingStudent, gc2.ZombieStrengthIncreaseForEatingStudent); Assert.AreEqual(gc1.ZombieStrengthIncreaseForExcuseGenerator, gc2.ZombieStrengthIncreaseForExcuseGenerator); Assert.AreEqual(gc1.ZombieStrengthIncreaseForWhiningSpinner, gc2.ZombieStrengthIncreaseForWhiningSpinner); Assert.AreEqual(gc1.MinEatingDistance, gc2.MinEatingDistance); Assert.AreEqual(gc1.MaxEatingDistance, gc2.MaxEatingDistance); Assert.AreEqual(gc1.RefereeRegistrationMin, gc2.RefereeRegistrationMin); Assert.AreEqual(gc1.RefereeRegistrationMax, gc2.RefereeRegistrationMax); Assert.AreEqual(gc1.BombExcuseDamage, gc2.BombExcuseDamage); Assert.AreEqual(gc1.BombTwinePerSquareOfDistance, gc2.BombTwinePerSquareOfDistance); Assert.AreEqual(gc1.BombDamageDiffusionFactor, gc2.BombDamageDiffusionFactor); Assert.AreEqual(gc1.TickLifetime, gc2.TickLifetime); Assert.AreEqual(gc1.TicksToStrengthRatio, gc2.TicksToStrengthRatio); bytes.Clear(); gc1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { gc2 = GameConfiguration.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); gc1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { gc2 = GameConfiguration.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
public void Clecr() { ByteList.Clear(); }
public void ByteList_WriteAndAddMethods() { ByteList myBytes = new ByteList(); // Case: Write out a boolean of True myBytes.Clear(); myBytes.Add(true); Assert.IsNotNull(myBytes); Assert.AreEqual(1, myBytes.Length); Assert.AreEqual(1, myBytes[0]); // Case: Write out a boolean of False myBytes.Clear(); myBytes.Add(false); Assert.IsNotNull(myBytes); Assert.AreEqual(1, myBytes.Length); Assert.AreEqual(0, myBytes[0]); // Case: Write out a Byte myBytes.Clear(); myBytes.Add((byte)4); Assert.IsNotNull(myBytes); Assert.AreEqual(1, myBytes.Length); Assert.AreEqual((byte)4, myBytes[0]); // Case: Write out a Char myBytes.Clear(); myBytes.Add('A'); Assert.IsNotNull(myBytes); Assert.AreEqual(2, myBytes.Length); Assert.AreEqual(65, myBytes[0]); Assert.AreEqual(0, myBytes[1]); // Case: Write out a Int16 myBytes.Clear(); myBytes.Add((Int16)7); Assert.IsNotNull(myBytes); Assert.AreEqual(2, myBytes.Length); Assert.AreEqual(0, myBytes[0]); Assert.AreEqual(7, myBytes[1]); // Case: Write out a Int16 myBytes.Clear(); myBytes.Add(Int16.MaxValue); Assert.IsNotNull(myBytes); Assert.AreEqual(2, myBytes.Length); Assert.AreEqual(127, myBytes[0]); Assert.AreEqual(255, myBytes[1]); // Case: Write out a Int32 myBytes.Clear(); myBytes.Add((Int32)7); Assert.IsNotNull(myBytes); Assert.AreEqual(4, myBytes.Length); for (int i = 0; i < 3; i++) { Assert.AreEqual(0, myBytes[i]); } Assert.AreEqual(7, myBytes[3]); // Case: Write out a Int32 myBytes.Clear(); myBytes.Add(Int32.MaxValue); Assert.IsNotNull(myBytes); Assert.AreEqual(4, myBytes.Length); Assert.AreEqual(127, myBytes[0]); for (int i = 1; i < 4; i++) { Assert.AreEqual(255, myBytes[i]); } // Case: Write out a Int64 myBytes.Clear(); myBytes.Add((Int64)7); Assert.IsNotNull(myBytes); Assert.AreEqual(8, myBytes.Length); for (int i = 0; i < 7; i++) { Assert.AreEqual(0, myBytes[i]); } Assert.AreEqual(7, myBytes[7]); // Case 7: Write out a Int64 myBytes.Clear(); myBytes.Add(Int64.MaxValue); Assert.IsNotNull(myBytes); Assert.AreEqual(8, myBytes.Length); Assert.AreEqual(127, myBytes[0]); for (int i = 1; i < 8; i++) { Assert.AreEqual(255, myBytes[i]); } // Case: Write out a Single Precision Real myBytes.Clear(); myBytes.Add((float)7.7); Assert.IsNotNull(myBytes); Assert.AreEqual(4, myBytes.Length); // Case: Write out a Double Precision Real myBytes.Clear(); myBytes.Add((float)7.7); Assert.IsNotNull(myBytes); Assert.AreEqual(4, myBytes.Length); // Case: Write out a Byte Array myBytes.Clear(); myBytes.Add(new byte[] { 1, 2, 3, 4, 5, 6 }); Assert.AreEqual(6, myBytes.Length); for (int i = 0; i < 6; i++) { Assert.AreEqual(i + 1, myBytes[i]); } // Case: Write out a string myBytes.Clear(); myBytes.Add((string)null); Assert.AreEqual(2, myBytes.Length); Assert.AreEqual(0, myBytes[0]); Assert.AreEqual(0, myBytes[1]); // Case: Write out a string myBytes.Clear(); myBytes.Add(string.Empty); Assert.AreEqual(2, myBytes.Length); Assert.AreEqual(0, myBytes[0]); Assert.AreEqual(0, myBytes[1]); // Case 11: Write out a string myBytes = new ByteList("abc"); Assert.AreEqual(2 + 2 * 3, myBytes.Length); Assert.AreEqual(0, myBytes[0]); Assert.AreEqual(2 * 3, myBytes[1]); // Note AddObjects and AddObject methods were tested with constructors }