예제 #1
0
void test_shift() {
  int default_value = 88;
  int_vector_type * v = int_vector_alloc(0,default_value);

  int_vector_append(v , 1 );
  int_vector_append(v , 2 );
  int_vector_append(v , 3 );
  test_assert_int_equal( 1 , int_vector_iget( v , 0 ));
  test_assert_int_equal( 2 , int_vector_iget( v , 1 ));
  test_assert_int_equal( 3 , int_vector_iget( v , 2 ));

  int_vector_rshift(v , 3 );
  test_assert_int_equal( 6 , int_vector_size( v ));
  test_assert_int_equal( default_value , int_vector_iget( v , 0 ));
  test_assert_int_equal( default_value , int_vector_iget( v , 1 ));
  test_assert_int_equal( default_value , int_vector_iget( v , 2 ));
  test_assert_int_equal( 1 , int_vector_iget( v , 3 ));
  test_assert_int_equal( 2 , int_vector_iget( v , 4 ));
  test_assert_int_equal( 3 , int_vector_iget( v , 5 ));

  int_vector_lshift(v,4);
  test_assert_int_equal( 2 , int_vector_size( v ));
  test_assert_int_equal( 2 , int_vector_iget( v , 0 ));
  test_assert_int_equal( 3 , int_vector_iget( v , 1 ));
  
  int_vector_free( v );
}
예제 #2
0
void int_vector_lshift(int_vector_type * vector , int shift) {
  int_vector_rshift( vector , -shift);
}