Ejemplo n.º 1
0
int main() {
    
    // Defines the example arrays to sort
    int testSort[10] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
    int testSortRep[20] = {10, 1, 9, 2, 8, 3, 7, 4, 6, 5, 5, 6, 4, 7, 3, 8, 2, 9, 1, 10};
    int testSortOdd[7] = {7, 9, 1, 5, 2, 3, 8};
    int testSortSingle[1] = {1};
    int testSortNone[5] = {};
    
    // Defines what the arrays should look like when sorted
    int sorted[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int sortedRep[20] = {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10};
    int sortedOdd[7] = {1, 2, 3, 5, 7, 8, 9};
    int sortedSingle[1] = {1};
    int sortedNone[5] = {};
    
    // Creates an array of all the unsorted arrays
    int *arraysToSort[5] = {testSort, testSortRep, testSortOdd, testSortSingle, testSortNone};
    // Creates an array of all the sorted arrays
    int *arraysToMatch[5] = {sorted, sortedRep, sortedOdd, sortedSingle, sortedNone};
    // Stores the size of each array
    int sizeToSort[5] = {10, 20, 7, 1, 5};
    
    int i;
    
    // For each array to sort, see that the function 'quicksort' sorts it correctly
    for (i=0; i<5; i++) {
        
        quicksort(arraysToSort[i], 0, sizeToSort[i]-1);
        assert(compareArrays(arraysToSort[i], arraysToMatch[i], sizeToSort[i]) == TRUE);
        
    }

    // Define arrays to sort with the wrong left and right indices
    int wrongStart[5] = {5, 4, 3, 2, 1};
    int wrongEnd[5] = {5, 4, 3, 2, 1};
    
    // Define a new array that should match both arrays once sorted
    int wrongSorted[5] = {1, 2, 3, 4, 5};
    
    // Quicksort the array with the wrong left index and see that it is sorted correctly
    quicksort(wrongStart, 1, 4);
    assert(compareArrays(wrongStart, wrongSorted, 5) == FALSE);
    
    // Quicksort the array with the wrong right index and see that it is sorted correctly
    quicksort(wrongEnd, 0, 5);
    assert(compareArrays(wrongEnd, wrongSorted, 5) == FALSE);
    
    // If no tests fail and abort the program, then all tests have passed
    printf("All tests passed.\n");
    
    return 0;
}
Ejemplo n.º 2
0
bool compareIntList( IntList * a, IntList * b ){
	//sortIntList(a);
	//sortIntList(b);
	int * aa = IntList2ArrayL(a);
	int * ab = IntList2ArrayL(b);
	bool result = compareArrays(aa,ab);
	delete [] aa;
	delete [] ab;
	return result;
}
Ejemplo n.º 3
0
void test_print(struct tnode* p, int expectedResult, char expectedArray[][MAX_URL_LENGTH], int expected_freq[10]){
	 
	char node_urls[10][MAX_URL_LENGTH];
	int url_frequency[10];
	  if ( expectedResult != treeprint(0,p, node_urls, url_frequency) ) {
        printf("Test TREE PRINT Failed.\n");
	  }
	  else{
          if(compareArrays(expectedArray, node_urls,expectedResult))
           if(compare_numArrays(expected_freq, url_frequency, expectedResult)){
              printf("Test TREE PRINT Passed.\n");
	      return;
	   }
              printf("Test TREE PRINT Failed.\n");
	  }
 }
Ejemplo n.º 4
0
bool Transfer::synchronize() {
  uint8_t data[2];
  uint8_t i;
  uint8_t time = 64;
  
  for ( i = 0 ; i < 2 ; i++ ) {
    data[i] = stream->read();
  }
    
  while ( !compareArrays(syncSequence,data,2) ) {
    if ( stream->available() > 0 ) {
			data[0] = data[1];
      data[1] = stream->read();
    }
    if ( time == 0 ) {
      return false;
    }
    time--;
  }
  
  return true;
}
Ejemplo n.º 5
0
int goalTest(tState *s) {
  
  int positions[3][3];
  positions[0][0] = 1;
  positions[0][1] = 2;
  positions[0][2] = 3;
  positions[1][0] = 4;
  positions[1][1] = 5;
  positions[1][2] = 6;
  positions[2][0] = 7;
  positions[2][1] = 8;
  positions[2][2] = 0;
  
  struct {
    int x;
    int y;
  } hole;
  
  hole.x = 2;
  hole.y = 2;
  
  return (compareArrays(3, s->tablero, positions) && hole.x == s->holePos.x && hole.y == s->holePos.y);
}
/***************************************************************************************************
 *         Main section                                                                            *
 ***************************************************************************************************/
void main(void) {

	WDTCTL = WDTPW | WDTHOLD;

		if(CALBC1_1MHZ==0xFF)
		{
			while(1);
		}
		DCOCTL = 0;
		BCSCTL1 = CALBC1_1MHZ;
		DCOCTL = CALDCO_1MHZ;

//	    LED_DIR = (LED_0 ); //LEDs are set as output
//	    LED_OUT &= ~(LED_0 ); //LEDs are turned off

		P1SEL  |= BIT1 + BIT2;	 	//Enable module function on pin
		P1SEL2 |= BIT1 + BIT2;  	//Select second module; P1.1 = RXD, P1.2=TXD

		UCA0CTL1 |= UCSSEL_2;    	// Set clock source SMCLK
		UCA0BR0 = 104;           	// 1MHz 9600 (N=BRCLK/baudrate)
		UCA0BR1 = 0;             	// 1MHz 9600
		UCA0MCTL = UCBRS0;       	// Modulation UCBRSx = 1
		UCA0CTL1 &= ~UCSWRST;    	// **Initialize USCI state machine**

		IE2 |= UCA0RXIE;         	//enable RX interrupt

		__enable_interrupt();
//	uint8 cntr = 0;

	// Initialize system
	Print_Error(System_Init());

	while (1) {

		if (process == 1)
		{
				request = compareArrays(data_transmit_buffer, data_memory_buffer, data_slots);
//				request = critical_request(model_output);
				process = 0;
		}
		if (request == 1)
		{
			payload_length = 0;

			// Construct the packet
			// This is the place where you can put your own data to send
			TxPacket[payload_length++] = PKT_CTRL | PKT_CTRL_REQUEST;
			TxPacket[payload_length++] = 'S';
			TxPacket[payload_length++] = data_transmit_buffer[0];
			TxPacket[payload_length++] = data_transmit_buffer[1];
			TxPacket[payload_length++] = data_transmit_buffer[2];
			TxPacket[payload_length++] = data_transmit_buffer[3];
			TxPacket[payload_length++] = data_transmit_buffer[4];
			TxPacket[payload_length++] = data_transmit_buffer[5];

			// Send data over RF and get the exit code to check for errors
			exit_code = Radio_Send_Data(TxPacket, payload_length, ADDR_REMOTE, PAYLOAD_ENC_OFF, PCKT_ACK_ON);

			// Add some delay (around 2sec)
			__delay_cycles(5000000*SYSTEM_SPEED_MHZ);

			request = 0;
		}
	}
}