예제 #1
0
 //Postcondition: pinging the blurtReps objects may result in them
 //  aging out and not producing output; this would result in the
 //  mixReps object not producing output and being useless
 public void print()
 {
     if (prefOdd)
     {
         if (mixCount == 1)
         {
             xBlurt.ping();
         }
         else
         {
             xBlurt.ping();
             zBlurt.ping();
         }
     }
     else
     {
         if (mixCount == 1)
         {
             zBlurt.ping();
         }
         else
         {
             zBlurt.ping();
             xBlurt.ping();
         }
     }
     Console.WriteLine();
 }
예제 #2
0
    static void Main(string[] args)
    {
        const int NUMTESTS = 5;

        blurtReps defaultIsNull = new blurtReps();
        blurtReps tooLong       = new blurtReps("sidney crosby");
        blurtReps shortWord     = new blurtReps("x");
        blurtReps myWord        = new blurtReps("it");

        Console.WriteLine("Demonstrating basic utility of blurtReps:");

        for (int i = 0; i < NUMTESTS; i++)
        {
            defaultIsNull.ping();
            tooLong.ping();
            shortWord.ping();
            myWord.ping();
        }

        Console.WriteLine("Demonstrating capacity to handle random input:");
        int prePing;
        int postPing;

        //This will test the blurtReps objects by pinging them until they deactivate

        for (int i = 0; i < NUMTESTS; i++)
        {
            blurtReps testObj = new blurtReps(randStringGen());
            bool      active  = true;
            while (active)
            {
                prePing = testObj.query();
                testObj.ping();
                postPing = testObj.query();
                if (prePing == postPing)
                {
                    active = false;
                }
            }
        }
        return;
    }