//constructor that takes two strings for the two blurtReps objects public mixReps(string one, string two) { xBlurt = new blurtReps(one); zBlurt = new blurtReps(two); mixCount = 2; prefOdd = true; }
//no argument constructor public mixReps() { xBlurt = new blurtReps(); zBlurt = new blurtReps(); mixCount = 2; prefOdd = true; }
//Postcondition: may result in cohortReps capacity doubling, // cohortReps object becomes temporarily responsible // for a newly initiated blurtReps object public void push(string word) { if (count == capacity) { resize(); } blurtReps newBlurt = new blurtReps(word); array[count] = newBlurt; count++; }
//PRIVATE UTILITY FUNCTIONS //resizes cohortReps array so it is functionally boundless to the client private void resize() { blurtReps[] newArray = new blurtReps[capacity * 2]; for (int i = 0; i < capacity; i++) { newArray[i] = array[i]; array[i] = null; } capacity *= 2; array = newArray; }
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; }