コード例 #1
0
ファイル: test_dlist.c プロジェクト: nathangeffen/cagl
static void test_reverse(struct cag_test_series *tests)
{
	complex_list l;
	it_complex_list it;
	int i;

	new_complex_list(&l);
	populate_list(&l, 0, 10, 1);
	it = reverse_complex_list(beg_complex_list(&l), end_complex_list(&l));
	CAG_TEST(*tests, it == beg_complex_list(&l),
			 "cag_dlist: reversed list returns iterator = begin");
	for (it = beg_complex_list(&l), i = 9; it != end_complex_list(&l);
	     it = it->next, --i) {
		CAG_TEST(*tests, it->value.real == i,
			"cag_dlist: reversed list");
	}
	free_complex_list(&l);
	new_complex_list(&l);
	populate_list(&l, 0, 9, 1);
	reverse_complex_list(beg_complex_list(&l), end_complex_list(&l));
	for (it = beg_complex_list(&l), i = 8; it != end_complex_list(&l);
	     it = it->next, --i) {
		CAG_TEST(*tests, it->value.real == i,
			"cag_dlist: reversed list");
	}
	reverse_all_complex_list(&l);
	for (it = beg_complex_list(&l), i = 0; it != end_complex_list(&l);
	     it = it->next, ++i) {
		CAG_TEST(*tests, it->value.real == i,
			"cag_dlist: reverse all container list");
	}
	free_complex_list(&l);
}
コード例 #2
0
ファイル: test_dlist.c プロジェクト: nathangeffen/cagl
static void test_erase(struct cag_test_series *tests)
{
	complex_list l;
	it_complex_list it;
	int i;
	size_t s;
	struct complex c;

	new_complex_list(&l);
	populate_list(&l, 0, 5, 1);
	CAG_TEST(*tests,
		 distance_complex_list(beg_complex_list(&l),
				       end_complex_list(&l)) == 5,
		 "cag_dlist: distance before erase");
	for(i = 0, it = beg_complex_list(&l), s = 4;
	    it != end_complex_list(&l);  ++i, --s) {
		c = *front_complex_list(&l);
		CAG_TEST(*tests, (i == c.real && c.imag == -i),
			 "cag_dlist: remove object");
		it = erase_complex_list(&l, it);
		CAG_TEST(*tests,
			 distance_complex_list(beg_complex_list(&l),
					       end_complex_list(&l)) == s,
			 "cag_dlist: number elements after erase");
	}
	populate_list(&l, 0, 5, 1);
	CAG_TEST(*tests,
		 distance_complex_list(beg_complex_list(&l),
				       end_complex_list(&l)) == 5,
		 "cag_dlist: distance before erase");
	erase_range_complex_list(&l, beg_complex_list(&l),
				 end_complex_list(&l));
	CAG_TEST(*tests,
		 distance_complex_list(beg_complex_list(&l),
				       end_complex_list(&l)) == 0,
		 "cag_dlist: distance after erase all");
	CAG_TEST(*tests,
		 rdistance_complex_list(rbeg_complex_list(&l),
				       rend_complex_list(&l)) == 0,
		 "cag_dlist: reverse distance after erase all");
	free_complex_list(&l);
	new_complex_list(&l);
	populate_list(&l, 0, 5, 1);
	CAG_TEST(*tests, distance_all_complex_list(&l) == 5,
			 "cag_dlist: distance all container");
	erase_all_complex_list(&l);
	CAG_TEST(*tests, distance_all_complex_list(&l) == 0,
			 "cag_dlist: erase all container");
	free_complex_list(&l);
}
コード例 #3
0
ファイル: test_dlist.c プロジェクト: nathangeffen/cagl
static void test_cmp(struct cag_test_series *tests)
{
	complex_list l1, l2, l3;
	struct complex c;
	new_complex_list(&l1);
	new_complex_list(&l2);
	new_complex_list(&l3);
	CAG_TEST(*tests, cmp_range_complex_list(beg_complex_list(&l1),
						end_complex_list(&l1),
						beg_complex_list(&l2),
						end_complex_list(&l2)) == 0,
		 "cag_dlist: compare empty lists");
	populate_list(&l1, 0, 5, 1);
	populate_list(&l2, 0, 5, 1);
	CAG_TEST(*tests, cmp_all_complex_list(&l1, &l2) == 0,
		 "cag_dlist: compare all equal lists");
	CAG_TEST(*tests, cmp_range_complex_list(beg_complex_list(&l1),
						end_complex_list(&l1),
						beg_complex_list(&l2),
						end_complex_list(&l2)) == 0,
		 "cag_dlist: compare equal lists");
	c.real = 10;
	c.imag = -10;
	append_complex_list(&l1, c);
	CAG_TEST(*tests, cmp_all_complex_list(&l1, &l2) > 0,
		 "cag_dlist: compare all 1st list bigger");
	CAG_TEST(*tests, cmp_range_complex_list(beg_complex_list(&l1),
						end_complex_list(&l1),
						beg_complex_list(&l2),
						end_complex_list(&l2)) > 0,
		 "cag_dlist: compare 1st list bigger");
	c.real = 20;
	c.imag = -10;
	append_complex_list(&l2, c);
	CAG_TEST(*tests, cmp_all_complex_list(&l1, &l2) < 0,
		 "cag_dlist: compare all 2nd list bigger");
	CAG_TEST(*tests, cmp_range_complex_list(beg_complex_list(&l1),
						end_complex_list(&l1),
						beg_complex_list(&l2),
						end_complex_list(&l2)) < 0,
		 "cag_dlist: compare 2nd list bigger");
	rcopy_all_complex_list(&l2, &l3);
	CAG_TEST(*tests, rcmp_all_complex_list(&l2, &l3) == 0,
		 "cag_dlist: compare all list and its reverse");
	free_complex_list(&l1);
	free_complex_list(&l2);
	free_complex_list(&l3);
}
コード例 #4
0
ファイル: test_dlist.c プロジェクト: nathangeffen/cagl
static void test_at(struct cag_test_series *tests)
{
	complex_list l;
	it_complex_list it;
	rit_complex_list rit;
	new_complex_list(&l);
	populate_list(&l, 0, 10, 1);
	it = at_complex_list(beg_complex_list(&l), 0);
	CAG_TEST(*tests, it == beg_complex_list(&l),
		"cag_dlist: 0 index");
	it = at_complex_list(it, 2);
	CAG_TEST(*tests, it->value.real == 2.0,
		 "cag_dlist: 2 index");
	it = at_complex_list(it, 7);
	CAG_TEST(*tests, it->value.real == 9.0,
		 "cag_dlist: 7 index");
	it = at_complex_list(it, 1);
	CAG_TEST(*tests, it == end_complex_list(&l),
		 "cag_dlist: at end");

	rit = rat_complex_list(rbeg_complex_list(&l), 0);
	CAG_TEST(*tests, rit == rbeg_complex_list(&l),
		"cag_dlist: 0 index reverse");
	rit = rat_complex_list(rit, 2);
	CAG_TEST(*tests, rit->value.real == 7.0,
		 "cag_dlist: 2 index reverse");
	rit = rat_complex_list(rit, 7);
	CAG_TEST(*tests, rit->value.real == 0.0,
		 "cag_dlist: 7 index reverse");
	rit = rat_complex_list(rit, 1);
	CAG_TEST(*tests, rit == rend_complex_list(&l),
		 "cag_dlist: rat end");

	free_complex_list(&l);
}
コード例 #5
0
ファイル: test_dlist.c プロジェクト: nathangeffen/cagl
static void test_copy_over(struct cag_test_series *tests)
{
	complex_list l1, l2;
	it_complex_list it1, it2;

	new_complex_list(&l1);
	new_complex_list(&l2);

	populate_list(&l1, 0, 5, 1);

	set_exact_size_complex_list(&l2, 5);
	copy_over_complex_list(beg_complex_list(&l1), end_complex_list(&l1),
			       beg_complex_list(&l2));
	for (it1 = beg_complex_list(&l1), it2 = beg_complex_list(&l2);
	     it1 != end_complex_list(&l1); it1 = it1->next, it2 = it2->next)
		CAG_TEST(*tests, it1->value.real == it2->value.real &&
			 it1->value.imag == it2->value.imag,
			 "cag_dlist: element values after copy");
	CAG_TEST(*tests,
		 distance_complex_list(beg_complex_list(&l1),
				       end_complex_list(&l1)) ==
		 distance_complex_list(beg_complex_list(&l2),
				       end_complex_list(&l2)),
		 "cag_dlist: number elements after copy");
	free_complex_list(&l1);
	free_complex_list(&l2);
}
コード例 #6
0
ファイル: test_slist.c プロジェクト: nathangeffen/cagl
static void test_find(struct cag_test_series *tests)
{
	complex_slist l;
	it_complex_slist it;
	struct complex c;

	c.imag = -9;

	new_complex_slist(&l);
	populate_list(&l, 0, 10, 1);
	it = find_all_complex_slist(&l,c, find_element);
	CAG_TEST(*tests, it && it->value.real == 9.0,
		 "cag_slist: find element");
	c.imag = -10;
	it = find_all_complex_slist(&l, c, find_element);
	CAG_TEST(*tests, it == end_complex_slist(&l),
		 "cag_slist: find element");
	c.imag = -9.0;
	it = findp_all_complex_slist(&l, &c, find_element);
	CAG_TEST(*tests, it && it->value.real == 9.0,
		 "cag_slist: find element");
	c.imag = -10;
	it = findp_all_complex_slist(&l, &c, find_element);
	CAG_TEST(*tests, it == end_complex_slist(&l),
		 "cag_slist: find element");
	c.imag = -9.0;
	free_complex_slist(&l);
}
コード例 #7
0
/* Setup custom list style */
static void
setup_customlist (GtkWidget *tv, GreeterItemInfo *item)
{
  GtkTreeModel *tm;
  GtkTreeViewColumn *column;
  GtkTreeSelection *selection;
  GtkTreeIter iter = {0};

  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tv),
				     FALSE);
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
  gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);

  g_signal_connect (selection, "changed",
		    G_CALLBACK (list_selected),
		    item);

  tm = (GtkTreeModel *)gtk_list_store_new (2,
					   G_TYPE_STRING,
					   G_TYPE_STRING);
  gtk_tree_view_set_model (GTK_TREE_VIEW (tv), tm);
      
  column = gtk_tree_view_column_new_with_attributes
	  ("Choice",
	   gtk_cell_renderer_text_new (),
	   "text", GREETER_LIST_TEXT,
	   NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW (tv), column);

  g_signal_connect (tv, "button_release_event",
                    G_CALLBACK (custom_list_release_event),
                    NULL);

  if (strcmp (item->id, "session") == 0)
    {
      populate_session (G_OBJECT (tm));
      /*
       * Do not select since the session_init will initialize the
       * value and cause the combo list to get set without needing
       * to do it here.
       */
    }
  else if (strcmp (item->id, "language") == 0)
    {
      populate_language (G_OBJECT (tm));

      /* Select first item */
      if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (tm), &iter))
        gtk_tree_selection_select_iter (selection, &iter);
    }
  else
    {
      populate_list (tm, selection, item->data.list.items);

      /* Select first item */
      if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (tm), &iter))
        gtk_tree_selection_select_iter (selection, &iter);
    }
}
コード例 #8
0
int main() {
  List linkedList;
  list_init(&linkedList, free);

  populate_list(&linkedList);
  print(&linkedList);
  sort(&linkedList, compare);
  print(&linkedList);
}
コード例 #9
0
ファイル: test_slist.c プロジェクト: nathangeffen/cagl
static void test_copy_over(struct cag_test_series *tests)
{
	complex_slist l1, l2;
	new_complex_slist(&l1);
	new_complex_slist(&l2);
	populate_list(&l1, 0, 5, 1);
	populate_list(&l2, 5, 0, -1);
	CAG_TEST(*tests, cmp_all_complex_slist(&l1, &l2) != 0,
		 "cag_test: differently populated lists not equal");
	copy_over_complex_slist(beg_complex_slist(&l1), end_complex_slist(&l1),
				beg_complex_slist(&l2));
	CAG_TEST(*tests, cmp_all_complex_slist(&l1, &l2) == 0,
		 "cag_test: copied over list equals copied from");
	CAG_TEST(*tests, distance_all_complex_slist(&l2) ==
		 distance_all_complex_slist(&l1),
		 "cag_test: copied over list has same distance");
	free_complex_slist(&l2);
	free_complex_slist(&l1);
}
コード例 #10
0
ファイル: test_dlist.c プロジェクト: nathangeffen/cagl
static void test_batch(struct cag_test_series *tests)
{
	complex_list l1, l2, l3;
	int i;

	CAG_CHECK( (i = new_many_complex_list(&l1, NULL) > 0),
		   "failure many new");
	populate_list(&l1, 0, 5, 1);
	CAG_TEST(*tests, distance_complex_list(beg_complex_list(&l1),
					       end_complex_list(&l1)) == 5,
		 "cag_dlist: lists populated after batch new 1");
error:
	free_many_complex_list(i, &l1, NULL);

	CAG_CHECKL( (i = new_many_complex_list(&l1, &l2, NULL) > 0),
		    "failure many new", error_1);
	populate_list(&l1, 0, 5, 1);
	CAG_CHECKL(copy_many_complex_list(&l1, &l2, NULL) > 0,
		   "assign many failed", error_1);
	CAG_TEST(*tests,
		 distance_complex_list(beg_complex_list(&l1),
				       end_complex_list(&l1)) == 5 &&
		 cmp_all_complex_list(&l1, &l2) == 0,
		 "cag_dlist: lists populated after batch new 2");
error_1:
	free_many_complex_list(i, &l1, &l2, NULL);

	CAG_CHECKL( (i = new_many_complex_list(&l1, &l2, &l3, NULL)) > 0,
		   "failure many new", error_2);
	populate_list(&l1, 0, 5, 1);
	CAG_CHECKL(copy_many_complex_list(&l1, &l2, &l3, NULL) > 0,
		   "assign many failed", error_2);
	CAG_TEST(*tests,
		 distance_complex_list(beg_complex_list(&l1),
				       end_complex_list(&l1)) == 5 &&
		 cmp_all_complex_list(&l1, &l2) == 0 &&
		 cmp_all_complex_list(&l2, &l3) == 0,
		 "cag_dlist: lists populated after batch new 3");
error_2:
	free_many_complex_list(i, &l1, &l2, &l3, NULL);

}
コード例 #11
0
ファイル: app_list.cpp プロジェクト: fretelweb/audio-router
bool app_list::populate_list(const filters_t & filters) {
    this->apps.clear(); 

    if ( ! this-> populate_list(true, filters))
        return false; 
#ifdef _WIN64
    return this -  > populate_list(false, filters); 
#else
    return true; 
#endif
}
コード例 #12
0
ファイル: test_dlist.c プロジェクト: nathangeffen/cagl
static void test_iterator_comparison(struct cag_test_series *tests)
{
	complex_list l;
	it_complex_list it1, it2;
	rit_complex_list rit1, rit2;

	new_complex_list(&l);
	populate_list(&l, 0, 5, 1);
	it1 = beg_complex_list(&l);
	it2 = it1;
	CAG_TEST(*tests, lteq_it_complex_list(it1, it2) == 1,
		 "cag_dlist: equal iterators are equal");
	CAG_TEST(*tests, lt_it_complex_list(it1, it2) == 0,
		 "cag_dlist: equal iterators are not less than");
	it2 = it2->next;
	CAG_TEST(*tests, lteq_it_complex_list(it1, it2) == 1,
		 "cag_dlist: less than equal iterators");
	CAG_TEST(*tests, lt_it_complex_list(it1, it2) == 1,
		 "cag_dlist: less than iterators");
	it2 = end_complex_list(&l)->prev;
	CAG_TEST(*tests, lteq_it_complex_list(it1, it2) == 1,
		 "cag_dlist: less than equal last item");
	CAG_TEST(*tests, lt_it_complex_list(it1, it2) == 1,
		 "cag_dlist: less than last item");
	it2 = end_complex_list(&l)->prev;
	CAG_TEST(*tests, lteq_it_complex_list(it2, it1) == 0,
		 "cag_dlist: more than not equal last item");
	CAG_TEST(*tests, lt_it_complex_list(it2, it1) == 0,
		 "cag_dlist: more than last item");

	rit1 = rbeg_complex_list(&l);
	rit2 = rit1;
	CAG_TEST(*tests, rlteq_it_complex_list(rit1, rit2) == 1,
		 "cag_dlist: equal rev iterators are equal");
	CAG_TEST(*tests, rlt_it_complex_list(rit1, rit2) == 0,
		 "cag_dlist: equal rev iterators are not less than");
	rit2 = rit2->next;
	CAG_TEST(*tests, rlteq_it_complex_list(rit1, rit2) == 1,
		 "cag_dlist: less than equal rev iterators");
	CAG_TEST(*tests, rlt_it_complex_list(rit1, rit2) == 1,
		 "cag_dlist: less than rev iterators");
	rit2 = rend_complex_list(&l)->prev;
	CAG_TEST(*tests, rlteq_it_complex_list(rit1, rit2) == 1,
		 "cag_dlist: less than equal first item reverse");
	CAG_TEST(*tests, rlt_it_complex_list(rit1, rit2) == 1,
		 "cag_dlist: less than first item reverse");
	rit2 = rend_complex_list(&l)->prev;
	CAG_TEST(*tests, rlteq_it_complex_list(rit2, rit1) == 0,
		 "cag_dlist: more than not equal first item reverse");
	CAG_TEST(*tests, rlt_it_complex_list(rit2, rit1) == 0,
		 "cag_dlist: more than first item reverse");
	free_complex_list(&l);
}
コード例 #13
0
ファイル: test_slist.c プロジェクト: nathangeffen/cagl
static void test_front(struct cag_test_series *tests)
{
	complex_slist l;
	struct complex c;

	new_complex_slist(&l);
	populate_list(&l, 0, 5, 1);
	c = *front_complex_slist(&l);
	CAG_TEST(*tests, c.real == 4.0 && c.imag == -4.0,
		 "cag_dlist: Retrieve front value after prepends");
	free_complex_slist(&l);
}
コード例 #14
0
ファイル: main.c プロジェクト: luizsol/MAC0122
/** @brief The main function
 *
 *  @param argc the number of arguments passed to the main function
 *  @param argv the arguments passed to the main function
 *  @return the finishing status of the funcion
 */
int main(int argc, char *argv[]){
	if(argc == 2){
		start_list();
		populate_list(argv[1]);
		print_list();
		printf("The index of the middle cell is %d\n", recursive_middle_search(-1,-1));
		return 0;
	} else if(argc != 1){
		fprintf(stderr, "Bad argumet\n");
	}
	printf("Usage:\n./main <list>\n");
	return 1;
}
コード例 #15
0
ファイル: test_slist.c プロジェクト: nathangeffen/cagl
static void test_distance(struct cag_test_series *tests)
{
	complex_slist l;

	new_complex_slist(&l);
	populate_list(&l, 0, 5, 1);
	CAG_TEST(*tests, distance_complex_slist(beg_complex_slist(&l),
					        end_complex_slist(&l)) == 5,
		 "cag_slist: distance after populate");
	CAG_TEST(*tests, distance_all_complex_slist(&l) == 5,
		 "cag_slist: distance after populate");
	free_complex_slist(&l);
}
コード例 #16
0
ファイル: test_slist.c プロジェクト: nathangeffen/cagl
static void test_erase(struct cag_test_series *tests)
{
	complex_slist l;

	new_complex_slist(&l);
	erase_front_complex_slist(&l);
	erase_range_complex_slist(&l, beg_complex_slist(&l),
				  end_complex_slist(&l));
	erase_all_complex_slist(&l);
	populate_list(&l, 0, 6, 1);
	CAG_TEST(*tests, distance_all_complex_slist(&l) == 6,
		 "cag_slist: distance after erase then populate");
	CAG_TEST(*tests, back_complex_slist(&l)->real == 0.0,
		 "cag_slist: back after erase then populate");
	erase_after_complex_slist(beg_complex_slist(&l));
	CAG_TEST(*tests, beg_complex_slist(&l)->next->value.real == 3.0,
		 "cag_slist: value after single erase after");
	CAG_TEST(*tests, distance_all_complex_slist(&l) == 5,
		 "cag_slist: distance after single erase after");
	erase_after_range_complex_slist(beg_complex_slist(&l), NULL);
	CAG_TEST(*tests, distance_all_complex_slist(&l) == 1,
		 "cag_slist: distance after erase after range");
	erase_after_range_complex_slist(beg_complex_slist(&l), NULL);
	erase_front_complex_slist(&l);
	CAG_TEST(*tests, distance_all_complex_slist(&l) == 0,
		 "cag_slist: distance after erase all range and erase front");
	populate_list(&l, 0, 6, 1);
	erase_front_complex_slist(&l);
	CAG_TEST(*tests, distance_all_complex_slist(&l) == 5,
		 "cag_slist: distance after erase after range");
	erase_front_complex_slist(&l);
	CAG_TEST(*tests, distance_all_complex_slist(&l) == 4,
		 "cag_slist: distance after erase after range");
	erase_all_complex_slist(&l);
	CAG_TEST(*tests, distance_all_complex_slist(&l) == 0,
		 "cag_slist: distance after erase after range");
	free_complex_slist(&l);
}
コード例 #17
0
ファイル: test_dlist.c プロジェクト: nathangeffen/cagl
static void test_searchp(struct cag_test_series *tests)
{
	complex_list l;
	it_complex_list it, it_all;
	rit_complex_list rit;
	struct complex c;

	new_complex_list(&l);
	populate_list(&l, 0, 5, 1);
	populate_list(&l, 0, 5, 1);
	c.real = 3.0;
	c.imag = -3.0;
	it = searchp_complex_list(beg_complex_list(&l),
				end_complex_list(&l), &c);
	it_all = searchp_all_complex_list(&l, &c);
	CAG_TEST(*tests, it == it_all,
		 "cag_dlist: Searchp all finds same as searchp iterator");
	CAG_TEST(*tests, it != end_complex_list(&l) && it->value.real == 3.0
		 && it->value.imag == -3.0,
		 "cag_dlist: Value found");
	it = searchp_complex_list(it->next, end_complex_list(&l), &c);
	CAG_TEST(*tests, it != end_complex_list(&l) && it->value.real == 3.0
		 && it->value.imag == -3.0,
		 "cag_dlist: Value found second time");
	it = searchp_complex_list(it->next, end_complex_list(&l), &c);
	CAG_TEST(*tests, it == end_complex_list(&l),
		 "cag_dlist: Value not found");
	rit = rbeg_complex_list(&l);
	rit = rsearchp_complex_list(rit->next, rend_complex_list(&l), &c);
	CAG_TEST(*tests, rit != rend_complex_list(&l) && rit->value.real == 3.0
		 && rit->value.imag == -3.0,
		 "cag_dlist: reverse value found");
	c.real = 100.0;
	rit = rsearchp_complex_list(rit->next, rend_complex_list(&l), &c);
	CAG_TEST(*tests, rit == rend_complex_list(&l),
		 "cag_dlist: value reverse not found");
	free_complex_list(&l);
}
コード例 #18
0
ファイル: test_dlist.c プロジェクト: nathangeffen/cagl
static void test_distance(struct cag_test_series *tests)
{
	complex_list l;

	new_complex_list(&l);
	populate_list(&l, 0, 5, 1);
	CAG_TEST(*tests, distance_complex_list(beg_complex_list(&l),
					       end_complex_list(&l)) == 5,
		 "cag_dlist: number elements appended list");
	CAG_TEST(*tests, rdistance_complex_list(rbeg_complex_list(&l),
						rend_complex_list(&l)) == 5,
		 "cag_dlist: number elements appended list reverse");
	free_complex_list(&l);
}
コード例 #19
0
ファイル: test_dlist.c プロジェクト: nathangeffen/cagl
static void test_equal(struct cag_test_series *tests)
{
	complex_list l1, l2, l3;
	new_complex_list(&l1);
	new_complex_list(&l2);
	new_complex_list(&l3);
	CAG_TEST(*tests,
		 equal_range_complex_list(beg_complex_list(&l1),
					  end_complex_list(&l1),
					  beg_complex_list(&l2)) == CAG_TRUE,
		 "cag_dlist: equal empty lists");
	populate_list(&l1, 0, 5, 1);
	populate_list(&l2, 0, 5, 1);
	rcopy_all_complex_list(&l2, &l3);
	CAG_TEST(*tests,
		 equal_range_complex_list(beg_complex_list(&l1),
					  end_complex_list(&l1),
					  beg_complex_list(&l2)) == CAG_TRUE,
		 "cag_dlist: equal lists");
	CAG_TEST(*tests, equal_all_complex_list(&l1, &l2) == CAG_TRUE,
		 "cag_dlist: equal all lists");
	at_complex_list(beg_complex_list(&l1), 3)->value.real = 10;
	at_complex_list(beg_complex_list(&l1), 3)->value.imag = 20;
	CAG_TEST(*tests,
		 equal_range_complex_list(beg_complex_list(&l1),
					  end_complex_list(&l1),
					  beg_complex_list(&l2)) == CAG_FALSE,
		 "cag_dlist: unequal lists");
	CAG_TEST(*tests, equal_all_complex_list(&l1, &l2) == CAG_FALSE,
		 "cag_dlist: unequal all lists");
	CAG_TEST(*tests, requal_all_complex_list(&l2, &l3) == CAG_TRUE,
		 "cag_dlist: requal all list and its reverse");
	free_complex_list(&l1);
	free_complex_list(&l2);
	free_complex_list(&l3);
}
コード例 #20
0
ファイル: test_slist.c プロジェクト: nathangeffen/cagl
static void test_copy(struct cag_test_series *tests)
{
	complex_slist l1, l2;
	new_complex_slist(&l1);
	new_complex_slist(&l2);
	populate_list(&l1, 0, 5, 1);
	copy_all_complex_slist(&l1, &l2);
	CAG_TEST(*tests, cmp_all_complex_slist(&l1, &l2) == 0,
		 "cag_test: assigned lists equals");
	CAG_TEST(*tests, distance_all_complex_slist(&l2) ==
		 distance_all_complex_slist(&l1),
		 "cag_test: assigned lists have same distance");
	free_complex_slist(&l2);
	free_complex_slist(&l1);
}
コード例 #21
0
ファイル: main.c プロジェクト: luizsol/MAC0122
/** @brief The main function
 *
 *  @param argc the number of arguments passed to the main function
 *  @param argv the arguments passed to the main function
 *  @return the finishing status of the funcion
 */
int main(int argc, char *argv[]){
	if(argc == 2){
		List lista;
		populate_list(&lista, argv[1]);
		puts("Original list:");
		print_list(&lista);
		reverse_list(&lista);
		puts("Reverse list:");
		print_list(&lista);
		return 0;
	} else if(argc != 1){
		fprintf(stderr, "Bad argumet\n");
	}
	printf("Usage:\n./main <comma separetad list>\n");
	return 1;
}
コード例 #22
0
// Primary constructor to establish the dialog
US_XpnRunAuc::US_XpnRunAuc( QString& runID ) 
: US_WidgetsDialog( 0, 0 ), runID( runID )
{
   setWindowTitle( tr( "US3 Directories with Optima-derived .auc Files" ) );

   setPalette( US_GuiSettings::frameColor() );

   runID             = "";
   QVBoxLayout* main = new QVBoxLayout( this );
   main->setSpacing        ( 2 );
   main->setContentsMargins( 2, 2, 2, 2 );

   // Search
   QHBoxLayout* search       = new QHBoxLayout;
   QLabel*      lb_search    = us_label( tr( "Search" ) );
                le_search    = us_lineedit( "" );
   search      ->addWidget( lb_search );
   search      ->addWidget( le_search );
   connect( le_search, SIGNAL( textChanged( const QString& ) ),
            this,      SLOT  ( limit_data ( const QString& ) ) );

   // Load the runInfo structure with current data
   load_runs();

   // Tree
   tw                     = new QTableWidget( runInfo.size(), 3, this );
   populate_list();

   // Button Row
   QHBoxLayout* buttons   = new QHBoxLayout;

   QPushButton* pb_cancel = us_pushbutton( tr( "Cancel" ) );
   connect( pb_cancel, SIGNAL( clicked() ), SLOT( reject() ) );
   buttons->addWidget( pb_cancel );

   QPushButton* pb_accept = us_pushbutton( tr( "Select" ) );
   connect( pb_accept, SIGNAL( clicked() ), SLOT( select() ) );
   buttons->addWidget( pb_accept );

   main->addLayout( search );
   main->addWidget( tw );
   main->addLayout( buttons );
qDebug() << "gDBr: size" << size();

   resize( 600, 300 );
qDebug() << "gDBr: size" << size();
}
コード例 #23
0
ファイル: test_slist.c プロジェクト: nathangeffen/cagl
static void test_reverse(struct cag_test_series *tests)
{
	complex_slist l;
	it_complex_slist node1, node2;
	int failure = 0;
	int i;

	new_complex_slist(&l);
	populate_list(&l, 0, 5, 1);
	reverse_all_complex_slist(&l);
	node1 = beg_complex_slist(&l);
	for (i = 0, node2 = node1; node2 != NULL; node2 = node2->next, ++i)
		if (node2->value.real != i)
			failure = 1;
	CAG_TEST(*tests, failure == 0,
		 "cag_slist: reverse all");
	free_complex_slist(&l);
}
コード例 #24
0
ファイル: test_dlist.c プロジェクト: nathangeffen/cagl
static void test_reverse_iterator(struct cag_test_series *tests)
{
	int i = 4;
	complex_list l;
	rit_complex_list rt;

	new_complex_list(&l);
	populate_list(&l, 0, 5, 1);
	for(rt = rbeg_complex_list(&l); rt != rend_complex_list(&l);
	    rt = rt->next) {
		CAG_TEST(*tests, rt->value.real == i,
			 "cag_dlist: append correct value");
		CAG_TEST(*tests, rt->value.imag == -i,
			 "cag_dlist: append value");
		--i;
	}
	free_complex_list(&l);
}
コード例 #25
0
ファイル: test_dlist.c プロジェクト: nathangeffen/cagl
static void test_shuffle(struct cag_test_series *tests)
{
	complex_list a;
	it_complex_list it1, it2;
	int inorder = 1;

	new_complex_list(&a);
	populate_list(&a, 0, 52, 1);
	random_shuffle_complex_list(beg_complex_list(&a),
				     end_complex_list(&a));
	it1 = beg_complex_list(&a);
	CAG_TEST(*tests,
		 at_complex_list(it1, 0)->value.real != 0.0 &&
		 at_complex_list(it1, 51)->value.real != 51.0 &&
		 at_complex_list(it1, 25)->value.real != 25.0,
		"cag_dlist: random shuffle puts values out of order");
	sort_all_complex_list(&a);
	CAG_FOLD_ALL(complex_list, &a, it1, it2,
		     {
			     if (it2->value.real <= it1->value.real)
				     inorder = 0;
		     },
コード例 #26
0
ファイル: test_main.c プロジェクト: Cfretz244/systems
int main(int argc, char*argv[])
{
    int choice = atoi(argv[1]);

    
    

    
    printf("Choice: %d\n", choice);
    
    if(choice == 1){
        //1.  Normal SLInserts (@ beginning, middle, end of list)
        //a. integers
        SortedListPtr s = SLCreate(compareInts,destroyBasicTypeAlloc);
        int iarr[6] = {7,5,155,42,-1,6};
        if(populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,NULL,NULL,NULL) == 0){
            failure();
            return 1;
        }
        SortedListIteratorPtr iter = SLCreateIterator(s);
        iterprint_all(s,iter,INT); //prints 155 42 7 6 5 -1
        
        
    }else if(choice == 2){
        //b. doubles
        SortedListPtr s = SLCreate(compareDoubles,destroyBasicTypeAlloc);
        
        double darr[6] = {7.43,5.55,155.26,42.1,-1.5,6.7};
        if(populate_list(s,DOUBLE,sizeof(darr)/sizeof(double),NULL,darr,NULL,NULL) == 0){
            failure();
            return 1;
        }

        
        SortedListIteratorPtr iter = SLCreateIterator(s);
        iterprint_all(s,iter,DOUBLE); //prints 155.26 42.1 7.43 6.7 5.55 -1.5
        
        
    }else if(choice == 3){
        //c. strings
        SortedListPtr s = SLCreate(compareStrings,destroyBasicTypeAlloc);
        
        char *carr[6] = {"cat","dog","catamaran","apple","cormorant","zebra"};
        if(populate_list(s,STRING,6,0,0,carr,NULL) == 0){
            failure();
            return 1;
        }

        SortedListIteratorPtr iter = SLCreateIterator(s);
        iterprint_all(s,iter,STRING); //prints apple cat catamaran cormorant dog zebra
				      // should print zebra dog cormorant catamaran cat apple
        
        
        
    }else if(choice == 4){
        
        //d. structs
        SortedListPtr s = SLCreate(compareTestStructs,destroyBasicTypeAlloc);
        
        TestStruct strtarr[6];
        strtarr[0].field = 7;
        strtarr[1].field = 5;
        strtarr[2].field = 155;
        strtarr[3].field = 42;
        strtarr[4].field = -1;
        strtarr[5].field = 6;
        
        if(populate_list(s,STRUCT,6,0,0,0,strtarr) == 0){
            failure();
            return 1;
        }
        
        SortedListIteratorPtr iter = SLCreateIterator(s);
        iterprint_all(s,iter,STRUCT); //prints 155 42 7 6 5 -1
    
    }else if(choice == 5){
        //SLRemove nonexistent element
        SortedListPtr s = SLCreate(compareInts,destroyBasicTypeAlloc);
        int iarr[6] = {7,5,155,42,-1,6};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0,NULL);

        int toremove = 54;
        if (SLRemove(s,&toremove) != 0) {
            failure();
        }else{
            success();
        }
    }else if(choice == 6){
        //SLRemove existing element (no duplicates; didn't handle them anyway)
        SortedListPtr s = SLCreate(compareInts,destroyBasicTypeAlloc);
        int iarr[6] = {7,5,155,42,-1,6};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0,NULL);


        int toremove = 5;
        
        if (SLRemove(s,&toremove) != 0) {
            SortedListIteratorPtr iter = SLCreateIterator(s);
            iterprint_all_int(s,iter); //prints 155 42 7 6 -1
        }else{
            failure();
        }
        
    }else if(choice == 7){
        //Iterate on empty list
        //Should not fail
        SortedListPtr s = SLCreate(compareInts,destroyBasicTypeAlloc);
        SortedListIteratorPtr iter = SLCreateIterator(s);
        iterprint_all_int(s,iter);
    }else if (choice == 8){
        //SLInsert for item beyond iterator
        SortedListPtr s = SLCreate(compareInts,destroyBasicTypeAlloc);
        int iarr[6] = {7,5,155,42,-1,6};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0,NULL);
        
        SortedListIteratorPtr iter = SLCreateIterator(s);
        void *item = SLNextItem(iter);
        item = SLNextItem(iter);
        
        int *toins = malloc(sizeof(int));
        *toins = 4;
        SLInsert(s,toins);
        iterprint_all_int(s,iter); //prints 7 6 5 4 -1
        
    }else if(choice == 9){
        //Create multiple iterators on same list, interleave iterations.
        //Delete item between iterators.
        
        SortedListPtr s = SLCreate(compareInts,destroyBasicTypeAlloc);
        int iarr[6] = {7,5,155,42,-1,6};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0,NULL);
        
        SortedListIteratorPtr olditer = SLCreateIterator(s);
        
        SortedListIteratorPtr iter = SLCreateIterator(s);

        
        void *item;
        
        int i;
        for(i = 0; i < 2; i++){
            item = SLGetItem(olditer);//modify by lezi
            printf("%d ", *((int*)item));
	    item = SLNextItem(olditer);//modify by lezi
        } //prints 155 42
        printf("\n");

        for(i = 0; i < 4; i++){
            item = SLGetItem(iter); //modify by lezi
            printf("%d ", *((int*)item));
            item = SLNextItem(iter);//modify by lezi
        } //prints 155 42 7 6
        printf("\n");  
               
        int itoremove = 6;
        if (SLRemove(s,&itoremove) == 0) {
            failure();
            return 1;
        }
        
        item = SLGetItem(iter);  //prints 5  //modufy by lezi
        printf("%d\n", *((int*)item));
        item = SLGetItem(olditer);
        printf("%d\n", *((int*)item)); //prints 7  //modify by lezi
         
        
        iterprint_all_int(s,iter); //prints 5 -1
        
        iterprint_all_int(s,olditer); //prints 7 5 -1
        
    }else if(choice == 10){
        //SLRemove end element, iterator positioned on it
        
        SortedListPtr s = SLCreate(compareInts,destroyBasicTypeAlloc);
        int iarr[3] = {7,5,3};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0,NULL);

        
        SortedListIteratorPtr iter = SLCreateIterator(s);

        int x3 = 3;
        void *item = SLNextItem(iter);
        item = SLNextItem(iter);//iterator points to 3
        if(SLRemove(s,&x3) && SLNextItem(iter) == NULL){
            success();
        }else{
            failure();
        }
        
    }else if(choice == 11){ //TODO
        //SLRemove element in middle, iterator positioned on it
        SortedListPtr s = SLCreate(compareInts,destroyBasicTypeAlloc);
        int iarr[3] = {7,5,3};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0,NULL);
        
        SortedListIteratorPtr iter = SLCreateIterator(s);
        void *item = SLNextItem(iter);
        
        int x1 = 5;
        if(SLRemove(s,&x1) && *((int*)SLNextItem(iter)) == 3 &&
           ((int*)SLNextItem(iter)) == NULL){
            success();
        }else{
            failure();
        }
        
        
        
        
    }else if(choice == 12){
        //SLRemove element positioned immediately after element iterator is pointing to
        SortedListPtr s = SLCreate(compareInts,destroyBasicTypeAlloc);
        int iarr[6] = {7,5,155,42,-1,6};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0,NULL);
        

        SortedListIteratorPtr iter = SLCreateIterator(s);
        void *item = SLNextItem(iter);
        item = SLNextItem(iter);
        int x1 = 6;
        if(SLRemove(s,&x1) && *((int*)SLGetItem(iter)) == 7 //modify by lezi
           && *((int*)SLNextItem(iter)) == 5
           && *((int*)SLNextItem(iter)) == -1
           && ((int*)SLNextItem(iter)) == NULL){
            success();
        }else{
            failure();
        }
        
    }else if(choice == 13){
        //Add item between recently returned element and element about to be returned.
        SortedListPtr s = SLCreate(compareInts,destroyBasicTypeAlloc);
        int iarr[3] = {7,5,3};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0,NULL);
        
        SortedListIteratorPtr iter = SLCreateIterator(s);
        void *item = SLNextItem(iter);
        item = SLNextItem(iter);//point to 3 now
        int *x4 = malloc(sizeof(int));
        *x4 = 4;
        SLInsert(s,x4);
        
        iterprint_all_int(s,iter); //prints 3
        

        
        
    }else if(choice == 14){
        //Add item to head and middle, after iterator has been created //modify by Lezi
        SortedListPtr s = SLCreate(compareInts,destroyBasicTypeAlloc);
        int iarr[3] = {7,5,3};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0,NULL);
        
        SortedListIteratorPtr iter = SLCreateIterator(s);
        int *toinsert = malloc(sizeof(int));
        *toinsert = 8;
        SLInsert(s,toinsert);
        int *toinsert1 = malloc(sizeof(int));
  	*toinsert1 = 4; // add by lezi
	SLInsert(s,toinsert1);//add by lezi
        
        iterprint_all_int(s,iter); //prints 7 5 4 3 //modify by lezi
    }else if(choice == 15){
        
        //Add item to tail after all items have been returned by iterator.
        SortedListPtr s = SLCreate(compareInts,destroyBasicTypeAlloc);
        int iarr[3] = {7,5,3};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0,NULL);
        
        SortedListIteratorPtr iter = SLCreateIterator(s);
        void *item;
        while((item = SLNextItem(iter)) != NULL);
        
        
        int *toins = malloc(sizeof(int));
        *toins = -1;
        SLInsert(s,toins);
        
        if(SLGetItem(iter) == NULL){ //modify by lezi
            success();
        }else{
            failure();
        }
    }else{
        printf("Bad input\n");
    }
    
    
    return 0;
    
}
コード例 #27
0
ファイル: UNinstaller.c プロジェクト: pinchyCZN/Uninstaller
LRESULT CALLBACK MainDlg(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	static HWND grippy=0;
	static int col=0,dir=0;

#ifdef _DEBUG
	// if(FALSE)
//	if(message!=0x200&&message!=0x84&&message!=0x20&&message!=WM_ENTERIDLE)
	if(msg!=WM_MOUSEFIRST&&msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE&&msg!=WM_DRAWITEM
		&&msg!=WM_CTLCOLORBTN&&msg!=WM_CTLCOLOREDIT)
	//if(msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE)
	{
		static DWORD tick=0;
		if((GetTickCount()-tick)>500)
			printf("--\n");
		printf("*");
		print_msg(msg,lparam,wparam);
		tick=GetTickCount();
	}
#endif	
	switch(msg)
	{
	case WM_INITDIALOG:
		hlistview=CreateWindow(WC_LISTVIEW,"",WS_TABSTOP|WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE|LVS_REPORT|LVS_SHOWSELALWAYS,
                                     0,0,
                                     0,0,
                                     hwnd,
                                     IDC_LIST1,
                                     ghinstance,
                                     NULL);
		ListView_SetExtendedListViewStyle(hlistview,LVS_EX_FULLROWSELECT);		
		populate_list(hlistview,TRUE);
		sort_listview(hlistview,dir,col);
		grippy=create_grippy(hwnd);
		PostMessage(hwnd,WM_SIZE,0,0);
		//dump_main(hwnd);
		break;
	case WM_HELP:
		show_main_help(hwnd,(HELPINFO *)lparam);
		return TRUE;
		break;
	case WM_SIZE:
		grippy_move(hwnd,grippy);
		resize_main(hwnd);
		break;
	case WM_CONTEXTMENU:
		break;
	case WM_NOTIFY:
		{
			NMHDR *nmhdr=lparam;
			if(nmhdr!=0 && nmhdr->idFrom==IDC_LIST1){
				LV_HITTESTINFO lvhit={0};
				switch(nmhdr->code){
				case NM_DBLCLK:
					GetCursorPos(&lvhit.pt);
					ScreenToClient(nmhdr->hwndFrom,&lvhit.pt);
					if(ListView_SubItemHitTest(nmhdr->hwndFrom,&lvhit)>=0)
						do_regjump(hlistview);
					break;
				case NM_RCLICK:
				case NM_CLICK:
					GetCursorPos(&lvhit.pt);
					ScreenToClient(nmhdr->hwndFrom,&lvhit.pt);
					if(ListView_SubItemHitTest(nmhdr->hwndFrom,&lvhit)>=0){
					}
					printf("item = %i\n",lvhit.iSubItem);
					break;
				case LVN_ITEMCHANGED:
					{
					}
					break;
				case LVN_KEYDOWN:
					{
					}
					break;
				case LVN_COLUMNCLICK:
					{
						NMLISTVIEW *nmlv=lparam;
						col=nmlv->iSubItem;
						dir=!dir;
						sort_listview(hlistview,dir,col);
					}
					break;
				}
			}
		}
		break;

	case WM_VKEYTOITEM:
		switch(LOWORD(wparam)){
		case '0':case '1':case'2':case'3':case'4':case'5':
			break;
		}
		return -1;
		break;
	case WM_CHARTOITEM:
		switch(wparam){
		case 'z':
			break;
		case 'x':
			break;
		}
		break;
	case WM_COMMAND:
		switch(LOWORD(wparam)){
		case IDC_REFRESH:
			{
			RECT rect={0};
			RECT newrect={0};
			int dx,dy,mark;
			ListView_GetItemRect(hlistview,0,&rect,LVIR_BOUNDS);
			mark=ListView_GetSelectionMark(hlistview);

			populate_list(hlistview,FALSE);
			sort_listview(hlistview,dir,col);

			ListView_GetItemRect(hlistview,0,&newrect,LVIR_BOUNDS);
			dx=-rect.left+newrect.left;
			dy=-rect.top+newrect.top;
			ListView_Scroll(hlistview,dx,dy);
			if(mark>=0)
				ListView_SetItemState(hlistview,mark,LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED);
				SetFocus(hlistview);
			}
			break;
		case IDC_INFO:
			do_regjump(hlistview);
			break;
		case IDOK:
			break;
		case IDCANCEL:
			DestroyWindow(hwnd);
			PostQuitMessage(0);
			return TRUE;
			break;
		}
		break;
	case WM_QUERYENDSESSION:
		SetWindowLong(hwnd,DWL_MSGRESULT,TRUE); //ok to end session
		return TRUE;
	case WM_ENDSESSION:
		if(wparam){
			SetWindowLong(hwnd,DWL_MSGRESULT,0);
			DestroyWindow(hwnd);
			PostQuitMessage(0);
			return TRUE;
		}
		break;
	case WM_CLOSE:
		DestroyWindow(hwnd);
		PostQuitMessage(0);
		return TRUE;
		break;
	}
	return 0;
}
コード例 #28
0
ファイル: test_dlist.c プロジェクト: nathangeffen/cagl
static void test_insert_order(struct cag_test_series *tests)
{
	struct complex c = {3, -3};
	complex_list l;
	it_complex_list it;
	size_t d;
	double t = -20.0;
	int inorder = CAG_TRUE;

	new_complex_list(&l);
	c.real = 6;
	insert_gt_complex_list(&l, beg_complex_list(&l), c);
	c.real = 0;
	insert_gt_complex_list(&l, beg_complex_list(&l), c);
	c.real = 4;
	insert_gt_complex_list(&l, beg_complex_list(&l), c);
	c.real = 8;
	insert_gt_complex_list(&l, beg_complex_list(&l), c);
	c.real = 2;
	insert_gt_complex_list(&l, beg_complex_list(&l), c);
	for (it = beg_complex_list(&l); it != end_complex_list(&l);
	     it = it->next)
		if (it->value.real < t) {
			inorder = CAG_FALSE;
			break;
		} else
			t = it->value.real;
	d = distance_complex_list(beg_complex_list(&l), end_complex_list(&l));
	CAG_TEST(*tests,  d == 5 && inorder == CAG_TRUE,
		 "cag_dlist: insert ordered values");
	c.real = 3.0;
	it = insert_gt_complex_list(&l, beg_complex_list(&l), c);
	CAG_TEST(*tests, it->prev->value.real == 2.0 &&
		 it->value.real == 3.0 &&
		 it->next->value.real == 4.0 &&
		 distance_complex_list(beg_complex_list(&l),
				       end_complex_list(&l)) == d+1,
		 "cag_dlist: insert gt middle");
	c.real = 20.0;
	it = insert_gt_complex_list(&l, beg_complex_list(&l), c);
	CAG_TEST(*tests, it->prev->value.real == 8.0 &&
		 it->value.real == 20.0 &&
		 distance_complex_list(beg_complex_list(&l),
				       end_complex_list(&l)) == d+2,
		 "cag_dlist: insert gt end");
	c.real = -1.0;
	it = insert_gt_complex_list(&l, beg_complex_list(&l), c);
	CAG_TEST(*tests, it == beg_complex_list(&l) &&
		 it->next->value.real == 0.0 &&
		 it->value.real == -1.0 &&
		 distance_complex_list(beg_complex_list(&l),
				       end_complex_list(&l)) == d+3,
		 "cag_dlist: insert gt beginning");
	c.real = -0.5;
	c.imag = 10.0;
	it = insert_gt_complex_list(&l, beg_complex_list(&l), c);
	CAG_TEST(*tests, it->prev->value.real == -1.0 &&
		 it->value.real == -0.5 &&
		 distance_complex_list(beg_complex_list(&l),
				       end_complex_list(&l)) == d+4,
		 "cag_dlist: insert gt one beyond beginning");
	c.imag = 5.0;
	it = insert_gt_complex_list(&l, beg_complex_list(&l), c);
	CAG_TEST(*tests, it->prev->value.real == -1.0 &&
		 it->value.real == -0.5 &&
		 distance_complex_list(beg_complex_list(&l),
				       end_complex_list(&l)) == d+5,
		 "cag_dlist: insert gt duplicate stable");
	it = insert_gteq_complex_list(&l, beg_complex_list(&l), c);
	CAG_TEST(*tests, it->prev->value.real == -0.5 &&
		 it->value.real == -0.5 &&
		 distance_complex_list(beg_complex_list(&l),
				       end_complex_list(&l)) == d+6,
		 "cag_dlist: insert gt duplicate unstable");
	free_complex_list(&l);

	new_complex_list(&l);
	populate_list(&l, 10, 0, -2);
	d = distance_complex_list(beg_complex_list(&l), end_complex_list(&l));
	c.real = 3.0;
	c.imag = 1.0;
	it = insert_lt_complex_list(&l, beg_complex_list(&l), c);
	CAG_TEST(*tests, it->next->value.real == 2.0 &&
		 it->value.real == 3.0 &&
		 it->prev->value.real == 4.0 &&
		 distance_complex_list(beg_complex_list(&l),
				       end_complex_list(&l)) == d+1,
		 "cag_dlist: insert lt middle");
	c.imag = 2.0;
	it = insert_lt_complex_list(&l, beg_complex_list(&l), c);
	CAG_TEST(*tests, it->next->value.real == 3.0 &&
		 it->value.real == 3.0 &&
		 it->prev->value.real == 4.0 &&
		 distance_complex_list(beg_complex_list(&l),
				       end_complex_list(&l)) == d+2,
		 "cag_dlist: insert lt duplicate stable");
	c.imag = 3.0;
	it = insert_lteq_complex_list(&l, beg_complex_list(&l), c);
	CAG_TEST(*tests, it->prev->value.real == 3.0 &&
		 it->value.real == 3.0 &&
		 it->next->value.real == 2.0 &&
		 distance_complex_list(beg_complex_list(&l),
				       end_complex_list(&l)) == d+3,
		 "cag_dlist: insert lt duplicate unstable");
	free_complex_list(&l);
}
コード例 #29
0
int main(int argc, char*argv[])
{
    int choice = atoi(argv[1]);


    printf("Choice: %d\n", choice);

    if(choice == 1){
        //1.  Normal SLInserts (@ beginning, middle, end of list)
        //a. integers
        SortedListPtr s = SLCreate(compareInts);
        int iarr[6] = {7,5,155,42,-1,6};
        if(populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,NULL,NULL) == 0){
            failure();
            return 1;
        }
        SortedListIteratorPtr iter = SLCreateIterator(s);
        iterprint_all(s,iter,INT); //prints 155 42 7 6 5 -1


    }else if(choice == 2){
        //b. doubles
        SortedListPtr s = SLCreate(compareDoubles);

        double darr[6] = {7.43,5.55,155.26,42.1,-1.5,6.7};
        if(populate_list(s,DOUBLE,sizeof(darr)/sizeof(double),NULL,darr,NULL) == 0){
            failure();
            return 1;
        }


        SortedListIteratorPtr iter = SLCreateIterator(s);
        iterprint_all(s,iter,DOUBLE); //prints 155.26 42.1 7.43 6.7 5.55 -1.5


    }else if(choice == 3){
        //c. strings
        SortedListPtr s = SLCreate(compareStrings);

        char *carr[6] = {"cat","dog","catamaran","apple","cormorant","zebra"};
        if(populate_list(s,STRING,6,0,0,carr) == 0){
            failure();
            return 1;
        }

        SortedListIteratorPtr iter = SLCreateIterator(s);
        iterprint_all(s,iter,STRING); //prints apple cat catamaran cormorant dog zebra



    }else if(choice == 4){
        //SLInsert on null list;
        int x = 5;
        if(SLInsert(NULL, &x) == 0){
            success();
        }else{
            failure();
        }
    }else if(choice == 5){
        //SLInsert null object
        SortedListPtr s = SLCreate(compareDoubles);

        if (SLInsert(s,NULL) == 0){
            success();
        }else{
            failure();
        }

    }else if(choice == 6){
        //SLRemove nonexistent element
        SortedListPtr s = SLCreate(compareInts);
        int iarr[6] = {7,5,155,42,-1,6};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0);

        int toremove = 54;
        if (SLRemove(s,&toremove) != 0) {
            failure();
        }else{
            success();
        }
    }else if(choice == 7){
        //SLRemove existing element (no duplicates; didn't handle them anyway)
        SortedListPtr s = SLCreate(compareInts);
        int iarr[6] = {7,5,155,42,-1,6};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0);


        int toremove = 5;

        if (SLRemove(s,&toremove) != 0) {
            SortedListIteratorPtr iter = SLCreateIterator(s);
            iterprint_all_int(s,iter); //prints 155 42 7 6 -1
        }else{
            failure();
        }

    }else if(choice == 8){
        //Iterate on empty list
        SortedListPtr s = SLCreate(compareInts);
        SortedListIteratorPtr iter = SLCreateIterator(s);
        iterprint_all_int(s,iter);
        //TODO: Separate into a) create iterator b) print empty list
    }else if(choice == 9){
        //Create new iterator on list, destroy old one mid-iteration
        SortedListPtr s = SLCreate(compareInts);
        int iarr[6] = {7,5,155,42,-1,6};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0);



        SortedListIteratorPtr olditer = SLCreateIterator(s);
        void *olditem = SLNextItem(olditer);
        olditem = SLNextItem(olditer);
        SortedListIteratorPtr iter = SLCreateIterator(s);
        SLDestroyIterator(olditer);

        iterprint_all_int(s,iter); //prints 155 42 7 6 5 -1
    }else if(choice == 10){ //TODO
        //Create multiple iterators on same list, interleave iterations.

        SortedListPtr s = SLCreate(compareInts);
        int iarr[6] = {7,5,155,42,-1,6};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0);

        SortedListIteratorPtr olditer = SLCreateIterator(s);

        SortedListIteratorPtr iter = SLCreateIterator(s);


        void *item;

        item = SLNextItem(olditer);
        printf("%d ", *((int*)item));
        item = SLNextItem(olditer);
        printf("%d ", *((int*)item));  //prints 155 42

        item = SLNextItem(iter);
        printf("%d ", *((int*)item));
        item = SLNextItem(iter);
        printf("%d ", *((int*)item));
        item = SLNextItem(iter);
        printf("%d ", *((int*)item)); //prints 155 42 7


        item = SLNextItem(iter);  //prints 6
        printf("%d ", *((int*)item));
        item = SLNextItem(olditer);
        printf("%d ", *((int*)item)); //prints 7


        iterprint_all_int(s,iter); //prints 5 -1

        iterprint_all_int(s,olditer); //prints 6 5 -1

    }else if(choice == 11){
        //SLRemove end element, iterator positioned on it

        SortedListPtr s = SLCreate(compareInts);
        int iarr[3] = {7,5,3};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0);


        SortedListIteratorPtr iter = SLCreateIterator(s);

        int x3 = 3;
        void *item = SLNextItem(iter);
        item = SLNextItem(iter);
        if(SLRemove(s,&x3) && SLNextItem(iter) == NULL){
            success();
        }else{
            failure();
        }

    }else if(choice == 12){ //TODO
        //SLRemove beginning element, iterator positioned on it

        SortedListPtr s = SLCreate(compareInts);
        int iarr[3] = {7,5,3};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0);

        SortedListIteratorPtr iter = SLCreateIterator(s);

        int x1 = 7;
        if(SLRemove(s,&x1) && *((int*)SLNextItem(iter)) == 5 &&
           *((int*)SLNextItem(iter)) == 3 &&
           ((int*)SLNextItem(iter)) == NULL){
            success();
        }else{
            failure();
        }
    }else if(choice == 13){ //TODO
        //SLRemove element in middle, iterator positioned on it
        SortedListPtr s = SLCreate(compareInts);
        int iarr[3] = {7,5,3};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0);

        SortedListIteratorPtr iter = SLCreateIterator(s);
        void *item = SLNextItem(iter);

        if (*((int*)item) != 7) {
            failure();
            return 1;
        }

        int x1 = 5;
        if(SLRemove(s,&x1) && *((int*)SLNextItem(iter)) == 3 &&
           ((int*)SLNextItem(iter)) == NULL){
            success();
        }else{
            failure();
        }
    }else if(choice == 14){
        //Add element after iterator
        SortedListPtr s = SLCreate(compareInts);
        int iarr[3] = {7,5,3};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0);

        SortedListIteratorPtr iter = SLCreateIterator(s);
        void *item = SLNextItem(iter);
        item = SLNextItem(iter);
        int x4 = 4;
        SLInsert(s,&x4); //prints 4 3

        iterprint_all_int(s,iter);


    }else if(choice == 15){
        //Remove element after iterator
        SortedListPtr s = SLCreate(compareInts);
        int iarr[4] = {7,5,3,4};
        populate_list(s,INT,sizeof(iarr)/sizeof(int),iarr,0,0);


        SortedListIteratorPtr iter = SLCreateIterator(s);
        void *item = SLNextItem(iter);
        item = SLNextItem(iter);
        int x4 = 4;
        if(SLRemove(s,&x4)){
            iterprint_all_int(s,iter); //prints 3
        }else{
            failure();
        }
    }else{
        printf("Bad input\n");
    }


    return 0;

}