Beispiel #1
0
 /*
  * copy(gen) - for deep copying
  *
  * Preconditions: argument must of gen type
  * Postconditions: states and variables may change
  * Invariants:
  */
 private gen copy(gen rhs)
 {
     if (rhs != this)
     {
         gen_state      = rhs.gen_state;
         constant       = rhs.constant;
         a1             = rhs.a1;
         position       = rhs.position;
         n              = rhs.n;
         m              = rhs.m;
         original_state = rhs.original_state;
     }
     return(this);
 }
Beispiel #2
0
        /*
         * Testing of heterogeneous collection with gen interface as base
         * Every object in the collection will skip the position specified by "skip_this_num" and double the value of the position
         *      specified by "double_this_num". This will only affect dubGen, skipGen, blurtDubGen, and blurtSkipGen.
         * The for loop gets the next value from the internalized arithmetic sequence of each object by the number specified by
         *      test_num and the output is checked if they are skipped or if the object is inactive.
         * Each object's states will be toggled after every call to the arithmetic sequence and is expected to return an "Inactive"
         *      string when the state of the object is off.
         * Compared to p4, explicit tests using blurtDubGen and blurtSkipGen objects were done. They print out to the console the original
         *      arithmetic sequences, then resetting them and doubling or skipping every position in the sequence.
         *
         * Invariants: This test uses 5 objects. If the initia value of picker_2 isn't changed, the objects are in the order:
         *      blurtGen
         *      blurtDubGen
         *      blurtSkipGen
         *      blurtDubGen
         *      gen
         */
        void gen_hetero_test()
        {
            const int    COLL_SIZE             = 5;
            const int    IS_INACTIVE           = -1;
            const int    IS_SKIPPED            = -2;
            const string STR_INACTIVE          = "Inactive";
            const string STR_SKIPPED           = "Skipped";
            int          output_control        = 0;
            int          test_num              = 8;
            int          skip_this_num         = 2;
            int          double_this_num       = 4;
            int          current_array_element = 0;

            gen[] gen_array = new gen[COLL_SIZE];

            // fill in heterogeneous array
            for (int i = 0; i < COLL_SIZE; i++)
            {
                gen_array[i] = gen_base_obj();
            }
            Console.WriteLine("Current Order: blurtGen, blurtDubGen, blurtSkipGen, blurtDubGen, gen");
            Console.WriteLine();
            // general getting sequence test
            for (int i = 0; i < COLL_SIZE; i++)
            {
                output_control++;
                gen_array[i].skip_position(skip_this_num);
                gen_array[i].double_this(double_this_num);
                for (int j = 0; j < test_num; j++)
                {
                    float temp = gen_array[i].gimme_sequence();
                    if ((int)temp == IS_INACTIVE)
                    {
                        Console.Write(STR_INACTIVE);
                    }
                    else if ((int)temp == IS_SKIPPED)
                    {
                        Console.Write(STR_SKIPPED);
                    }
                    else
                    {
                        Console.Write(temp);
                    }
                    if (j != test_num - 1)
                    {
                        Console.Write(", ");
                    }
                    gen_array[i].toggle_state();
                }
                Console.WriteLine();
            }
            Console.WriteLine();

            // Explicitly testing blurtDubGen
            current_array_element++;
            Console.WriteLine("Explicitly testing out blurtDubGen. It is the 3rd object in the array.");
            gen_array[current_array_element].gen_reset();
            for (int i = 0; i < test_num; i++)
            {
                Console.Write(gen_array[current_array_element].gimme_sequence() + ", ");
            }
            Console.WriteLine();
            Console.WriteLine("Resetting and doubling every position in blurtDubGen obj:");
            gen_array[current_array_element].gen_reset();
            for (int i = 0; i < test_num; i++)
            {
                gen_array[1].double_this(i);
                Console.Write(gen_array[1].gimme_sequence() + ", ");
            }
            Console.WriteLine();
            Console.WriteLine();

            // Explicitly testing blurtSkipGen
            current_array_element++;
            Console.WriteLine("Explicitly testing out blurtSkipGen. It is the 2nd and 4th object in the array. Let us use the 2nd.");
            gen_array[current_array_element].gen_reset();
            for (int i = 0; i < test_num; i++)
            {
                float temp = gen_array[current_array_element].gimme_sequence();
                if ((int)temp == IS_INACTIVE)
                {
                    Console.Write(STR_INACTIVE);
                }
                else if ((int)temp == IS_SKIPPED)
                {
                    Console.Write(STR_SKIPPED);
                }
                else
                {
                    Console.Write(temp);
                }
                if (i != test_num - 1)
                {
                    Console.Write(", ");
                }
            }
            Console.WriteLine();
            Console.WriteLine("Resetting and skipping every position in blurtSkipGen obj:");
            gen_array[current_array_element].gen_reset();
            for (int i = 0; i < test_num; i++)
            {
                gen_array[current_array_element].skip_position(i);

                float temp = gen_array[current_array_element].gimme_sequence();
                if ((int)temp == IS_INACTIVE)
                {
                    Console.Write(STR_INACTIVE);
                }
                else if ((int)temp == IS_SKIPPED)
                {
                    Console.Write(STR_SKIPPED);
                }
                else
                {
                    Console.Write(temp);
                }
                if (i != test_num - 1)
                {
                    Console.Write(", ");
                }
            }
            Console.WriteLine();
        }
Beispiel #3
0
 /*
  * copy constructor - copies passed gen object's data
  *
  * Preconditions: argument must be of gen type
  * Postconditions:
  * Invariants:
  */
 public gen(gen rhs)
 {
     this.copy(rhs);
 }