Esempio n. 1
0
TEST(math, hypotl) {
  ASSERT_DOUBLE_EQ(5.0L, hypotl(3.0L, 4.0L));
}
Esempio n. 2
0
TEST(ParticleCUDA, Random) {
	rand2_seed(1080);
	ASSERT_DOUBLE_EQ(rand2(), 0.6554163483485531);
	ASSERT_DOUBLE_EQ(rand2(), 0.2009951854518572);
	ASSERT_DOUBLE_EQ(rand2(), 0.8936223876466522);
	ASSERT_DOUBLE_EQ(rand2(), 0.2818865431288053);
	ASSERT_DOUBLE_EQ(rand2(), 0.5250003829714993);
	ASSERT_DOUBLE_EQ(rand2(), 0.3141267749950177);
	ASSERT_DOUBLE_EQ(rand2(), 0.4446156782993733);
	ASSERT_DOUBLE_EQ(rand2(), 0.2994744556282315);
	ASSERT_DOUBLE_EQ(rand2(), 0.4712494933308135);
	ASSERT_DOUBLE_EQ(rand2(), 0.5913675200502571);

	rand2_seed(1080);
	ASSERT_DOUBLE_EQ(rand2(), 0.6554163483485531);
	ASSERT_DOUBLE_EQ(rand2(), 0.2009951854518572);
	ASSERT_DOUBLE_EQ(rand2(), 0.8936223876466522);
	ASSERT_DOUBLE_EQ(rand2(), 0.2818865431288053);
	ASSERT_DOUBLE_EQ(rand2(), 0.5250003829714993);
	ASSERT_DOUBLE_EQ(rand2(), 0.3141267749950177);
	ASSERT_DOUBLE_EQ(rand2(), 0.4446156782993733);
	ASSERT_DOUBLE_EQ(rand2(), 0.2994744556282315);
	ASSERT_DOUBLE_EQ(rand2(), 0.4712494933308135);
	ASSERT_DOUBLE_EQ(rand2(), 0.5913675200502571);
}
Esempio n. 3
0
TEST_F(RectangleTest, rectangleSize) {
	ASSERT_EQ(myRectangle->getHeight(), 3);
	ASSERT_EQ(myRectangle->getWidth(), 4);
	ASSERT_EQ(myRectangle->getRadius(), 0);
	ASSERT_DOUBLE_EQ(myRectangle->getArea(), 12);
}
Esempio n. 4
0
TEST(Circle, Length){
    ASSERT_DOUBLE_EQ(Circle(Point(1,2),3).length(), 3. * 2 * M_PI );
};
Esempio n. 5
0
TEST_F(test_move, independents_gradmanual)
{
  independent_variables independents(1, 2);
  independents(1) = 1.5;
  independents(2) = 3.5;

  gradient_structure gs;

  ASSERT_EQ(0, gradient_structure::GRAD_STACK1->total());
  ASSERT_EQ(1750, gradient_structure::GRAD_LIST->total_addresses());

  dvar_vector variables(independents);

  auto sum = [&variables]()
  {
    dvariable a(variables(1));
    dvariable b(variables(2));
    return a + b;
  };

  dvariable result = sum();
  ASSERT_EQ(4, gradient_structure::GRAD_STACK1->total());
  ASSERT_EQ(1752, gradient_structure::GRAD_LIST->total_addresses());

  ASSERT_DOUBLE_EQ(value(result), 5.0);

  --gradient_structure::GRAD_STACK1->ptr;

  double_and_int* ptr = (double_and_int*)gradient_structure::get_ARRAY_MEMBLOCK_BASE();
  unsigned long int imax = gradient_structure::ARR_LIST1->get_max_last_offset() / sizeof(double_and_int);
  for (unsigned int i = 0; i < imax; ++i)
  {
     ptr->x = 0.0;
     ++ptr;
  }
  gradient_structure::GRAD_LIST->initialize();
  *gradient_structure::GRAD_STACK1->ptr->dep_addr = 1.0;

  //Sum
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->dep_addr), 1.0);
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->ind_addr1), 0.0);
  (*(gradient_structure::GRAD_STACK1->ptr->func))();
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->dep_addr), 0.0);
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->ind_addr1), 1.0);
  ASSERT_TRUE(gradient_structure::GRAD_STACK1->ptr->ind_addr2 == NULL);
  ASSERT_DOUBLE_EQ(gradient_structure::GRAD_STACK1->ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(gradient_structure::GRAD_STACK1->ptr->mult2, 0.0);

  //Addition
  --gradient_structure::GRAD_STACK1->ptr;
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->dep_addr), 1.0);
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->ind_addr1), 0.0);
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->ind_addr2), 0.0);
  (*(gradient_structure::GRAD_STACK1->ptr->func))();
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->dep_addr), 0.0);
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->ind_addr1), 1.0);
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->ind_addr2), 1.0);
  ASSERT_DOUBLE_EQ(gradient_structure::GRAD_STACK1->ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(gradient_structure::GRAD_STACK1->ptr->mult2, 0.0);

  //Constructor
  --gradient_structure::GRAD_STACK1->ptr;
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->dep_addr), 1.0);
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->ind_addr1), 0.0);
  (*(gradient_structure::GRAD_STACK1->ptr->func))();
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->dep_addr), 0.0);
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->ind_addr1), 1.0);
  ASSERT_TRUE(gradient_structure::GRAD_STACK1->ptr->ind_addr2 == NULL);
  ASSERT_DOUBLE_EQ(gradient_structure::GRAD_STACK1->ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(gradient_structure::GRAD_STACK1->ptr->mult2, 0.0);

  //Constructor
  --gradient_structure::GRAD_STACK1->ptr;
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->dep_addr), 1.0);
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->ind_addr1), 0.0);
  (*(gradient_structure::GRAD_STACK1->ptr->func))();
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->dep_addr), 0.0);
  ASSERT_DOUBLE_EQ(*(gradient_structure::GRAD_STACK1->ptr->ind_addr1), 1.0);
  ASSERT_TRUE(gradient_structure::GRAD_STACK1->ptr->ind_addr2 == NULL);
  ASSERT_DOUBLE_EQ(gradient_structure::GRAD_STACK1->ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(gradient_structure::GRAD_STACK1->ptr->mult2, 0.0);

  //ASSERT_DOUBLE_EQ(*gradient_structure::INDVAR_LIST->get_address(1), 0.0);
  //ASSERT_DOUBLE_EQ(*gradient_structure::INDVAR_LIST->get_address(2), 0.0);
  ASSERT_DOUBLE_EQ(value(variables(1)), 1.0);
  ASSERT_DOUBLE_EQ(value(variables(2)), 1.0);
}
Esempio n. 6
0
TEST(Point,Eq){
    Point a = Point(2,3);
    Point b = Point(2,3);
    ASSERT_DOUBLE_EQ(a.x, b.x);
    ASSERT_DOUBLE_EQ(a.y, b.y);
};
Esempio n. 7
0
TEST(Segment, Length){
    ASSERT_DOUBLE_EQ(Segment(1,3,3,3).length(),(Point(1,3) - Point(3,3)).norm());
};
Esempio n. 8
0
TEST(math, log1pl) {
  ASSERT_EQ(-HUGE_VALL, log1pl(-1.0L));
  ASSERT_TRUE(isnan(log1pl(nanl(""))));
  ASSERT_TRUE(isinf(log1pl(HUGE_VALL)));
  ASSERT_DOUBLE_EQ(1.0L, log1pl(M_E - 1.0L));
}
Esempio n. 9
0
TEST(math, fdim) {
  ASSERT_DOUBLE_EQ(0.0, fdim(1.0, 1.0));
  ASSERT_DOUBLE_EQ(1.0, fdim(2.0, 1.0));
  ASSERT_DOUBLE_EQ(0.0, fdim(1.0, 2.0));
}
Esempio n. 10
0
TEST(math, erfcl) {
  ASSERT_DOUBLE_EQ(0.15729920705028513l, erfcl(1.0L));
}
Esempio n. 11
0
TEST(math, log1p) {
  ASSERT_EQ(-HUGE_VAL, log1p(-1.0));
  ASSERT_TRUE(isnan(log1p(nan(""))));
  ASSERT_TRUE(isinf(log1p(HUGE_VAL)));
  ASSERT_DOUBLE_EQ(1.0, log1p(M_E - 1.0));
}
Esempio n. 12
0
TEST(math, erfc) {
  ASSERT_DOUBLE_EQ(0.15729920705028513, erfc(1.0));
}
Esempio n. 13
0
TEST(math, erfl) {
  ASSERT_DOUBLE_EQ(0.84270079294971489L, erfl(1.0L));
}
Esempio n. 14
0
TEST(math, erf) {
  ASSERT_DOUBLE_EQ(0.84270079294971489, erf(1.0));
}
Esempio n. 15
0
TEST(Point,Norm){
    ASSERT_DOUBLE_EQ(Point(2,2).norm(), 2 * sqrt(2.));
};
Esempio n. 16
0
TEST(math, fdiml) {
  ASSERT_DOUBLE_EQ(0.0L, fdiml(1.0L, 1.0L));
  ASSERT_DOUBLE_EQ(1.0L, fdiml(2.0L, 1.0L));
  ASSERT_DOUBLE_EQ(0.0L, fdiml(1.0L, 2.0L));
}
Esempio n. 17
0
TEST(Square, Length){
    ASSERT_DOUBLE_EQ(Square(1,1,4,1).length(),12);
};
Esempio n. 18
0
TEST(stdlib, atof) {
  ASSERT_DOUBLE_EQ(1.23, atof("1.23"));
}
Esempio n. 19
0
TEST(Point,Multi){
    ASSERT_DOUBLE_EQ((Point(2,2) * Point(3,3)),12);
};
Esempio n. 20
0
TEST(stdlib, strtold) {
  ASSERT_DOUBLE_EQ(1.23, strtold("1.23", NULL));
}
Esempio n. 21
0
TEST(Segment, Length_oy){ // ||oy = 3
    ASSERT_DOUBLE_EQ(Segment(1,1,4,1).length(),(Point(1,1) - Point(4,1)).norm());
};
Esempio n. 22
0
int testBSplineSetBasic() {
  PrintTimeStamp(PETSC_COMM_SELF, "set basics", NULL);

  MPI_Comm comm = PETSC_COMM_SELF;
  BPS bps; BPSCreate(comm, &bps); BPSSetLine(bps, 5.0, 6);
  
  int order = 3;
  BSS bss; 
  BSSCreate(comm, &bss); 
  BSSSetKnots(bss, order, bps);
  BSSSetUp(bss);

  ASSERT_EQ(order, bss->order);
  ASSERT_EQ(5, bss->num_ele);
  ASSERT_EQ(5, bss->num_basis);

  ASSERT_EQ(1, bss->b_idx_list[0]);
  ASSERT_EQ(2, bss->b_idx_list[1]);
  ASSERT_EQ(4, bss->b_idx_list[3]);

  PetscReal *zs; BPSGetZs(bps, &zs, NULL);
  for(int i = 0; i < 6; i++)
    ASSERT_DOUBLE_EQ(1.0*i, zs[i]);
  PetscFree(zs);
  ASSERT_DOUBLE_EQ(0.0, bss->ts_r[0]);
  ASSERT_DOUBLE_EQ(0.0, bss->ts_r[1]);
  ASSERT_DOUBLE_EQ(0.0, bss->ts_r[2]);
  ASSERT_DOUBLE_EQ(1.0, bss->ts_r[3]);
  ASSERT_DOUBLE_EQ(2.0, bss->ts_r[4]);
  ASSERT_DOUBLE_EQ(3.0, bss->ts_r[5]);
  ASSERT_DOUBLE_EQ(4.0, bss->ts_r[6]);
  ASSERT_DOUBLE_EQ(5.0, bss->ts_r[7]);
  ASSERT_DOUBLE_EQ(5.0, bss->ts_r[8]);
  ASSERT_DOUBLE_EQ(5.0, bss->ts_r[9]);

  double x = 0.34;
  PetscScalar y1; BSSBasisPsi(bss, 2-1, x, &y1);
  ASSERT_DOUBLE_EQ(0.5*x*x, PetscRealPart(y1));

  ASSERT_DOUBLE_NEAR(0.11270167, bss->xs[0], pow(10.0, -8.0));
  ASSERT_DOUBLE_NEAR(0.5,        bss->xs[1], pow(10.0, -8.0));
  ASSERT_DOUBLE_NEAR(0.88729833, bss->xs[2], pow(10.0, -8.0));

  ASSERT_DOUBLE_NEAR(0.2777777777777, bss->ws[0], pow(10.0, -8.0));
  ASSERT_DOUBLE_NEAR(0.4444444444444, bss->ws[1], pow(10.0, -8.0));
  ASSERT_DOUBLE_NEAR(0.2777777777777, bss->ws[14], pow(10.0, -8.0));

  ASSERT_DOUBLE_NEAR(0.20635083, bss->vals[0], pow(10.0, -8.0));
  ASSERT_DOUBLE_EQ(0.625, bss->vals[1]);
  ASSERT_DOUBLE_EQ(0.0,   bss->vals[10]);
  ASSERT_DOUBLE_EQ(0.125, bss->vals[15*2+4]);

  ASSERT_DOUBLE_NEAR(1.66189500386, bss->derivs[0], pow(10.0, -8.0));
  ASSERT_DOUBLE_NEAR(-0.5         , bss->derivs[4], pow(10.0, -8.0));
  ASSERT_DOUBLE_NEAR(-0.887298334621, bss->derivs[21],pow(10.0, -8.0));

  BSSDestroy(&bss);
  return 0;
}
Esempio n. 23
0
TEST_F(test_move, independents)
{
  independent_variables independents(1, 2);
  independents(1) = 1.5;
  independents(2) = 3.5;

  gradient_structure gs;

  ASSERT_EQ(0, gradient_structure::GRAD_STACK1->total());
  ASSERT_EQ(1750, gradient_structure::GRAD_LIST->total_addresses());

  dvar_vector variables(independents);

  dvariable a(variables(1));
  dvariable b(variables(2));
  auto sum = [&a, &b]()
  {
    return a + b;
  };

  dvariable result = sum();
  ASSERT_EQ(4, gradient_structure::GRAD_STACK1->total());
  ASSERT_EQ(1753, gradient_structure::GRAD_LIST->total_addresses());

  ASSERT_DOUBLE_EQ(value(result), 5.0);

  grad_stack_entry* ptr = gradient_structure::GRAD_STACK1->ptr;
  ASSERT_TRUE(ptr->func == NULL);

  --ptr;
  ASSERT_TRUE(ptr->func == &default_evaluation1);
  ASSERT_TRUE(ptr->dep_addr == gradient_structure::GRAD_LIST->get(1752));
  ASSERT_TRUE(ptr->ind_addr1 == &(gradient_structure::RETURN_PTR->v->x));
  ASSERT_TRUE(ptr->ind_addr2 == NULL);
  ASSERT_DOUBLE_EQ(ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(ptr->mult2, 0.0);

  --ptr;
  ASSERT_TRUE(ptr->func == &default_evaluation4);
  ASSERT_TRUE(ptr->dep_addr == &(gradient_structure::RETURN_PTR->v->x));
  ASSERT_TRUE(ptr->ind_addr1 == gradient_structure::GRAD_LIST->get(1750));
  ASSERT_TRUE(ptr->ind_addr2 == gradient_structure::GRAD_LIST->get(1751));
  ASSERT_DOUBLE_EQ(ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(ptr->mult2, 0.0);

  --ptr;
  ASSERT_TRUE(ptr->func == &default_evaluation1);
  ASSERT_TRUE(ptr->dep_addr == gradient_structure::GRAD_LIST->get(1751));
  ASSERT_TRUE(ptr->ind_addr1 == &(variables(2).v->x));
  ASSERT_TRUE(ptr->ind_addr2 == NULL);
  ASSERT_DOUBLE_EQ(ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(ptr->mult2, 0.0);

  --ptr;
  ASSERT_TRUE(ptr->func == &default_evaluation1);
  ASSERT_TRUE(ptr->dep_addr == gradient_structure::GRAD_LIST->get(1750));
  ASSERT_TRUE(ptr->ind_addr1 == &(variables(1).v->x));
  ASSERT_TRUE(ptr->ind_addr2 == NULL);
  ASSERT_DOUBLE_EQ(ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(ptr->mult2, 0.0);
}
Esempio n. 24
0
TEST_F(TestVariant, MinLimitReal)
{
    vmf::vmf_real limitReal = vmf::Variant::minLimit<vmf::vmf_real>(vmf::Variant::type_real);
    ASSERT_DOUBLE_EQ(limitReal, std::numeric_limits<vmf::vmf_real>::lowest());
}
Esempio n. 25
0
TEST_F(test_move, follow_gradient_structure)
{
  ASSERT_TRUE(gradient_structure::GRAD_STACK1 == NULL);
  ASSERT_TRUE(gradient_structure::GRAD_LIST == NULL);

  gradient_structure gs;

  ASSERT_TRUE(gradient_structure::GRAD_STACK1 != NULL);
  ASSERT_TRUE(gradient_structure::GRAD_LIST != NULL);

  ASSERT_EQ(0, gradient_structure::GRAD_STACK1->total());
  ASSERT_EQ(1750, gradient_structure::GRAD_LIST->total_addresses());

  grad_stack_entry* ptr = gradient_structure::GRAD_STACK1->ptr;
  ASSERT_TRUE(ptr != NULL);

  ASSERT_TRUE(ptr->func == NULL);
  ASSERT_TRUE(ptr->dep_addr == NULL);
  ASSERT_TRUE(ptr->ind_addr1 == NULL);
  ASSERT_TRUE(ptr->ind_addr2 == NULL);
  ASSERT_DOUBLE_EQ(ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(ptr->mult2, 0.0);

  dvariable a(1.5);

  ASSERT_EQ(1, gradient_structure::GRAD_STACK1->total());
  ASSERT_EQ(1751, gradient_structure::GRAD_LIST->total_addresses());

  ASSERT_TRUE(ptr->func == &default_evaluation0);
  ASSERT_TRUE(ptr->dep_addr == gradient_structure::GRAD_LIST->get(1750));
  ASSERT_TRUE(ptr->ind_addr1 == NULL);
  ASSERT_TRUE(ptr->ind_addr2 == NULL);
  ASSERT_DOUBLE_EQ(ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(ptr->mult2, 0.0);

  ptr++;

  ASSERT_TRUE(ptr->func == NULL);
  ASSERT_TRUE(ptr->dep_addr == NULL);
  ASSERT_TRUE(ptr->ind_addr1 == NULL);
  ASSERT_TRUE(ptr->ind_addr2 == NULL);
  ASSERT_DOUBLE_EQ(ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(ptr->mult2, 0.0);

  dvariable b(3.5);

  ASSERT_EQ(2, gradient_structure::GRAD_STACK1->total());
  ASSERT_EQ(1752, gradient_structure::GRAD_LIST->total_addresses());

  ASSERT_TRUE(ptr->func == &default_evaluation0);
  ASSERT_TRUE(ptr->dep_addr == gradient_structure::GRAD_LIST->get(1751));
  ASSERT_TRUE(ptr->ind_addr1 == NULL);
  ASSERT_TRUE(ptr->ind_addr2 == NULL);
  ASSERT_DOUBLE_EQ(ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(ptr->mult2, 0.0);

  ptr++;

  ASSERT_TRUE(ptr->func == NULL);
  ASSERT_TRUE(ptr->dep_addr == NULL);
  ASSERT_TRUE(ptr->ind_addr1 == NULL);
  ASSERT_TRUE(ptr->ind_addr2 == NULL);
  ASSERT_DOUBLE_EQ(ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(ptr->mult2, 0.0);

  dvariable result = a + b;

  ASSERT_EQ(4, gradient_structure::GRAD_STACK1->total());
  ASSERT_EQ(1753, gradient_structure::GRAD_LIST->total_addresses());

  ASSERT_TRUE(ptr->func == &default_evaluation4);
  ASSERT_TRUE(ptr->dep_addr == &(gradient_structure::RETURN_PTR->v->x));
  ASSERT_TRUE(ptr->ind_addr1 == gradient_structure::GRAD_LIST->get(1750));
  ASSERT_TRUE(ptr->ind_addr2 == gradient_structure::GRAD_LIST->get(1751));
  ASSERT_DOUBLE_EQ(ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(ptr->mult2, 0.0);

  ptr++;

  ASSERT_TRUE(ptr->func == &default_evaluation1);
  ASSERT_TRUE(ptr->dep_addr == gradient_structure::GRAD_LIST->get(1752));
  ASSERT_TRUE(ptr->ind_addr1 == &(gradient_structure::RETURN_PTR->v->x));
  ASSERT_TRUE(ptr->ind_addr2 == NULL);
  ASSERT_DOUBLE_EQ(ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(ptr->mult2, 0.0);

  ptr++;

  ASSERT_TRUE(ptr->func == NULL);
  ASSERT_TRUE(ptr->dep_addr == NULL);
  ASSERT_TRUE(ptr->ind_addr1 == NULL);
  ASSERT_TRUE(ptr->ind_addr2 == NULL);
  ASSERT_DOUBLE_EQ(ptr->mult1, 0.0);
  ASSERT_DOUBLE_EQ(ptr->mult2, 0.0);

  ASSERT_DOUBLE_EQ(value(result), 5.0);
}
Esempio n. 26
0
TEST_F(TestVariant, FloatConstructor)
{
    float value = 42.0f;
    v = vmf::Variant(value);
    ASSERT_DOUBLE_EQ(value, (vmf::vmf_real) v);
}
Esempio n. 27
0
TEST(wchar, wcstold) {
  ASSERT_DOUBLE_EQ(1.23L, wcstold(L"1.23", NULL));
}
Esempio n. 28
0
TEST(Rectangle, Length){
    ASSERT_DOUBLE_EQ(Rectangle(1,1,4,1,2).length(),10);
};
TEST(ByteStreamTest, testRandomReadWrite) {
	ByteStream byteStream;
	srandom(SDL_GetTicks());

	TypeValueList _typeValueList;
	TypeValueListIter _typeValueListIter;

	unsigned int iterations = random() % 20 + 1;
	unsigned int index = 0;
	size_t size = 0;

	//add random types to byte stream
	do {
		DataType dataType = DataType(random() % count);
		TypeValue typeValue;
		typeValue.type = dataType;
		switch (dataType) {
		case e_byte: {
			uint8_t* byte = new uint8_t(random() % BYTE_ADD);
			byteStream.addByte(*byte);
			typeValue.pValue = byte;
			size += 1;
			break;
		}
		case e_short: {
			int16_t* word = new int16_t(random() % SHORT_ADD);
			byteStream.addShort(*word);
			typeValue.pValue = word;
			size += 2;
			break;
		}
		case e_int: {
			int32_t* dword = new int32_t(random() % INT_ADD);
			byteStream.addInt(*dword);
			typeValue.pValue = dword;
			size += 4;
			break;
		}
		case e_float: {
			float* dword = new float(
					floorf((random() % INT_ADD) / float(INT_ADD) * 100.0)
							/ 100.0);
			byteStream.addFloat(*dword);
			typeValue.pValue = dword;
			size += 4;
			break;
		}
		case e_string: {
			std::string* str = new std::string("hello IT!");
			byteStream.addString(*str);
			typeValue.pValue = str;
			size += str->length() + 1; //plus the '\0' char
			break;
		}
		default:
			ASSERT_TRUE(false);
			break;
		}
		_typeValueList.push_back(typeValue);
	} while (index++ < iterations);
	ASSERT_EQ(byteStream.getSize(), size);

	//read and verify added types in byte stream
	index = 0;
	do {
		DataType dataType = _typeValueList.front().type;
		void* value = _typeValueList.front().pValue;
		switch (dataType) {
		case e_byte: {
			uint8_t byte = byteStream.readByte();
			size -= 1;
			ASSERT_EQ(byte, *(uint8_t* ) value);
			delete (uint8_t*) value;
			break;
		}
		case e_short: {
			int16_t word = byteStream.readShort();
			size -= 2;
			ASSERT_EQ(word, *(int16_t* ) value);
			delete (int16_t*) value;
			break;
		}
		case e_int: {
			int32_t dword = byteStream.readInt();
			size -= 4;
			ASSERT_EQ(dword, *(int32_t* ) value);
			delete (int32_t*) value;
			break;
		}
		case e_float: {
			float dword = byteStream.readFloat();
			size -= 4;
			ASSERT_DOUBLE_EQ(dword, *(float* ) value);
			delete (float*) value;
			break;
		}
		case e_string: {
			std::string str = byteStream.readString();
			size -= str.length() + 1; //plus the '\0' char
			ASSERT_EQ(str, *(std::string* ) value);
			delete (std::string*) value;
			break;
		}
		default:
			ASSERT_TRUE(false);
			break;
		}
		_typeValueList.erase(_typeValueList.begin());
		ASSERT_EQ(byteStream.getSize(), size);
	} while (index++ < iterations);
	ASSERT_EQ(byteStream.getSize(), size_t(0));
}
Esempio n. 30
0
TEST(math, hypot) {
  ASSERT_DOUBLE_EQ(5.0, hypot(3.0, 4.0));
}