TEST(SparseMatrixSpecialValues, Z3determined)
{
	typedef FiniteFieldParam<ZPlusRing32>::Module<3> Param;
	Param::Matrix m;
	const auto E = m.ElementConstructor();
	{//1x1 non-identity
		m.Clear();
		m.AddRow();
		m.AddElement(0, 2u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 2u)}));
	}
	{//first column is fixed by others with different coef relations
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddRow();
		m.AddElement(0, 2u);
		m.AddElement(1, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
	 	m.AddElement(2, 2u);
	 	m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(3, 1u);
	 	m.AddRow();
		m.AddElement(0, 2u);
		m.AddElement(4, 2u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u), E(1, 1u), E(2, 1u), E(3, 2u), E(4, 2u)}));
	}
}
예제 #2
0
TEST(GridUtils, CombineGrids)
{
  GridPtr g1(new nav_msgs::OccupancyGrid());
  GridPtr g2(new nav_msgs::OccupancyGrid());
  
  g1->info.origin = makePose(2, 1, 0);
  g2->info.origin = makePose(3, 0, PI/4);
  g1->info.resolution = 0.5;
  g2->info.resolution = 0.5;
  g1->info.height = 4;
  g1->info.width = 6;
  g2->info.height = 4;
  g2->info.width = 4;
  g1->data.resize(24);
  g2->data.resize(16);

  fill(g1->data.begin(), g1->data.end(), -1);
  fill(g2->data.begin(), g2->data.end(), -1);

  setVal(g2.get(), 1, 0, 0);
  setVal(g2.get(), 0, 3, 50);
  setVal(g2.get(), 2, 0, 42);
  setVal(g2.get(), 0, 2, 11);
  setVal(g2.get(), 3, 2, 0);
  setVal(g2.get(), 3, 0, 110);
  
  setVal(g1.get(), 5, 3, 100);
  setVal(g1.get(), 3, 0, 24);
  setVal(g1.get(), 0, 0, 66);
  setVal(g1.get(), 4, 0, 90);
  
  std::vector<GridConstPtr> grids;
  grids.push_back(g1);
  grids.push_back(g2);
  GridPtr combined = occupancy_grid_utils::combineGrids(grids, g1->info.resolution/2.0);
  
  EXPECT_PRED2(approxEqual, 3-std::sqrt(2), combined->info.origin.position.x);
  EXPECT_PRED2(approxEqual, 0, combined->info.origin.position.y);
  EXPECT_EQ(0.25, combined->info.resolution);
  EXPECT_EQ(std::round((2+std::sqrt(2))/0.25), combined->info.width);
  EXPECT_EQ(12u, combined->info.height);

  // Note there are rounding issues that mean that some of the values below
  // could theoretically go either way
  EXPECT_EQ(-1, val(*combined, 11, 2));
  EXPECT_EQ(-1, val(*combined, 2, 0));
  EXPECT_EQ(-1, val(*combined, 5, 0));
  EXPECT_EQ(0, val(*combined, 7, 2));
  EXPECT_EQ(66, val(*combined, 1, 6));
  EXPECT_EQ(100, val(*combined, 11, 11));
  EXPECT_EQ(-1, val(*combined, 2, 11));
  EXPECT_EQ(11, val(*combined, 3, 2));
  EXPECT_EQ(42, val(*combined, 7, 4));
  EXPECT_EQ(66, val(*combined, 2, 4));
  EXPECT_EQ(0, val(*combined, 6, 8));
  EXPECT_EQ(90, val(*combined, 10, 5));
}
예제 #3
0
TEST(CoreTest, FloatComparison)
{
    float const one = 1.0f;
    float const zero = 0.0f;
    float const tenth = 0.1f;

    float const a = 10.f * tenth;
    float const b = 57.6767f;
    float const c = b / b;
    float const d = 1.0f / 3.0f;
    float const e = 3.0f * one - b / (d * b);

    EXPECT_PRED2(drgn::AlmostEqual<float>, zero, zero);
    EXPECT_PRED2(drgn::AlmostEqual<float>, one, c);
    EXPECT_PRED2(drgn::AlmostEqual<float>, zero, e);
}
예제 #4
0
void caos_assert_eq (CaosContext *c)
{
  CaosValue l = caos_arg_value(c);
  CaosValue r = caos_arg_value(c);
  if (caos_get_error (c)) return;
  
  EXPECT_PRED2 (caos_value_equal, l, r);
}
예제 #5
0
GTEST_TEST(ExpectedTest, failure_error_str_contructor_initialization) {
  const auto msg =
      std::string{"\"#$%&'()*+,-./089:;<[=]>\" is it a valid error message?"};
  auto expected = Expected<std::string, TestError>::failure(msg);
  EXPECT_FALSE(expected);
  EXPECT_TRUE(expected.isError());
  EXPECT_EQ(expected.getErrorCode(), TestError::Some);
  auto fullMsg = expected.getError().getFullMessage();
  EXPECT_PRED2(stringContains, fullMsg, msg);
}
예제 #6
0
TEST_VM_F(LogConfigurationTest, describe) {
  ResourceMark rm;
  stringStream ss;
  LogConfiguration::describe(&ss);
  const char* description = ss.as_string();

  // Verify that stdout and stderr are listed by default
  EXPECT_PRED2(string_contains_substring, description, StdoutLog.name());
  EXPECT_PRED2(string_contains_substring, description, StderrLog.name());

  // Verify that each tag, level and decorator is listed
  for (size_t i = 0; i < LogTag::Count; i++) {
    EXPECT_PRED2(string_contains_substring, description, LogTag::name(static_cast<LogTagType>(i)));
  }
  for (size_t i = 0; i < LogLevel::Count; i++) {
    EXPECT_PRED2(string_contains_substring, description, LogLevel::name(static_cast<LogLevelType>(i)));
  }
  for (size_t i = 0; i < LogDecorators::Count; i++) {
    EXPECT_PRED2(string_contains_substring, description, LogDecorators::name(static_cast<LogDecorators::Decorator>(i)));
  }

  // Verify that the default configuration is printed
  char expected_buf[256];
  int ret = jio_snprintf(expected_buf, sizeof(expected_buf), "=%s", LogLevel::name(LogLevel::Default));
  ASSERT_NE(-1, ret);
  EXPECT_PRED2(string_contains_substring, description, expected_buf);
  EXPECT_PRED2(string_contains_substring, description, "#1: stderr all=off");

  // Verify default decorators are listed
  LogDecorators default_decorators;
  expected_buf[0] = '\0';
  for (size_t i = 0; i < LogDecorators::Count; i++) {
    LogDecorators::Decorator d = static_cast<LogDecorators::Decorator>(i);
    if (default_decorators.is_decorator(d)) {
      ASSERT_LT(strlen(expected_buf), sizeof(expected_buf));
      ret = jio_snprintf(expected_buf + strlen(expected_buf),
                         sizeof(expected_buf) - strlen(expected_buf),
                         "%s%s",
                         strlen(expected_buf) > 0 ? "," : "",
                         LogDecorators::name(d));
      ASSERT_NE(-1, ret);
    }
  }
  EXPECT_PRED2(string_contains_substring, description, expected_buf);

  // Add a new output and verify that it gets described after it has been added
  const char* what = "all=trace";
  EXPECT_FALSE(is_described(TestLogFileName)) << "Test output already exists!";
  set_log_config(TestLogFileName, what);
  EXPECT_TRUE(is_described(TestLogFileName));
  EXPECT_TRUE(is_described("logging=trace"));
}
예제 #7
0
TEST(diofantiane_solve, macro_64_direct_big_values)
{
	EXPECT_PRED2(checkCorrectDiofantioanSolution, PRA_DEQUE_DIOFANTEINE_SOLVE_UINT64_DETAILV1(0xFFFFFFF), 0xFFFFFFF);
	EXPECT_PRED2(checkCorrectDiofantioanSolution, PRA_DEQUE_DIOFANTEINE_SOLVE_UINT64_DETAILV1(0x8000001), 0x8000001);
	EXPECT_PRED2(checkCorrectDiofantioanSolution, PRA_DEQUE_DIOFANTEINE_SOLVE_UINT64_DETAILV1(0x80000001ull), 0x80000001ull);
	EXPECT_PRED2(checkCorrectDiofantioanSolution, PRA_DEQUE_DIOFANTEINE_SOLVE_UINT64_DETAILV1(0x7FFFFFFFFFFFFFFFll), 0x7FFFFFFFFFFFFFFFll);
	EXPECT_PRED2(checkCorrectDiofantioanSolution, PRA_DEQUE_DIOFANTEINE_SOLVE_UINT64_DETAILV1(0x8000000000000001ull), 0x8000000000000001ull);
	EXPECT_PRED2(checkCorrectDiofantioanSolution, PRA_DEQUE_DIOFANTEINE_SOLVE_UINT64_DETAILV1(0xFFFFFFFFFFFFFFFFll), 0xFFFFFFFFFFFFFFFFll);
}
TEST(LogTagSetDescriptions, describe) {
  for (LogTagSetDescription* d = tagset_descriptions; d->tagset != NULL; d++) {
    char expected[1 * K];
    d->tagset->label(expected, sizeof(expected), "+");
    jio_snprintf(expected + strlen(expected),
                 sizeof(expected) - strlen(expected),
                 ": %s", d->descr);

    ResourceMark rm;
    stringStream stream;
    LogConfiguration::describe(&stream);
    EXPECT_PRED2(string_contains_substring, stream.as_string(), expected)
      << "missing log tag set descriptions in LogConfiguration::describe";
  }
}
예제 #9
0
GTEST_TEST(ExpectedTest, nested_errors_example) {
  const auto msg = std::string{"Write a good error message"};
  auto firstFailureSource = [&msg]() -> Expected<std::vector<int>, TestError> {
    return createError(TestError::Semantic, msg);
  };
  auto giveMeNestedError = [&]() -> Expected<std::vector<int>, TestError> {
    auto ret = firstFailureSource();
    ret.isError();
    return createError(TestError::Runtime, msg, ret.takeError());
  };
  auto ret = giveMeNestedError();
  EXPECT_FALSE(ret);
  ASSERT_TRUE(ret.isError());
  EXPECT_EQ(ret.getErrorCode(), TestError::Runtime);
  ASSERT_TRUE(ret.getError().hasUnderlyingError());
  EXPECT_PRED2(stringContains, ret.getError().getFullMessage(), msg);
}
TEST(SparseMatrixSpecialValues, Z2determined)
{
	typedef FiniteFieldParam<ZPlusRing32>::Module<2> Param;
	Param::Matrix m;
	const auto E = m.ElementConstructor();
	{//zero matrix size 1
		m.Clear();
		m.AddRow();
		ExpectNoSolution(m);
	}
	{//zero matrix size 3
		m.Clear();
		m.AddRow();
		m.AddRow();
		m.AddRow();
		ExpectNoSolution(m);
	}
	{//identity matrix size 1
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u)}));
	}
	{//identity matrix size 3
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddRow();
		m.AddElement(1, 1u);
		m.AddRow();
		m.AddElement(2, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u)}));
	}
	{//matrix with only last column needed
		m.Clear();
		m.AddRow();
		m.AddElement(2, 1u);
		m.AddRow();
		m.AddElement(1, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(2, 1u)}));
	}
	{//matrix with big column number
		m.Clear();
		m.AddRow();
		m.AddElement(42, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(42, 1u)}));
	}
	{//matrix with single zero column
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		ExpectNoSolution(m);
	}
	{//matrix with single columnwith ones
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		ExpectNoSolution(m);
	}
	{//matrix with single columnw eqaul to result, non-obviousely initialized
		m.Clear();
		m.AddRow();
		m.AddElement(0, 3u);
		m.AddRow();
		m.AddElement(0, 2u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u)}));
	}
	{//matrix with every column needed in sum
		m.Clear();
		m.AddRow();
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(2, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u), E(1, 1u), E(2, 1u), E(3, 1u)}));
	}
	{//matrix with every column needed in sum - other column order
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(1, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(2, 1u);
		m.AddElement(3, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u), E(1, 1u), E(2, 1u), E(3, 1u)}));
	}
	{//matrix with NOT every column needed in sum
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(2, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddElement(3, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u), E(2, 1u)}));
	}
	{//matrix with NOT every column needed in sum - other column order
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(2, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddRow();
		m.AddElement(1, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddElement(3, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(1, 1u), E(3, 1u)}));
	}
	{//wide matrix with zero columns; wide matrix with non-zero columns would have non-determined result, so is not included in this test
		m.Clear();
		m.AddRow();
		m.AddElement(42, 1u);
		m.AddRow();
		m.AddElement(12, 1u);
		m.AddElement(32, 1u);
		m.AddElement(42, 1u);
		m.AddRow();
		m.AddElement(2, 1u);
		m.AddElement(32, 1u);
		m.AddRow();
		m.AddElement(2, 1u);
		m.AddElement(12, 1u);
		m.AddElement(32, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(2, 1u), E(32, 1u), E(42, 1u)}));
	}
	{//tall matrix
		m.Clear();
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddRow();
		m.AddElement(1, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(2, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddElement(3, 1u);
		m.AddElement(4, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(3, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddRow();
		m.AddElement(0, 1u);
		m.AddElement(1, 1u);
		m.AddElement(2, 1u);
		m.AddElement(3, 1u);
		m.AddElement(4, 1u);
		EXPECT_PRED2(ExpectKnownSolution, m, ilist({E(0, 1u), E(2, 1u), E(3, 1u), E(4, 1u)}));
	}
}
TEST_F(SampelCodeTest, testFunc3)
{
    int m = 5, n = 10;
    EXPECT_PRED2(MutuallyPrime, m, n);   
}     
예제 #12
0
파일: test1.cpp 프로젝트: whuthj/siren
TEST(Lesson2, section5)
{
    int m = 5, n = 6;
    EXPECT_PRED2(MutuallyPrime, m, n);
}