Ejemplo n.º 1
0
TEST_F(RandomTests, Seed) {
    int a = rnd.nextInt(12345);

    Random rnd2;
    rnd2.setSeed(42);
    int b = rnd2.nextInt(12345);

    // almost always true
    EXPECT_THAT(a, Ne(b));
}
Ejemplo n.º 2
0
TEST_F(RandomTests, Shuffle) {
    vector<int> data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    rnd.shuffle(data.begin(), data.end());

    // almost always true
    EXPECT_THAT(data, Ne(vector<int>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}));

    sort(data.begin(), data.end());
    EXPECT_THAT(data, Eq(vector<int>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}));
}
Ejemplo n.º 3
0
TEST_F(VanishesBeforeTest, Dimensionless) {
  double const y = 3000.0 * std::numeric_limits<double>::epsilon();
  EXPECT_THAT(y, VanishesBefore(1000.0, 6));
  EXPECT_THAT(2 * y, Not(VanishesBefore(1000.0, 6)));
  double const δy = e / 100.0;
  double e_accumulated = 0.0;
  for (int i = 1; i <= 100.0; ++i) {
    e_accumulated += δy;
  }
  EXPECT_THAT(e_accumulated, Ne(e));
  EXPECT_THAT(e_accumulated - e, Not(VanishesBefore(e, 4)));
  EXPECT_THAT(e_accumulated - e, VanishesBefore(e, 1));
}
Ejemplo n.º 4
0
TEST_F(VanishesBeforeTest, Quantity) {
  Speed v1 = 1 * Knot;
  Speed const v2 = 3 * v1 * std::numeric_limits<double>::epsilon();
  EXPECT_THAT(v2, VanishesBefore(v1, 3));
  EXPECT_THAT(2 * v2, Not(VanishesBefore(v1, 3)));
  Speed const δv = v1 / 100;
  Speed v_accumulated;
  for (int i = 1; i <= 100; ++i) {
    v_accumulated += δv;
  }
  EXPECT_THAT(v_accumulated, Ne(v1));
  EXPECT_THAT(v_accumulated - v1, Not(VanishesBefore(v1, 8)));
  EXPECT_THAT(v_accumulated - v1, VanishesBefore(v1, 4));
}
Ejemplo n.º 5
0
TEST_F( ZDevicesTest, diff_with_2_devices) {
	zDevices->put(annunce1);
	zDevices->put(annunce2);
	ptree properties = zDevices->getDifferences(0);
	ASSERT_THAT(properties.size(), Eq(3));
	ASSERT_THAT(properties.get<int>(TOKEN_NAME), Ne(0));

	ASSERT_THAT(properties.count(DEVICE),2);
	auto devices = properties.equal_range(DEVICE);
	ptree firstDevice = (*(devices.first)).second;
	devices.first++;
	ptree secondDevice = (*(devices.first)).second;

	ASSERT_THAT(firstDevice.get<int>(SHORT_ADDR_NAME), Eq(annunce1.nwkAddr));
	ASSERT_THAT(firstDevice.get<int>(CAPABILITY_NAME), Eq(annunce1.capabilities));
	ASSERT_THAT(firstDevice.get<std::string>(EXT_ADDR_NAME), Eq(extAddr1));
	ASSERT_THAT(secondDevice.get<int>(SHORT_ADDR_NAME), Eq(annunce2.nwkAddr));
	ASSERT_THAT(secondDevice.get<int>(CAPABILITY_NAME), Eq(annunce2.capabilities));
	ASSERT_THAT(secondDevice.get<std::string>(EXT_ADDR_NAME), Eq(extAddr2));
}
Ejemplo n.º 6
0
TEST_P(SRKNTest, ExactInexactTMax) {
  parameters_.initial.positions.emplace_back(SIUnit<Length>());
  parameters_.initial.momenta.emplace_back(Speed());
  parameters_.initial.time = Time();
  parameters_.tmax = 10.0 * SIUnit<Time>();
  parameters_.sampling_period = 1;
  parameters_.Δt = (1.0 / 3.000001) * SIUnit<Time>();
  parameters_.tmax_is_exact = false;
  integrator_->SolveTrivialKineticEnergyIncrement<Length>(
      &ComputeHarmonicOscillatorAcceleration,
      parameters_,
      &solution_);
  EXPECT_EQ(30, solution_.size());
  EXPECT_THAT(solution_.back().time.value, Lt(parameters_.tmax));
  EXPECT_THAT(solution_.back().time.error, Ne(0.0 * SIUnit<Time>()));

  parameters_.tmax_is_exact = true;
  integrator_->SolveTrivialKineticEnergyIncrement<Length>(
      &ComputeHarmonicOscillatorAcceleration,
      parameters_,
      &solution_);
  EXPECT_EQ(30, solution_.size());
  EXPECT_THAT(solution_.back().time.value, Eq(parameters_.tmax));
  EXPECT_THAT(solution_.back().time.error, Eq(0.0 * SIUnit<Time>()));

  parameters_.Δt = (1.0 / 2.999999) * SIUnit<Time>();
  parameters_.tmax_is_exact = false;
  integrator_->SolveTrivialKineticEnergyIncrement<Length>(
      &ComputeHarmonicOscillatorAcceleration,
      parameters_,
      &solution_);
  EXPECT_EQ(29, solution_.size());
  EXPECT_THAT(solution_.back().time.value, Lt(parameters_.tmax));
  EXPECT_THAT(solution_.back().time.error, Ne(0.0 * SIUnit<Time>()));

  parameters_.tmax_is_exact = true;
  integrator_->SolveTrivialKineticEnergyIncrement<Length>(
      &ComputeHarmonicOscillatorAcceleration,
      parameters_,
      &solution_);
  EXPECT_EQ(30, solution_.size());
  EXPECT_THAT(solution_.back().time.value, Eq(parameters_.tmax));
  EXPECT_THAT(solution_.back().time.error, Eq(0.0 * SIUnit<Time>()));

  parameters_.Δt = 11.0 * SIUnit<Time>();
  parameters_.tmax_is_exact = false;
  integrator_->SolveTrivialKineticEnergyIncrement<Length>(
      &ComputeHarmonicOscillatorAcceleration,
      parameters_,
      &solution_);
  EXPECT_EQ(0, solution_.size());

  parameters_.tmax_is_exact = true;
  integrator_->SolveTrivialKineticEnergyIncrement<Length>(
      &ComputeHarmonicOscillatorAcceleration,
      parameters_,
      &solution_);
  EXPECT_EQ(1, solution_.size());
  EXPECT_THAT(solution_.back().time.value, Eq(parameters_.tmax));
  EXPECT_THAT(solution_.back().time.error, Eq(0.0 * SIUnit<Time>()));

  parameters_.Δt = 100.0 * SIUnit<Time>();
  parameters_.tmax_is_exact = false;
  integrator_->SolveTrivialKineticEnergyIncrement<Length>(
      &ComputeHarmonicOscillatorAcceleration,
      parameters_,
      &solution_);
  EXPECT_EQ(0, solution_.size());

  parameters_.tmax_is_exact = true;
  integrator_->SolveTrivialKineticEnergyIncrement<Length>(
      &ComputeHarmonicOscillatorAcceleration,
      parameters_,
      &solution_);
  EXPECT_EQ(1, solution_.size());
  EXPECT_THAT(solution_.back().time.value, Eq(parameters_.tmax));
  EXPECT_THAT(solution_.back().time.error, Eq(0.0 * SIUnit<Time>()));
}