Find the algorithm for data that is not in the original data

Source: Internet
Author: User
Tags assert count sort
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]);
}
}
}
}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.