Beispiel #1
0
static void
test_bt_change_log_nested_groups (BT_TEST_ARGS)
{
  BT_TEST_START;
  GST_INFO ("-- arrange --");
  BtChangeLog *cl = bt_change_log_new ();
  BtTestChangeLogger *tcl = bt_test_change_logger_new ();

  // make 1 change group
  bt_change_log_start_group (cl);
  make_change (cl, tcl, "new_data 2", "new_data 0");
  make_change (cl, tcl, "inc_data 0", "dec_data 0");
  bt_change_log_start_group (cl);
  make_change (cl, tcl, "inc_data 1", "dec_data 1");
  bt_change_log_end_group (cl);
  bt_change_log_end_group (cl);

  // undo & verify
  bt_change_log_undo (cl);
  fail_unless (tcl->data == NULL, NULL);
  ck_assert_int_eq (tcl->data_size, 0);

  // redo & verify
  bt_change_log_redo (cl);
  fail_unless (tcl->data != NULL, NULL);
  ck_assert_int_eq (tcl->data_size, 2);
  ck_assert_int_eq (tcl->data[0], 1);
  ck_assert_int_eq (tcl->data[1], 1);

  GST_INFO ("-- cleanup --");
  g_object_unref (tcl);
  g_object_unref (cl);
  BT_TEST_END;
}
Beispiel #2
0
void make_change(int i,int j,int pos,int sum){

  if(sum==0){
	 count++;
	print_array(pos);
	return;
  }

  if(i>j || i>n-1)
  return;

  if(sum<0)
  return;





	ot[pos]=a[i];

make_change(i,j,pos+1,sum-a[i]);
make_change(i+1,j,pos,sum);

//make_change(i+1,j,pos+1,sum);





}
Beispiel #3
0
// test double undo/redo actions
static void
test_bt_change_log_two_changes (BT_TEST_ARGS)
{
  BT_TEST_START;
  GST_INFO ("-- arrange --");
  BtChangeLog *cl = bt_change_log_new ();
  BtTestChangeLogger *tcl = bt_test_change_logger_new ();

  /* act (make 2 changes) */
  make_change (cl, tcl, "set_val 5", "set_val 0");
  make_change (cl, tcl, "set_val 10", "set_val 5");

  // undo & verify
  bt_change_log_undo (cl);
  ck_assert_int_eq (tcl->val, 5);

  bt_change_log_undo (cl);
  ck_assert_int_eq (tcl->val, 0);

  // redo & verify
  bt_change_log_redo (cl);
  ck_assert_int_eq (tcl->val, 5);

  bt_change_log_redo (cl);
  ck_assert_int_eq (tcl->val, 10);

  GST_INFO ("-- cleanup --");
  g_object_unref (tcl);
  g_object_unref (cl);
  BT_TEST_END;
}
Beispiel #4
0
int make_change(int n)
{
	int i=0,ans=0;
	if (n<0)
		return -1;
	if (n==0)
		return 0;
	if (table[n]!=0)
		return table[n];
	table[n]=1+make_change(n-denominations[0])	;
	for(i=0;i<3;i++)
	{
		table[n]=min(table[n],make_change(n-denominations[i]));
	}
	return table[n];
}
Beispiel #5
0
int main(void) 
{
	int count=0;
	count=make_change(10);
	printf("%d",count);
	int i=0;
	for(;i<10;i++)
		printf("%d",table[i]);
	return 0;
}
Beispiel #6
0
int make_change(int coins[], int change)
{
    int i;
    for (i = 0; i < N; i++)
    {
        if (coins[i] == change)
            return 1;
    }

    int min_coins = change; // all with 1 cent.
    int j;
    for(j = 1; j <= change / 2; j++)
    {
        int this_coins = make_change(coins, j) + make_change(coins, change - j);
        if(this_coins < min_coins)
            min_coins = this_coins;
    }

    return min_coins;
}
Beispiel #7
0
int main()
try {
    auto denoms = read_denominations();
    sort(denoms, greater<double>{});
    auto amount = read_amount();
    auto change = make_change(denoms, amount);
    print_change(denoms, change);
}
catch (runtime_error& e) {
    cerr << "runtime error: " << e.what() << '\n';
    return 1;
}
Beispiel #8
0
// test truncating the undo/redo stack
static void
test_bt_change_log_undo_redo_state_stack_trunc (BT_TEST_ARGS)
{
  BT_TEST_START;
  GST_INFO ("-- arrange --");
  BtChangeLog *cl = bt_change_log_new ();
  BtTestChangeLogger *tcl = bt_test_change_logger_new ();
  gboolean can_undo, can_redo;

  GST_INFO ("-- act --");
  make_change (cl, tcl, "set_val 5", "set_val 0");
  bt_change_log_undo (cl);
  make_change (cl, tcl, "set_val 10", "set_val 0");
  g_object_get (cl, "can-undo", &can_undo, "can-redo", &can_redo, NULL);

  GST_INFO ("-- assert --");
  fail_unless (can_undo, NULL);
  fail_unless (!can_redo, NULL);

  GST_INFO ("-- cleanup --");
  g_object_unref (tcl);
  g_object_unref (cl);
  BT_TEST_END;
}
Beispiel #9
0
// test single undo/redo actions
static void
test_bt_change_log_single_change_after_undo (BT_TEST_ARGS)
{
  BT_TEST_START;
  GST_INFO ("-- arrange --");
  BtChangeLog *cl = bt_change_log_new ();
  BtTestChangeLogger *tcl = bt_test_change_logger_new ();

  GST_INFO ("-- act --");
  make_change (cl, tcl, "set_val 5", "set_val 0");
  bt_change_log_undo (cl);

  GST_INFO ("-- assert --");
  ck_assert_int_eq (tcl->val, 0);

  GST_INFO ("-- cleanup --");
  g_object_unref (tcl);
  g_object_unref (cl);
  BT_TEST_END;
}
Beispiel #10
0
int make_change(int n, int choice){
  int next_choice = 0;
  switch(choice){
    case 25:
      next_choice = 10;
      break;
    case 10:
      next_choice = 5;
      break;
    case 5:
      next_choice = 1;
      break;
    case 1:
      return 1;// !!!
  }
  int ways = 0;
  for(int i = 0; i * choice <= n; i++){
    ways += make_change(n - i * choice, next_choice);
  }
  return ways;

}
Beispiel #11
0
void main(){

make_change(0,n-1,0,sum);
 printf("m%d",count);
}
Beispiel #12
0
int main(){
  int n = 100;
  cout<<make_change(n, 25)<<endl;// from 25 cents to make change
  cout<<make_change1(0, n, 25)<<endl;
}