Data | algorithms
Use C # AH NUnit to do development testing tools
Using System;
Using System.Collections;
Using Nunit.framework;
Namespace Cn.lovetyping.UnitTest
{
<summary>
A summary description of the Sort.
</summary>
///
[Testfixture]
public class Sort
{
<summary>
The orignal data which is used to compare with the new
Data. The If there is some data exist in the NewData but no in orignal data.
Add it to the result.
</summary>
Input:
<param name= "orignal" ></param>
<param name= "NewData" ></param>
Output
<returns>arrayList</returns>
Public ArrayList sortdata (string[] orignal,string[] newdata)
{
ArrayList result = new ArrayList ();
int oindex=0,nindex=0;
According to the condition
while (oindex<orignal. Length && nindex<newdata.length)
{
if (Newdata[nindex). CompareTo (Orignal[oindex]) <0)
{
Result. ADD (Newdata[nindex]);
nindex++;
}
else if (newdata[nindex). CompareTo (Orignal[oindex]) ==0)
{
oindex++;nindex++;
}
else if (newdata[nindex). CompareTo (Orignal[oindex]) > 0)
{
oindex++;
Continue
}
}
If the
if (nindex = = Newdata.length | | oindex< orignal. Length)
{
return result;
}
else if (Nindex < newdata.length)
{
while (nindex< newdata.length)
{
Result. ADD (newdata[nindex++]);
}
}
return result;
}
[Test]
public void Testsort ()
{
string[] Code1 = new string[]{"0", "4", "6", "9"};
string[] Code2 = new string[]{"1", "3", "6", "7", "9", "12"};
ArrayList result = This.sortdata (CODE1,CODE2);
Assert.istrue (result. Count = = 4);
for (int i=0;i<result. count;i++)
{
Console.WriteLine (Result[i]);
}
Console.WriteLine ("---------------Another data------------");
Code1 = new string[]{"0", "4", "6", "9"};
Code2 = new string[]{"1", "3", "6"};
result = This.sortdata (CODE1,CODE2);
Assert.istrue (result. Count = = 2);
for (int i=0;i<result. count;i++)
{
Console.WriteLine (Result[i]);
}
console.writeline ("---------------Another data------------");
code1 = new string[]{"0", "4", "6", "9"};
code2 = new string[]{"1", "3", "7"};
result = This.sortdata (Code1,code2);
assert.istrue (result. Count = = 3);
for (int i=0;i<result. count;i++)
{
console.writeline (Result[i]);
.}
Console.WriteLine ("---------------Another data------------");
Code1 = new string[]{"0", "11", "13", "3", "3", "9"};
Code2 = new string[]{"1", "11", "15", "16", "19", "3", "7"};
result = This.sortdata (CODE1,CODE2);
Assert.istrue (result. Count = = 5);
for (int i=0;i<result. count;i++)
{
Console.WriteLine (Result[i]);
}
}
}
}