typestest.cs
来自「SRI international 发布的OAA框架软件」· CS 代码 · 共 492 行 · 第 1/2 页
CS
492 行
for (int i = 0; i < testData.Length; i++) {
testData[i] = new byte[1000];
}
for (int i = 0; i < testData.Length; i++) {
random.NextBytes(testData[i]);
}
byte[][] copyData = iRemoteTypes.identity(testData);
assert(copyData.Length == testData.Length);
for (int i = 0; i < testData.Length; i++) {
assert(testData[i].Length == copyData[i].Length);
for (int j = 0; j < testData[i].Length; j++) {
assert(testData[i][j] == copyData[i][j]);
}
}
}
[Test] public void test2DChar() {
TestTypesInterface iRemoteTypes = UnitTestFactory.getFactory().newTestTypesInterface();
Random random = new Random();
char[][] testData = new char[100][];
for (int i = 0; i < testData.Length; i++) {
testData[i] = new char[100];
}
for (int i = 0; i < testData.Length; i++) {
for (int j = 0; j < testData[i].Length; j++) {
testData[i][j] = (char)random.Next(char.MinValue, char.MaxValue);
}
}
char[][] copyData = iRemoteTypes.identity(testData);
assert(copyData.Length == testData.Length);
for (int i = 0; i < testData.Length; i++) {
assert(testData[i].Length == copyData[i].Length);
for (int j = 0; j < testData[i].Length; j++) {
assert(testData[i][j] == copyData[i][j]);
}
}
}
[Test] public void test2DShort() {
TestTypesInterface iRemoteTypes = UnitTestFactory.getFactory().newTestTypesInterface();
Random random = new Random();
short[][] testData = new short[100][];
for (int i = 0; i < testData.Length; i++) {
testData[i] = new short[100];
}
for (int i = 0; i < testData.Length; i++) {
for (int j = 0; j < testData[i].Length; j++) {
testData[i][j] = (short)random.Next(short.MinValue, short.MaxValue);
}
}
short[][] copyData = iRemoteTypes.identity(testData);
assert(copyData.Length == testData.Length);
for (int i = 0; i < testData.Length; i++) {
assert(testData[i].Length == copyData[i].Length);
for (int j = 0; j < testData[i].Length; j++) {
assert(testData[i][j] == copyData[i][j]);
}
}
}
[Test] public void test2DInt() {
TestTypesInterface iRemoteTypes = UnitTestFactory.getFactory().newTestTypesInterface();
Random random = new Random();
int[][] testData = new int[100][];
for (int i = 0; i < testData.Length; i++) {
testData[i] = new int[100];
}
for (int i = 0; i < testData.Length; i++) {
for (int j = 0; j < testData[i].Length; j++) {
testData[i][j] = random.Next();
}
}
int[][] copyData = iRemoteTypes.identity(testData);
assert(copyData.Length == testData.Length);
for (int i = 0; i < testData.Length; i++) {
assert(testData[i].Length == copyData[i].Length);
for (int j = 0; j < testData[i].Length; j++) {
assert(testData[i][j] == copyData[i][j]);
}
}
}
[Test] public void test2DLong() {
TestTypesInterface iRemoteTypes = UnitTestFactory.getFactory().newTestTypesInterface();
Random random = new Random();
long[][] testData = new long[100][];
for (int i = 0; i < testData.Length; i++) {
testData[i] = new long[100];
}
for (int i = 0; i < testData.Length; i++) {
for (int j = 0; j < testData[i].Length; j++) {
testData[i][j] = random.Next();
}
}
long[][] copyData = iRemoteTypes.identity(testData);
assert(copyData.Length == testData.Length);
for (int i = 0; i < testData.Length; i++) {
assert(testData[i].Length == copyData[i].Length);
for (int j = 0; j < testData[i].Length; j++) {
assert(testData[i][j] == copyData[i][j]);
}
}
}
[Test] public void test2DFloat() {
TestTypesInterface iRemoteTypes = UnitTestFactory.getFactory().newTestTypesInterface();
Random random = new Random();
float[][] testData = new float[100][];
for (int i = 0; i < testData.Length; i++) {
testData[i] = new float[100];
}
for (int i = 0; i < testData.Length; i++) {
for (int j = 0; j < testData[i].Length; j++) {
testData[i][j] = (float)(float.MinValue + (float.MaxValue-float.MinValue)*random.NextDouble());
}
}
float[][] copyData = iRemoteTypes.identity(testData);
assert(copyData.Length == testData.Length);
for (int i = 0; i < testData.Length; i++) {
assert(testData[i].Length == copyData[i].Length);
for (int j = 0; j < testData[i].Length; j++) {
assert(testData[i][j] == copyData[i][j]);
}
}
}
[Test] public void test2DDouble() {
TestTypesInterface iRemoteTypes = UnitTestFactory.getFactory().newTestTypesInterface();
Random random = new Random();
double[][] testData = new double[100][];
for (int i = 0; i < testData.Length; i++) {
testData[i] = new double[100];
}
for (int i = 0; i < testData.Length; i++) {
for (int j = 0; j < testData[i].Length; j++) {
testData[i][j] = (double.MinValue + (double.MaxValue-double.MinValue)*random.NextDouble());
}
}
double[][] copyData = iRemoteTypes.identity(testData);
assert(copyData.Length == testData.Length);
for (int i = 0; i < testData.Length; i++) {
assert(testData[i].Length == copyData[i].Length);
for (int j = 0; j < testData[i].Length; j++) {
assert(testData[i][j] == copyData[i][j]);
}
}
}
[Test] public void testString1() {
TestTypesInterface iRemoteTypes = UnitTestFactory.getFactory().newTestTypesInterface();
assertStringIdentity(iRemoteTypes, "");
}
[Test] public void testString2() {
TestTypesInterface iRemoteTypes = UnitTestFactory.getFactory().newTestTypesInterface();
assertStringIdentity(iRemoteTypes, "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}
[Test] public void testString3() {
TestTypesInterface iRemoteTypes = UnitTestFactory.getFactory().newTestTypesInterface();
assertStringIdentity(iRemoteTypes, "!@#$%^&*()_+<>:\"?{}|~[];',./\\-=`\n\t\0");
}
[Test] public void test1DString() {
TestTypesInterface iRemoteTypes = UnitTestFactory.getFactory().newTestTypesInterface();
Random random = new Random();
String[] testData = new String[500];
for (int i = 0; i < testData.Length; i++) {
char[] randChars = new char[100];
for (int j = 0; j < randChars.Length; j++) {
randChars[j] = (char)random.Next(char.MinValue, char.MaxValue);
}
testData[i] = new String(randChars);
}
String[] copyData = iRemoteTypes.identity(testData);
assert(copyData.Length == testData.Length);
for (int i = 0; i < testData.Length; i++) {
assert(testData[i].Equals(copyData[i]));
}
}
[Test] public void test2DString() {
TestTypesInterface iRemoteTypes = UnitTestFactory.getFactory().newTestTypesInterface();
Random random = new Random();
String[][] testData = new String[50][];
for (int i = 0; i < testData.Length; i++) {
testData[i] = new String[50];
}
for (int i = 0; i < testData.Length; i++) {
for (int s = 0; s < testData[i].Length; s++) {
char[] randChars = new char[100];
for (int j = 0; j < randChars.Length; j++) {
randChars[j] = (char)random.Next(char.MinValue, char.MaxValue);
}
testData[i][s] = new String(randChars);
}
}
String[][] copyData = iRemoteTypes.identity(testData);
assert(copyData.Length == testData.Length);
for (int i = 0; i < testData.Length; i++) {
for (int j = 0; j < testData[i].Length; j++) {
assert(testData[i][j].Equals(copyData[i][j]));
}
}
}
void assert(bool condition) {
if (!condition) {
throw new Exception("Exception failure");
}
}
public void assertByteIdentity(TestTypesInterface iRemoteTypes, byte i) {
assert(iRemoteTypes.identity(i) == i);
}
public void assertShortIdentity(TestTypesInterface iRemoteTypes, short i) {
assert(iRemoteTypes.identity(i) == i);
}
public void assertIntIdentity(TestTypesInterface iRemoteTypes, int i) {
assert(iRemoteTypes.identity(i) == i);
}
public void assertCharIdentity(TestTypesInterface iRemoteTypes, char i) {
assert(iRemoteTypes.identity(i) == i);
}
public void assertLongIdentity(TestTypesInterface iRemoteTypes, long i) {
assert(iRemoteTypes.identity(i) == i);
}
public void assertFloatIdentity(TestTypesInterface iRemoteTypes, float i) {
assert(iRemoteTypes.identity(i) == i);
}
public void assertDoubleIdentity(TestTypesInterface iRemoteTypes, double i) {
assert(iRemoteTypes.identity(i) == i);
}
public void assertStringIdentity(TestTypesInterface iRemoteTypes, String i) {
assert(iRemoteTypes.identity(i).Equals(i));
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?