예제 #1
0
TEST(TBitField, compare_equal_bitfields_of_equal_size)
{
  const int size = 2;
  TBitField bf1(size), bf2(size);
  for (int i = 0; i < size; i++)
  {
    bf1.SetBit(i);
  }
  bf2 = bf1;

  EXPECT_EQ(bf1, bf2);
}
예제 #2
0
TEST(TBitField, assign_operator_changes_bitfield_size)
{
  const int size1 = 2, size2 = 5;
  TBitField bf1(size1), bf2(size2);
  for (int i = 0; i < size1; i++)
  {
    bf1.SetBit(i);
  }
  bf2 = bf1;

  EXPECT_EQ(2, bf2.GetLength());
}
예제 #3
0
TEST(TBitField, can_assign_bitfields_of_equal_size)
{
  const int size = 2;
  TBitField bf1(size), bf2(size);
  for (int i = 0; i < size; i++)
  {
    bf1.SetBit(i);
  }
  bf2 = bf1;

  EXPECT_NE(0, bf2.GetBit(0));
  EXPECT_NE(0, bf2.GetBit(1));
}
예제 #4
0
TEST(TBitField, bitfields_with_different_bits_are_not_equal)
{
  const int size = 4;
  TBitField bf1(size), bf2(size);

  bf1.SetBit(1);
  bf1.SetBit(3);

  bf2.SetBit(1);
  bf2.SetBit(2);

  EXPECT_NE(bf1, bf2);
}
예제 #5
0
void
TestBitField3D<T>::testOperatorComparison() 
{
    DEFINE_TYPEDEFS;

    BitField bf1(1);
    BitField bf2(1);
    CPPUNIT_ASSERT(bf1 == bf2);

    bf1.setBit(5);
    bf2.setBit(5);
    CPPUNIT_ASSERT(bf1 == bf2);

    bf1.setBit(2);
    bf2.setBit(2);
    CPPUNIT_ASSERT(bf1 == bf2);

    bf1.setBit(7);
    bf2.setBit(7);
    CPPUNIT_ASSERT(bf1 == bf2);

    bf1.setBit(0);
    bf2.setBit(0);
    CPPUNIT_ASSERT(bf1 == bf2);

    bf1.invertBits();
    bf2.invertBits();
    CPPUNIT_ASSERT(bf1 == bf2);

    bf1.clearBits();
    bf2.clearBits();
    CPPUNIT_ASSERT(bf1 == bf2);

    bf1.fillBits();
    bf2.fillBits();
    CPPUNIT_ASSERT(bf1 == bf2);

    bf1.unsetBit(4);
    CPPUNIT_ASSERT(bf1 != bf2);

    bf2.unsetBit(4);
    CPPUNIT_ASSERT(bf1 == bf2);

    bf1.resize(2);
    CPPUNIT_ASSERT(bf1 != bf2);

    bf2.resize(2);
    CPPUNIT_ASSERT(bf1 == bf2);
}
예제 #6
0
TEST(TBitField, and_operator_applied_to_bitfields_of_equal_size)
{
  const int size = 4;
  TBitField bf1(size), bf2(size), expBf(size);
  // bf1 = 0011
  bf1.SetBit(2);
  bf1.SetBit(3);
  // bf2 = 0101
  bf2.SetBit(1);
  bf2.SetBit(3);

  // expBf = 0001
  expBf.SetBit(3);

  EXPECT_EQ(expBf, bf1 & bf2);
}
예제 #7
0
TEST(TBitField, several_intersection_in_one_line)
{
	const int size = 4;
	TBitField bf1(size), bf2(size), bf3(size), expbf(size);
	//bf1 = 1000
	bf1.SetBit(0);
	//bf2 = 1100;
	bf2.SetBit(0);
	bf2.SetBit(1);
	//bf3 = 1101;
	bf3.SetBit(0);
	bf3.SetBit(1);
	bf3.SetBit(3);
	//expbf = 1000;
	expbf.SetBit(0);
	EXPECT_EQ(expbf, bf1 & bf2 & bf3);
}
예제 #8
0
TEST(TBitField, and_operator_applied_to_bitfields_of_non_equal_size)
{
  const int size1 = 4, size2 = 5;
  TBitField bf1(size1), bf2(size2), expBf(size2);
  // bf1 = 0011
  bf1.SetBit(2);
  bf1.SetBit(3);
  // bf2 = 01010
  bf2.SetBit(1);
  bf2.SetBit(3);

  // expBf = 00010
  expBf.SetBit(1);
  expBf.SetBit(2);
  expBf.SetBit(3);

  EXPECT_EQ(expBf, bf1 | bf2);
}
예제 #9
0
int main()
{
	TBitField bit(10);
	cout << bit << " constructor\n";
	int m = bit.GetLength();
	cout << m << " lenght of bit\n";
	bit.SetBit(1);
	bit.SetBit(5);
	bit.SetBit(4);
	cout << bit << " Setting bits 1,4,5 on bit(10)\n";
	bit.ClrBit(5);
	cout << bit << " Clear bit 5 on bit(10)\n";
	TBitField bit3(21);
	bit3.SetBit(2);
	bit3.SetBit(15);
	bit3.SetBit(4);
	cout<<bit3<<" Setting bits 2, 4,15 on bit3(21)\n";
	TBitField bittemp(10);
	bittemp = bit | bit3;
	cout << bittemp << " Operation bit|bit3\n";
	bittemp = bit & bit3;
	cout << bittemp << " Operation bit&bit3\n";
	bittemp = ~bit;
	cout << bittemp << " Operation ~bit\n";
	TBitField bit4(10);
	cin >> bit4;
	cout << "bit4: " <<  bit4 << "\n";
	//int a;
	//cin >> a;
	const int size = 4;
	TBitField bf1(size), bf2(size);
	bf1.SetBit(1);
	bf1.SetBit(3);
	bf2.SetBit(1);
	bf2.SetBit(2);
	//int result = bf1 == bf2;
	//cout << "result = bf1 == bf2: " << result;
	int result = bf1 != bf2;
	cout << "result = bf1 != bf2: " << result;

}
예제 #10
0
파일: func.cpp 프로젝트: filorom/simppl
int main()
{
   Function<void(*)()> fu(func1);
   eval(fu);

   Function<bool(*)(int, double&)> f(func);
   double y = 3.1415;
   std::cout << f(42, y) << std::endl;

   Function<void(Hello::*)(int)const> f1(&Hello::sayHello);
   Hello h;
   const Hello* h1 = &h;
   f1(*h1, 42);

   // get rid of this template arguments if possible...
   eval(bind(&Hello::sayHello1, ref(h)));
   double x = 3.1415;
   eval(bind(func, 3, x));
   std::cout << x << std::endl;

   x = 6.666667;
   bind(func, 4, _1)(x);
   std::cout << x << std::endl;

   bind(&Hello::sayHello, ref(h), 23)();
   bind(&Hello::sayHello, ref(h), _1)(33);
   bind(&Hello::sayHello, _1, 24)(h);  // FIXME here no pointer possible
   bind(&Hello::sayHello, _1, _2)(h, 22);

   std::vector<int> iv;
   iv.push_back(2);
   iv.push_back(4);
   iv.push_back(3);
   iv.push_back(1);
   std::for_each(iv.begin(), iv.end(), bind(printx, "%d\n", _1));
   
   double d = 123.123;
   Hello h2(42);   
   
   bind(&Hello::sayHello3, _1, 42, _2)(h2, d);
   std::cout << "d=" << d << std::endl;

   std::vector<Hello> hv;
   hv.push_back(Hello());
   hv.push_back(Hello());
   std::for_each(hv.begin(), hv.end(), bind(&Hello::doIt, _1)); 
   
   Function<bool(*)(double& d)> bf;
   std::cout << !!bf << std::endl;
   bf = bind(func, 4, _1);
   std::cout << !!bf << std::endl;
   d = 7.777;
   bf(d);   
   
   Function<void(*)(Hello&, double&)> bf1(bind(&Hello::sayHello3, _1, 42, _2));
   bf1(h, d);
   
   bind(f4, _2, _3, _4, _1)(1, 2, 3, 4);   
   
   std::vector<Hello*> hv1;
   hv1.push_back(new Hello(42));
   std::for_each(hv1.begin(), hv1.end(), bind(&Hello::sayHello, _1, 23));
   
   bind(&Hello::sayHello, hv1.front(), _1)(23);
   
   // FIXME any smart pointer does not work here!
   std::auto_ptr<Hello> ah(new Hello(11));
   Function<void(Hello::*)(int, double&)> fu1(&Hello::sayHello3);
   fu1(*ah, 42, d);
   
   return 0;
}