-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasePackTests.cs
More file actions
162 lines (132 loc) · 4.57 KB
/
BasePackTests.cs
File metadata and controls
162 lines (132 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace NETLIB.Tests
{
[TestClass]
public class BasePackTests
{
[TestMethod]
public void WriteTestAreBuffersEqual()
{
// Arrange
BasePack basePack = new BasePack();
byte[] buff = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
// Act
basePack.Write(buff, 0, buff.Length);
// Assert - note that BasePack's buffer[0] is Pack's header, so written buffer is shifted by 1 to the right
byte[] buffWritten = basePack.Buffer;
for (int i = 0; i < buff.Length; i++)
Assert.AreEqual(buff[i], buffWritten[i + 1]);
}
[TestMethod]
public void ReadTestAreBuffersEqual()
{
// Arrange
BasePack basePack = new BasePack();
byte[] buff = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
basePack.Write(buff, 0, buff.Length);
// Act
byte[] buffRead = new byte[buff.Length];
basePack.Read(buffRead, 0, buffRead.Length);
// Assert
CollectionAssert.AreEqual(buff, buffRead);
}
[TestMethod]
public void PutStringTestAndGetStringTest()
{
// Arrange
string stringPut = "Test string.";
BasePack basePack = new BasePack();
// Act
basePack.PutString(stringPut);
string stringGet = basePack.GetString();
// Assert
Assert.AreEqual(stringPut, stringGet);
}
[TestMethod]
public void PutIntAtTheBeginningAndGetIntFromBeginningTest()
{
// Arrange
int intPut = 123;
BasePack basePack = new BasePack();
// Act
basePack.PutInt(intPut);
int intGet = basePack.GetInt();
// Assert
Assert.AreEqual(intPut, intGet);
}
[TestMethod]
public void PutDoubleAtTheBeginningAndGetDoubleFromTheBeginningTest()
{
// Arrange
double doublePut = 123.4;
BasePack basePack = new BasePack();
// Act
basePack.PutDouble(doublePut);
double doubleGet = basePack.GetDouble();
// Assert
Assert.AreEqual(doublePut, doubleGet);
}
[TestMethod]
public void PutFloatAtTheBeginningAndGetFloatFromTheBeginningTest()
{
// Arrange
float floatPut = 123.4f;
BasePack basePack = new BasePack();
// Act
basePack.PutFloat(floatPut);
float floatGet = basePack.GetFloat();
// Assert
Assert.AreEqual(floatPut, floatGet);
}
[TestMethod]
public void PutCharAtTheBeginningAndGetCharFromTheBeginningTest()
{
// Arrange
char charPut = 'a';
BasePack basePack = new BasePack();
// Act
basePack.PutChar(charPut);
char charGet = basePack.GetChar();
// Assert
Assert.AreEqual(charPut, charGet);
}
[TestMethod]
public void PutByteAtTheBeginningAndGetByteFromTheBeginningTest()
{
// Arrange
byte bytePut = 7;
BasePack basePack = new BasePack();
// Act
basePack.PutByte(bytePut);
byte byteGet = basePack.GetByte();
// Assert
Assert.AreEqual(bytePut, byteGet);
}
[TestMethod]
public void PutBoolAtTheBeginningAndGetBoolFromTheBeginningTest()
{
// Arrange
bool boolPut = true;
BasePack basePack = new BasePack();
// Act
basePack.PutBool(boolPut);
bool boolGet = basePack.GetBool();
// Assert
Assert.AreEqual(boolPut, boolGet);
}
[TestMethod]
public void ConversionFromByteArrayToBasePackTest()
{
// Arrange
BasePack basePack = new BasePack();
byte[] byteArray = new byte[BasePack.packSize];
for (int i = 0; i < byteArray.Length; i++)
byteArray[i] = (byte)(i % 256);
// Act
basePack = byteArray;
// Assert
for (int i = 0; i < byteArray.Length; i++)
Assert.AreEqual(byteArray[i], basePack.Buffer[i]);
}
}
}