Exemplo n.º 1
0
//find angles between vectors
static void vector_find_angle_VectorWithCoordThreeAndFourAndVectorsWithCoordinatesFourAndFive_notMinusOne(){
    vector_t * vec1 = vector_test(3,4);
    vector_t * vec2 = vector_test(4,5);
    assert_int_not_equal(vector_find_angle(vec1,vec2),-1);
     vector_free(vec1);
    vector_free(vec2);
}
Exemplo n.º 2
0
//scalar products of vectors
static void vector_scalar_product_TwoVectorsWithCoordinatesFourAndFive_IntegerFourtyOne(void ** state){
    vector_t * vec1 = vector_test(4,5);
    vector_t * vec2 = vector_test(4,5);
    assert_int_equal(vector_scalar_product(vec1,vec2),41);
    vector_free(vec1);
    vector_findLength(vec2);

}
Exemplo n.º 3
0
//add vectors
static void vector_add_VectorsWithCoordinatesFourAndFive_VectorWithCoordEigthAndTen(void ** state)
{
    vector_t * vec1 = vector_test(4,5);
    vector_t * vec2 = vector_test(4,5);

    assert_int_equal(vector_getCoord(vector_add(vec1,vec2),0),8);
    assert_int_equal(vector_getCoord(vector_add(vec1,vec2),1),10);
    vector_free(vec1);
    vector_free(vec2);

}
Exemplo n.º 4
0
//multiplication vector and number
static void vector_mult_byNumber_VectorWithCoordTenAndTwentyIntegerTwo_VectorWithCoordTwentyAndForty(void ** state){
    vector_t * vec1 = vector_test(10,20);
    assert_int_equal(vector_getCoord(vector_mult_byNumber(vec1,2),0),20);
        assert_int_equal(vector_getCoord(vector_mult_byNumber(vec1,2),1),40);

        vector_free(vec1);
}
Exemplo n.º 5
0
int main()
{
	multi_file_test();

	vector_test();
	list_test();
	deque_test();
	adapter_test();
	sort_test();
	string_test();
	return 0;
}
Exemplo n.º 6
0
//multiplication matrix on vector
static void matrix_mult_vector_MatrixWithElementsSixTenTwoElevenVectorWithCoordinatesFiveSeven_MatrixWithElementsThirtyFiftyFourteenSeventyseven(void ** state)
{

    matrix_t * mat1 =  matrix_test(6,10,2,11);
    vector_t * vec1 = vector_test(5,7);
    assert_int_equal(matrix_getElementOfMatrix(matrix_mult_vector(mat1,vec1),0,0),30);
    assert_int_equal(matrix_getElementOfMatrix(matrix_mult_vector(mat1,vec1),0,1),50);
    assert_int_equal(matrix_getElementOfMatrix(matrix_mult_vector(mat1,vec1),1,0),14);
    assert_int_equal(matrix_getElementOfMatrix(matrix_mult_vector(mat1,vec1),1,1),77);
    matrix_free(mat1);
    vector_free(vec1);
}
Exemplo n.º 7
0
int main(int argc, const char * argv[])
{
    const std::size_t items = 10;
    std::srand(static_cast<unsigned>(std::time(0)));
    
    std::cout << "Vector test" << "\n";
    vector_test(items);
    std::cout << "List test" << "\n";
    list_test(items);
    std::cout << "Mixed test" << "\n";
    mixed_test(items);
    
    return 0;
}
Exemplo n.º 8
0
void part_two_describe()
{

	cout<<"******************************************"<<endl;
	cout<<"*         第二章 C++ STL泛型编程         *"<<endl;
	cout<<"******************************************"<<endl;
	cout<<"*(1) 一个简单的测试案例                 *"<<endl;
	cout<<"*(2) vector向量容器                     *"<<endl;
	cout<<"*(3) string基本字符系列容器             *"<<endl;
	cout<<"*(4) set集合容器                        *"<<endl;
	cout<<"*(5) mutiset多种集合容器                *"<<endl;
	cout<<"*(6) map映照容器                        *"<<endl;
	cout<<"*(7) mutimap多重映照容器                *"<<endl;
	cout<<"*(8) deque双端队列容器                  *"<<endl;
	cout<<"*(9) list双向链表容器                   *"<<endl;
	cout<<"*(10)bitset位集合容器                   *"<<endl;
	cout<<"*(11)stack堆栈容器                      *"<<endl;
	cout<<"*(12)queue队列容器                      *"<<endl;
	cout<<"*(13)priority_queue优先队列容器         *"<<endl;
	cout<<"******************************************"<<endl;
	cout<<"请输入对应的编号进入相应的题目(返回上级输入0):"<<endl;
	int num;
	cin>>num;
	while(num!=0&&num!=1&&num!=2&&num!=3&&num!=4&&num!=5&&num!=6&&num!=7&&num!=8&&num!=9&&num!=10&&num!=11&&num!=12&&num!=13){
		cout<<"编号不存在"<<endl;
		cout<<"请输入对应的编号进入相应的题目(返回上级输入0):"<<endl;
		cin>>num;
	}
	switch(num){
		case 0:total_describe();break;	
		case 1:test();break;
		case 2:vector_test();break;
		case 3:string_test();break;
		case 4:set_test();break;
		case 5:multiset_test();break;
		case 6:map_test();break;
		case 7:multimap_test();break;
		case 8:deque_test();break;
		case 9:list_test();break;
		case 10:bitset_test();break;
		case 11:stack_test();break;
		case 12:queue_test();break;
		case 13:priority_queue_test();break;
		}
	}
Exemplo n.º 9
0
int main() {
	vector_test();
	string_test();
	//Vector<int,3> b({-1,4,2});
	//cout << (a+b).toString() << endl;
}
Exemplo n.º 10
0
int main(int argc, char* argv[]) {

  // timing mechanism
  clock_t start, before_operation, after_operation, end;
  start = clock();

  // parse the command line arguments
  if (argc != 5 && argc != 7) {
    std::cerr << "Error: wrong number of arguments." << std::endl;
    usage();
  }
  std::string data_structure = argv[1];
  std::string operation = argv[2];
  std::string input = argv[3];
  int input_count = -1;
  int string_length = -1;
  std::string output_file;
  if (input == "random") {
    assert (argc == 7);
    input_count = atoi(argv[4]);
    string_length = atoi(argv[5]);
    output_file = argv[6];
  } else {
    assert (argc == 5);
    output_file = argv[4];
  } 

  // load the data into a heap-allocated, C-style array
  std::string *input_data;
  load_data(input,input_data,input_count,string_length);

  // prepare space for the answer (at most the same size as the input!)
  std::string *output_data = new std::string[input_count];
  int output_count;

  // mark the time before we start
  before_operation = clock();

  // perform the operation
  if (data_structure == "vector") 
    vector_test(input_data,input_count,operation,output_data,output_count);
  else if (data_structure == "list")
    list_test(input_data,input_count,operation,output_data,output_count);
  else if (data_structure == "bst")  // STL set or map
    bst_test(input_data,input_count,operation,output_data,output_count);
  else if (data_structure == "priority_queue")
    priority_queue_test(input_data,input_count,operation,output_data,output_count);
  else if (data_structure == "hash_table")  // STL unordered_set or unordered_map
    hash_table_test(input_data,input_count,operation,output_data,output_count);
  else {
    std::cerr << "Error: unknown data structure: " << data_structure << std::endl;
    usage();
    exit(0);
  }

  // mark the time once we are done
  after_operation = clock();

  // output the data
  std::ofstream ostr(output_file.c_str());
  for (int i = 0; i < output_count; i++) {
    ostr << output_data[i] << std::endl;
  }
  // cleanup
  delete [] input_data;
  delete [] output_data;

  // print statistics
  end = clock();
  double load_time = double(before_operation-start)/CLOCKS_PER_SEC;
  double operation_time = double(after_operation-before_operation)/CLOCKS_PER_SEC;
  double output_time = double(end-after_operation)/CLOCKS_PER_SEC;
  std::cout << "load time:          " << load_time << std::endl;
  std::cout << "operation time:     " << operation_time << std::endl;
  std::cout << "output time:        " << output_time << std::endl;
  std::cout << "input/output ratio: " << input_count << ":" << output_count << std::endl;
  return 0;
}
Exemplo n.º 11
0
main() 
{
	vector_test();
}
Exemplo n.º 12
0
//find length of vector
static void vector_findLength_VectorWithCoordThreeAndFour_IntegerFive(void ** state)
{
    vector_t * vec1 = vector_test(3,4);
    assert_int_equal(vector_findLength(vec1),5);
    vector_free(vec1);
}