Пример #1
0
//Main Function
int main()
{
	i = 0;
	/*
	printf("Enter Terminal Colors\n");

	for(i;i<4;i++)
	{
	printf("T%d : ",i);
	scanf("%d %d",&terminalColors[i][0],&terminalColors[i][1]);
	printf("\n");
	}
	*/


	noOfSteps = 4;	// Initial Cost Till BlackHole

	printCost("Initial Cost Till BlackHole");
	noOfSteps = noOfSteps + 2 + 1;
	printCost("Going to Terminal One");


	init_sort();

	if (checkForCompletion1())
	{
		printf("Sorted");
	}
	else  printf("Not Sorted");
	while (1);
	return 1;
}
Пример #2
0
void test_sort_1(CuTest *tc)
{
	/* General variable declaration. */
	db_query_mm_t mm;
	char segment[2000];
	init_query_mm(&mm, segment, 2000);
	
	scan_t scan;
	sort_t sort;
	db_tuple_t t;
	db_eet_t oneExpr[1];
	db_uint8 oneOrder[1];
	db_eetnode_attr_t attrNode;
	attrNode.base.type = DB_EETNODE_ATTR;
	db_int intResult;
	
	puts("**********************************************************************");
	puts("Test 1: Sort test_rel3 using first attribute in ascending order.");
	fflush(stdout);
	
	oneExpr[0].size = (1*sizeof(db_eetnode_attr_t) + 0*sizeof(db_eetnode_dbint_t));
	oneExpr[0].nodes = malloc((size_t)oneExpr[0].size);
	oneExpr[0].stack_size = oneExpr[0].size;
	oneOrder[0] = (db_uint8)DB_TUPLE_ORDER_ASC;
	
	attrNode.pos = 0;
	attrNode.tuple_pos = 0;
	(*((db_eetnode_attr_t*)(oneExpr[0].nodes))) = attrNode;
	
	init_scan(&scan, "test_rel3", &mm);
	init_sort(&sort, (db_op_base_t*)(&scan), oneExpr, 1, oneOrder, &mm);
	init_tuple(&t, sort.base.header->tuple_size, sort.base.header->num_attr, &mm);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 1 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	//printf("Result of next call: %d\n", intResult);
	CuAssertTrue(tc, 1 == intResult);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 73 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 0 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 0 == intResult);
	
	close((db_op_base_t*)&sort, &mm);
	close((db_op_base_t*)&scan, &mm);
	free(oneExpr[0].nodes);
	close_tuple(&t, &mm);
	puts("**********************************************************************");
}
Пример #3
0
int	sort_ways(int **ways)
{
  int	i;
  int	j;
  int	*len_ways;

  i = 0;
  j = 0;
  if ((len_ways = init_sort(ways, &i)) == NULL)
    return (-1);
  quick_sort(len_ways, 0, i - 1);
  j = 0;
  while (j != i)
    {
      if (len_ways[j] > 0)
	swap_tab(ways, len_ways[j]);
      j += 1;
    }
  return (0);
}
Пример #4
0
void init_subsystems(){
 init_cal();
 init_cli_macro();
 init_clipboard();
 init_commandline();
 init_evilloop();
 init_exec_cmd();
 init_expanded();
 init_file();
 init_file_ascii();
 init_file_help();
 init_file_hnb();
 init_file_html();
 init_file_opml();
 init_file_ps();
 init_file_xml();
 init_go();
 init_insertbelow();
 init_keepstate();
 init_mem();
 init_movenode();
 init_nodetest();
 init_outdent_indent();
 init_prefs();
 init_query();
 init_quit();
 init_remove();
 init_search();
 init_sort();
 init_spell();
 init_stats();
 init_tree_todo();
 init_ui_binding();
 init_ui_cli();
 init_ui_draw();
 init_ui_edit();
 init_ui_menu();
 init_ui_overlay();
 init_ui_style();
}
Пример #5
0
//Main Function
int main()
{
	/*init_devices();
	lcd_set_4bit();
	lcd_init();
	color_sensor_scaling();
	buzzer_on();
	servo_1(0);
	servo_2(0);
	servo_3(0);
	forward();
	red_read(); //display the pulse count when red filter is selected
	_delay_ms(500);
	green_read(); //display the pulse count when green filter is selected
	_delay_ms(500);
	blue_read(); //display the pulse count when blue filter is selected
	_delay_ms(500);
	lcd_wr_command(0x01);
	print_sensor(1,1,3);	//Prints value of White Line Sensor1
	print_sensor(1,5,2);	//Prints Value of White Line Sensor2
	print_sensor(1,9,1);	//Prints Value of White Line Sensor3
	print_sensor(2,1,11);
	servo_1(100);
	servo_2(100);
	servo_3(100);
	_delay_ms(7000);
	lcd_wr_command(0x01);
	buzzer();
	*/
	init_sort();
	//travel(1,3);
	while (1)
	{
	}
	return 1;
}
Пример #6
0
void test_sort_11(CuTest *tc)
{
	/* General variable declaration. */
	db_query_mm_t mm;
	char segment[2000];
	init_query_mm(&mm, segment, 2000);
	
	scan_t scan;
	sort_t sort;
	db_tuple_t t;
	db_eet_t twoExpr[2];
	db_uint8 twoOrder[2];
	db_eetnode_attr_t attrNode;
	attrNode.base.type = DB_EETNODE_ATTR;
	db_eetnode_t opNode;
	db_eetnode_t *arr_p;
	db_int intResult;
	
	puts("**********************************************************************");
	puts("Test 11: Sort fruit_stock_1 using two complex expressions.");
	fflush(stdout);
	twoExpr[0].size = (1*sizeof(db_eetnode_attr_t) + 0*sizeof(db_eetnode_dbstring_t)+ 1*sizeof(db_eetnode_t));
	twoExpr[0].nodes = malloc((size_t)twoExpr[0].size);
	twoExpr[0].stack_size = twoExpr[0].size;
	twoExpr[1].size = (2*sizeof(db_eetnode_attr_t) + 0*sizeof(db_eetnode_dbint_t)+ 1*sizeof(db_eetnode_t));
	twoExpr[1].nodes = malloc((size_t)twoExpr[1].size);
	twoExpr[1].stack_size = twoExpr[1].size;
	twoOrder[0] = DB_TUPLE_ORDER_ASC;
	twoOrder[1] = DB_TUPLE_ORDER_ASC;
	
	arr_p = twoExpr[0].nodes;
	
	attrNode.pos = 1;
	attrNode.tuple_pos = 0;
	(*((db_eetnode_attr_t*)(arr_p))) = attrNode;
	arr_p = ((db_eetnode_t*)(((db_eetnode_attr_t*)(arr_p))+1));
	
	opNode.type = DB_EETNODE_FUNC_LENGTH_DBSTRING;
	*arr_p = opNode;
	arr_p++;
	
	arr_p = twoExpr[1].nodes;
	
	attrNode.pos = 2;
	attrNode.tuple_pos = 0;
	(*((db_eetnode_attr_t*)(arr_p))) = attrNode;
	arr_p = ((db_eetnode_t*)(((db_eetnode_attr_t*)(arr_p))+1));
	
	attrNode.pos = 3;
	attrNode.tuple_pos = 0;
	(*((db_eetnode_attr_t*)(arr_p))) = attrNode;
	arr_p = ((db_eetnode_t*)(((db_eetnode_attr_t*)(arr_p))+1));
	
	opNode.type = DB_EETNODE_OP_MOD;
	*arr_p = opNode;
	arr_p++;
	
	init_scan(&scan, "fruit_stock_2", &mm);
	init_sort(&sort, (db_op_base_t*)(&scan), twoExpr, 2, twoOrder, &mm);
	init_tuple(&t, sort.base.header->tuple_size, sort.base.header->num_attr, &mm);
	
	// TODO: I really should change getintbypos and such to return to an address.
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	CuAssertTrue(tc, (1 << 0) + (1 << 1) + (1 << 2) == t.isnull[0]);
	//intResult = getintbypos(&t, 0, sort.base.header);
	//printf("Int value at position %d the tuple: %d\n", 0, intResult);
	//CuAssertTrue(tc, 3 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	CuAssertTrue(tc, (1 << 1) + (1 << 2) == t.isnull[0]);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 8 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	CuAssertTrue(tc, (1 << 1) == t.isnull[0]);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 3 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	CuAssertTrue(tc, (1 << 0) + (1 << 1) == t.isnull[0]);
	//intResult = getintbypos(&t, 0, sort.base.header);
	//printf("Int value at position %d the tuple: %d\n", 0, intResult);
	//CuAssertTrue(tc, 3 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	CuAssertTrue(tc, (1 << 2) == t.isnull[0]);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 5 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	CuAssertTrue(tc, (1 << 0) + (1 << 2) == t.isnull[0]);
	//intResult = getintbypos(&t, 0, sort.base.header);
	//printf("Int value at position %d the tuple: %d\n", 0, intResult);
	//CuAssertTrue(tc, 3 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	CuAssertTrue(tc, (1 << 0) == t.isnull[0]);
	//intResult = getintbypos(&t, 0, sort.base.header);
	//printf("Int value at position %d the tuple: %d\n", 0, intResult);
	//CuAssertTrue(tc, 3 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	CuAssertTrue(tc, 0 == t.isnull[0]);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 2 == intResult);
	

	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 0 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 0 == intResult);
	
	close((db_op_base_t*)&sort, &mm);
	close((db_op_base_t*)&scan, &mm);
	close_tuple(&t, &mm);
	free(twoExpr[0].nodes);
	free(twoExpr[1].nodes);
	puts("**********************************************************************");
}
Пример #7
0
void test_sort_9(CuTest *tc)
{
	/* General variable declaration. */
	db_query_mm_t mm;
	char segment[2000];
	init_query_mm(&mm, segment, 2000);
	
	scan_t scan;
	sort_t sort;
	db_tuple_t t;
	db_eet_t oneExpr[1];
	db_uint8 oneOrder[1];
	db_eetnode_attr_t attrNode;
	attrNode.base.type = DB_EETNODE_ATTR;
	db_eetnode_t opNode;
	db_eetnode_t *arr_p;
	db_int intResult;
	
	puts("**********************************************************************");
	puts("Test 9: Sort fruit_stock_1 using (3rd > 4th), in descending order.");
	fflush(stdout);
	oneExpr[0].size = (2*sizeof(db_eetnode_attr_t) + 0*sizeof(db_eetnode_dbint_t)+ 2*sizeof(db_eetnode_t));
	oneExpr[0].nodes = malloc((size_t)oneExpr[0].size);
	oneExpr[0].stack_size = oneExpr[0].size;
	oneOrder[0] = DB_TUPLE_ORDER_DESC;
	
	arr_p = oneExpr[0].nodes;
	
	attrNode.pos = 2;
	attrNode.tuple_pos = 0;
	(*((db_eetnode_attr_t*)(arr_p))) = attrNode;
	arr_p = ((db_eetnode_t*)(((db_eetnode_attr_t*)(arr_p))+1));
	
	attrNode.pos = 3;
	attrNode.tuple_pos = 0;
	(*((db_eetnode_attr_t*)(arr_p))) = attrNode;
	
	init_scan(&scan, "fruit_stock_1", &mm);
	init_sort(&sort, (db_op_base_t*)(&scan), oneExpr, 1, oneOrder, &mm);
	init_tuple(&t, sort.base.header->tuple_size, sort.base.header->num_attr, &mm);
	
	opNode.type = DB_EETNODE_OP_GT;
	*arr_p = opNode;
	arr_p++;
	
	opNode.type = DB_EETNODE_OP_NOT;
	*arr_p = opNode;
	arr_p++;
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 1 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 2 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 3 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 4 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 5 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 0 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 0 == intResult);
	
	close((db_op_base_t*)&sort, &mm);
	close((db_op_base_t*)&scan, &mm);
	close_tuple(&t, &mm);
	free(oneExpr[0].nodes);
	puts("**********************************************************************");
}
Пример #8
0
void test_sort_7(CuTest *tc)
{
	/* General variable declaration. */
	db_query_mm_t mm;
	char segment[2000];
	init_query_mm(&mm, segment, 2000);
	
	scan_t scan;
	sort_t sort;
	db_tuple_t t;
	db_eet_t twoExpr[2];
	db_uint8 twoOrder[2];
	db_eetnode_attr_t attrNode;
	attrNode.base.type = DB_EETNODE_ATTR;
	db_int intResult;
	
	puts("**********************************************************************");
	puts("Test 7: Sort fruit_stock_1 using 4th and 3rd attributes, in asc/desc order (respectively).");
	fflush(stdout);
	
	twoExpr[0].size = (1*sizeof(db_eetnode_attr_t) + 0*sizeof(db_eetnode_dbint_t));
	twoExpr[0].nodes = malloc((size_t)twoExpr[0].size);
	twoExpr[0].stack_size = twoExpr[0].size;
	
	twoExpr[1].size = (1*sizeof(db_eetnode_attr_t) + 0*sizeof(db_eetnode_dbint_t));
	twoExpr[1].nodes = malloc((size_t)twoExpr[1].size);
	twoExpr[1].stack_size = twoExpr[1].size;
	
	twoOrder[0] = DB_TUPLE_ORDER_ASC;
	twoOrder[1] = DB_TUPLE_ORDER_DESC;
	
	attrNode.pos = 3;
	attrNode.tuple_pos = 0;
	(*((db_eetnode_attr_t*)(twoExpr[0].nodes))) = attrNode;
	
	attrNode.pos = 2;
	attrNode.tuple_pos = 0;
	(*((db_eetnode_attr_t*)(twoExpr[1].nodes))) = attrNode;
	
	init_scan(&scan, "fruit_stock_1", &mm);
	init_sort(&sort, (db_op_base_t*)(&scan), twoExpr, 2, twoOrder, &mm);
	init_tuple(&t, sort.base.header->tuple_size, sort.base.header->num_attr, &mm);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 3 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 1 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 2 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 5 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 1 == intResult);
	intResult = getintbypos(&t, 0, sort.base.header);
	printf("Int value at position %d the tuple: %d\n", 0, intResult);
	CuAssertTrue(tc, 4 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 0 == intResult);
	
	intResult = next((db_op_base_t*)&sort, &t, &mm);
	CuAssertTrue(tc, 0 == intResult);
	
	close((db_op_base_t*)&sort, &mm);
	close((db_op_base_t*)&scan, &mm);
	close_tuple(&t, &mm);
	free(twoExpr[0].nodes);
	free(twoExpr[1].nodes);
	puts("**********************************************************************");
}