Example #1
0
    public static void TestEquals()
    {
        StringBuilder sb1 = new StringBuilder("Hello");
        StringBuilder sb2 = new StringBuilder("HelloX");

        bool b;
        b = sb1.Equals(sb1);
        Assert.True(b);
        b = sb1.Equals(sb2);
        Assert.False(b);
    }
 public virtual bool runTest()
   {
   Console.Error.WriteLine( "Co1454ctor_Strings.  runTest started." );
   int iCountErrors = 0;
   StringBuilder sbl2 = null;
   String str2b = null;
   String str2c = null;
   String str2d = null;
   String str2e = null;
   String str2_All = null;
   String str2_Some = null;
   String str9 = null;
   IntlStrings intl = new IntlStrings();
   str9 = intl.GetString(6, true, true);
   str2_All = str9;
   if ( ! str9.Equals( str2_All ) )
     {
     iCountErrors += 1;
     Console.Error.WriteLine(  "POINTTOBREAK:  Error E_6555im! (Co1454ctor_Strings)"  );
     }
   str2b = "Bb";
   str2c = "Cc";
   str2d = "Dd";
   str2e = "Ee";
   str2_All = "BbCcDdEe";
   str9 =  "BbCcDdEe" ;
   if ( ! str9.Equals( str2_All ) )
     {
     iCountErrors += 1;
     Console.Error.WriteLine(  "POINTTOBREAK:  Error E_638im! (Co1454ctor_Strings)"  );
     }
   sbl2 = new StringBuilder( "BbCcDd" );
   sbl2.Append( str2e );
   str9 = sbl2.ToString();
   if ( ! str9.Equals( str2_All ) )
     {
     iCountErrors += 1;
     Console.Error.WriteLine(  "POINTTOBREAK:  Error E_517cw! (Co1454ctor_Strings)"  );
     }
   str9 =  "Bb" + "Cc" +"Dd" ;
   str2_Some = "BbCcDd";
   if ( ! str9.Equals( str2_Some ) )
     {
     iCountErrors += 1;
     Console.Error.WriteLine(  "POINTTOBREAK:  Error E_460is! (Co1454ctor_Strings)"  );
     }
   str9 =  str2b + str2c + str2d ;
   str9 = new StringBuilder( str9 ).Append( str2e ).ToString();
   if ( ! str9.Equals( str2_All ) )
     {
     iCountErrors += 1;
     Console.Error.WriteLine(  "POINTTOBREAK:  Error E_253xi! (Co1454ctor_Strings)"  );
     }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
Example #3
0
    public static void Main()
    {
        int count = int.Parse(Console.ReadLine());
        int[] numbers = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
        bool haveMatch = false;

        StringBuilder left = new StringBuilder();
        StringBuilder right = new StringBuilder();

        for (int a = 0; a < count; a++)
        {
            for (int b = 0; b < count; b++)
            {
                for (int c = 0; c < count; c++)
                {
                    for (int d = 0; d < count; d++)
                    {
                        if (a != b && a != c && a != d && b != c && b != d && c != d)
                        {
                            left.Append(numbers[a]);
                            left.Append(numbers[b]);
                            right.Append(numbers[c]);
                            right.Append(numbers[d]);

                            if (left.Equals(right))
                            {
                                haveMatch = true;
                                Console.WriteLine("{0}|{1}=={2}|{3}", numbers[a], numbers[b], numbers[c], numbers[d]);
                            }

                            left.Clear();
                            right.Clear();
                        }
                    }
                }
            }
        }

        if (!haveMatch)
        {
            Console.WriteLine("No");
        }
    }
    static StringBuilder Evaluate(StringBuilder buffer, string tag = "")
    {
        // the method walks through "buffer" character by character
        // and prints any of them to the output in accordance to the type of surrounding pair of tags
        // if a pair of tags are found inside the buffer
        // the method calls itself with the text inside those tags (using recursion)
        // then the result is "replaced" within the buffer.

        StringBuilder result = new StringBuilder();
        if (tag == "del") return result; // if surroundng tag is del - returns empty result
        bool isTag = false; // indicates if we are reading the tag name
        bool inTag = false; // indicates if we are reading the text between pair of tags
        StringBuilder anyTag = new StringBuilder(); // holds the tag name of any found tag in the text
        StringBuilder openTag = new StringBuilder(); // holds the tag name of the relevant opening tag
        StringBuilder toEvaluate = new StringBuilder(); // holds the text between a pair of tags
        int nestedEqualTags = 0; // counts how many equal opening tags are found (the same number of closing tags we must have to make a pair)

        for (int i = 0; i < buffer.Length; i++)
        {
            char symbol = buffer[i];
            if (!isTag && symbol == '<') // tag start
            {
                isTag = true;
                continue;
            }

            if (isTag && symbol == '>') // tag end
            {
                isTag = false;
                if (openTag.Length == 0) // we don't have any opening tags up to the moment
                {
                    openTag.Append(anyTag);
                    inTag = true;
                    anyTag.Clear();
                }
                else
                {
                    if (openTag.Equals(anyTag)) nestedEqualTags++; // a new equal opening tag has been found - counts it
                    if (anyTag[0] == '/' && openTag.ToString() == anyTag.ToString(1, anyTag.Length - 1) && nestedEqualTags == 0)
                    // the closing tag that makes pair with the opening tag has been found
                    {
                        inTag = false;
                        // we already have a pair of tags inside the buffer - evaluates it
                        toEvaluate = Evaluate(toEvaluate, openTag.ToString());
                        // and then saves the result into buffer but after current position
                        if (i == buffer.Length - 1) // if end of buffer has been found
                        {
                            buffer.Append(toEvaluate); // appends it to the end of buffer
                        }
                        else
                        {
                            buffer.Insert(i+1, toEvaluate); // otherwise iserts it
                        }
                        anyTag.Clear();
                        openTag.Clear();
                        toEvaluate.Clear(); // clears all tag holders
                    }
                    else // we don't have a pair of tags or the pair is not the most outer one
                    {
                        // if we have more than one equal opening tags - counts the inner pair of them
                        if (anyTag[0] == '/' && openTag.ToString() == anyTag.ToString(1, anyTag.Length - 1)) nestedEqualTags--;
                        // since this is not the most outer tag puts it to the evaluation buffer
                        toEvaluate.Append("<" + anyTag + ">");
                        anyTag.Clear(); // clears the tag appended already
                    }
                }
                continue; // goes to the next buffer position
            }

            if (!isTag && !inTag) // standard output
            {
                switch (tag) // do the job of the corresponding tag
                {
                    case "upper":
                        result.Append(char.ToUpper(symbol));
                        break;
                    case "lower":
                        result.Append(char.ToLower(symbol));
                        break;
                    case "toggle":
                        if (Char.IsUpper(symbol)) result.Append(char.ToLower(symbol)); // toggles the case of the character
                        else result.Append(char.ToUpper(symbol));
                        break;
                    case "rev":
                        result.Insert(0, symbol); // text reversing is implemented through insert at the current buffer begining
                        break;
                    default:
                        result.Append(symbol); // normal text is just appended to the end of the current buffer
                        break;
                }
            }
            else if (isTag) //we are reading tag name
            {
                anyTag.Append(symbol);
            }
            else // we are in nested tag - just append to the evaluation buffer for further processing
            {
                toEvaluate.Append(symbol);
            }

        }

        return result;
    }
Example #5
0
    public static int Main(string[] args)
    {
        string strManaged = "Managed";
        string strRet = "a";

        StringBuilder strBRet = new StringBuilder("a", 1);
        string strNative = " Native";
        StringBuilder strBNative = new StringBuilder(" Native", 7);

        Console.WriteLine("[Calling PInvokeDef.Marshal_InOut]");
        //since the out attributes doesnt work for string, so i dont check the out value.
        string strPara2 = new string(strManaged.ToCharArray());
        string strRet2 = PInvokeDef.Marshal_InOut(strPara2);
        if (!strRet2.Equals(strRet))
        {
            ReportFailure("Method PInvokeDef.Marshal_InOut[Managed Side],The Return string is wrong", strRet, strRet2);
        }

        //TestMethod3
        Console.WriteLine("[Calling PInvokeDef.Marshal_Out]");
        string strPara3 = strManaged;
        string strRet3 = PInvokeDef.Marshal_Out(strPara3);
        if (!strRet.Equals(strRet3))
        {
            ReportFailure("Method PInvokeDef.Marshal_Out[Managed Side],The Return string is wrong", strRet, strRet3);
        }
        if (!strManaged.Equals(strPara3))
        {
            ReportFailure("Method PInvokeDef.Marshal_Out[Managed Side],The Parameter string is Changed", strManaged, strPara3);
        }
        
        //TestMethod5
        Console.WriteLine("[Calling PInvokeDef.MarshalPointer_InOut]");
        string strPara5 = strManaged;
        string strRet5 = PInvokeDef.MarshalPointer_InOut(ref strPara5);
        if (!strRet5.Equals(strRet))
        {
            ReportFailure("Method PInvokeDef.MarshalPointer_InOut[Managed Side],The Return string is wrong", strRet, strRet5);
        }
        if (!strPara5.Equals(strNative))
        {
            ReportFailure("Method PInvokeDef.MarshalPointer_InOut[Managed Side],The Passed string is wrong", strNative, strPara5);
        }

        //TestMethod6
        Console.WriteLine("[Calling PInvokeDef.MarshalPointer_Out]");
        string strPara6;// = String.Copy(strManaged);
        string strRet6 = PInvokeDef.MarshalPointer_Out(out strPara6);
        if (!strRet6.Equals(strRet))
        {
            ReportFailure("Method PInvokeDef.MarshalPointer_Out[Managed Side],The Return string is wrong", strRet, strRet6);
        }
        if (!strPara6.Equals(strNative))
        {
            ReportFailure("Method PInvokeDef.MarshalPointer_Out[Managed Side],The Passed string is wrong", strNative, strPara6);
        }


        //TestMethod7
        Console.WriteLine("[Calling PInvokeDef.MarshalStrB_InOut]");
        StringBuilder strPara7 = new StringBuilder(strManaged);
        StringBuilder strRet7 = PInvokeDef.MarshalStrB_InOut(strPara7);

        if (!IsEqual(strRet7,strBRet))
        {
            ReportFailure("Method PInvokeDef.MarshalStrB_InOut[Managed Side],The Return string is wrong", strRet, strRet7.ToString());
        }
        if (!strPara7.Equals(new StringBuilder(strNative)))
        {
            ReportFailure("Method PInvokeDef.MarshalStrB_InOut[Managed Side],The Passed string is wrong", strNative, strPara7.ToString());
        }

        //TestMethod8
        Console.WriteLine("[Calling PInvokeDef.MarshalStrB_Out]");
        StringBuilder strPara8;// = new StringBuilder(strManaged);
        StringBuilder strRet8 = PInvokeDef.MarshalStrB_Out(out strPara8);
        if (!IsEqual(strRet8, strBRet))
        {
            ReportFailure("Method PInvokeDef.MarshalStrB_Out[Managed Side],The Return string is wrong", strRet, strRet8.ToString());
        }
        if (!IsEqual(strPara8,strBNative))
        {
            ReportFailure("Method PInvokeDef.MarshalStrB_Out[Managed Side],The Passed string is wrong", strNative, strPara8.ToString());
        }
        
        //TestMethod9
        Console.WriteLine("[Calling PInvokeDef.MarshalStrWB_InOut]");
        StringBuilder strPara9 = new StringBuilder(strManaged, strManaged.Length);
        StringBuilder strRet9 = PInvokeDef.MarshalStrWB_InOut(strPara9);
        
        if (!IsEqual(strRet9, strBRet))
        {
            ReportFailure("Method PInvokeDef.MarshalStrWB_InOut[Managed Side],The Return string is wrong", strRet, strRet9.ToString());
        }
        if (!IsEqual(strPara9,strBNative))
        {
            ReportFailure("Method PInvokeDef.MarshalStrWB_InOut[Managed Side],The Passed string is wrong", strNative, strPara9.ToString());
        }

        #region DelegatePinvoke
        //TestMethod11
        Del_MarshalPointer_InOut d1 = new Del_MarshalPointer_InOut(PInvokeDef.MarshalPointer_InOut);
        string strPara11 = new string(strManaged.ToCharArray());
        string strRet11 = d1(ref strPara11);
        if (!strRet11.Equals(strRet))
        {
            ReportFailure("Method Del_MarshalPointer_InOut[Managed Side],The Return string is wrong", strRet, strRet11);
        }
        if (!strPara11.Equals(strNative))
        {
            ReportFailure("Method Del_MarshalPointer_InOut[Managed Side],The Passed string is wrong", strNative, strPara11);
        }

        Del_Marshal_Out d2 = new Del_Marshal_Out(PInvokeDef.Marshal_Out);
        string strPara12 = strManaged;
        string strRet12 = d2(strPara12);
        if (!strRet.Equals(strRet12))
        {
            ReportFailure("Method Del_Marshal_Out[Managed Side],The Return string is wrong", strRet, strRet12);
        }
        if (!strManaged.Equals(strPara12))
        {
            ReportFailure("Method Del_Marshal_Out[Managed Side],The Parameter string is Changed", strManaged, strPara12);
        }
        #endregion

        #region ReversePInvoke
        Del_MarshalStrB_InOut d3 = new Del_MarshalStrB_InOut(Call_Del_MarshalStrB_InOut);
        if (!PInvokeDef.ReverseP_MarshalStrB_InOut(d3, "ă"))
        {
            ReportFailure("Method ReverseP_MarshalStrB_InOut[Managed Side],return value is false");
        }

        Del_MarshalStrB_Out d4 = new Del_MarshalStrB_Out(Call_Del_MarshalStrB_Out);
        if (!PInvokeDef.ReverseP_MarshalStrB_Out(d4))
        {
            ReportFailure("Method ReverseP_MarshalStrB_Out[Managed Side],return value is false");
        }

        #endregion

        return ExitTest();
     }
Example #6
0
 public static void TestEquals(StringBuilder sb1, StringBuilder sb2, bool expected)
 {
     Assert.Equal(expected, sb1.Equals(sb2));
 }