Example #1
0
void testFloatsEqual(void)
{
    TEST_ASSERT_EQUAL_FLOAT(187245.0f, 187246.0f);
    TEST_ASSERT_EQUAL_FLOAT(18724.5f, 18724.6f);
    TEST_ASSERT_EQUAL_FLOAT(9273.2549f, 9273.2599f);
    TEST_ASSERT_EQUAL_FLOAT(-726.93724f, -726.9374f);
}
static void test_GetLowerResistance(void)
{
	static float actual = PD_GetLowerResistance(10000, 3.3, 3.3/2);
	TEST_ASSERT_EQUAL_FLOAT(10000, actual);	

	actual = PD_GetLowerResistance(10000, 3.3, 3.3*2/3);
	TEST_ASSERT_EQUAL_FLOAT(20000, actual);
}
static void test_GetInputVoltage(void)
{
	static float actual = PD_GetInputVoltage(1.0, 10000, 10000);
	TEST_ASSERT_EQUAL_FLOAT(2.0, actual);

	actual = PD_GetInputVoltage(1.0, 20000, 10000);
	TEST_ASSERT_EQUAL_FLOAT(3.0, actual);
}
void test_CorrectFloatIsParsedFromSetting(void)
{
    float result;
    TEST_ASSERT_TRUE(Setting_parseSettingAsFloat(&result, "1.234"));
    TEST_ASSERT_EQUAL_FLOAT(1.234, result);

    TEST_ASSERT_TRUE(Setting_parseSettingAsFloat(&result, "-37.324"));
    TEST_ASSERT_EQUAL_FLOAT(-37.324, result);

    TEST_ASSERT_FALSE(Setting_parseSettingAsFloat(&result, "NOTAFLOAT"));
}
void test_fixed_divide(void)
{
  /* Negative */
  a = fixed_make(-2023.621F);
  b = fixed_make(10.0F);
  result = fixed_div(a, b);
  TEST_ASSERT_EQUAL_FLOAT(fixed_make(-202.3621F), result);

  /* Positive */
  a = fixed_make(2023.621F);
  b = fixed_make(10.0F);
  result = fixed_div(a, b);
  TEST_ASSERT_EQUAL_FLOAT(fixed_make(202.3621F), result);
}
void test_fixed_subtract(void)
{
  /* Negative value */
  a = fixed_make(-2023.621F);
  b = fixed_make(1.0F);
  result = fixed_sub(a, b);
  TEST_ASSERT_EQUAL_FLOAT(fixed_make(-2024.621F), result);

  /* Negation */
  a = fixed_make(2023.621F);
  b = fixed_make(2023.621F);
  result = fixed_sub(a, b);
  TEST_ASSERT_EQUAL_FLOAT(0.0F, fixed_float(result));
}
void testRunning(T * data_ptr, uint16_t size, T expected_result, float expectedFloatResult)
{
	Averager<T> averager = Averager<T>(size);
	averager.fillFromArray(data_ptr, size);
	TEST_ASSERT_EQUAL(expected_result, averager.getAverage());
	TEST_ASSERT_EQUAL_FLOAT(expectedFloatResult, averager.getFloatAverage());
}
Example #8
0
void test_limitFloat(void) {
    float actual = limitFloat(100.3f, 200.1f);
    TEST_ASSERT_EQUAL_FLOAT(100.3f, actual);

    actual = limitFloat(200.2f, 200.2f);
    TEST_ASSERT_EQUAL_FLOAT(200.2f, actual);

    actual = limitFloat(300.3f, 200.1f);
    TEST_ASSERT_EQUAL_FLOAT(200.1f, actual);

    actual = limitFloat(300.4f, -200.3f);
    TEST_ASSERT_EQUAL_FLOAT(-200.3f, actual);

    // 0 Value
    actual = limitFloat(0, 200.3f);
    TEST_ASSERT_EQUAL_FLOAT(0, actual);

    actual = limitFloat(-100.6f, 200.4f);
    TEST_ASSERT_EQUAL_FLOAT(-100.6f, actual);

    // When negative, must raise and error
    actual = limitFloat(-100.2f, -200.3f);
    TEST_ASSERT_EQUAL(LIMIT_ARGUMENT_MUST_BE_POSITIVE, getLastError());
    clearLastError();

    actual = limitFloat(-100.4f, 200.7f);
    TEST_ASSERT_EQUAL_FLOAT(-100.4f, actual);
}
void test_ValidCurrentSettingsAreParsedCorrectly(void)
{
    TEST_ASSERT_EQUAL(ERR_READER_NONE, Settings_parseDataChannelSetting("ch1.Type =Current", 13));
    TEST_ASSERT_EQUAL(CURRENT, Settings_GetChannelType(1));
    TEST_ASSERT_FALSE(Settings_ChannelSettingIsValid(1));

    TEST_ASSERT_EQUAL(ERR_READER_NONE, Settings_parseDataChannelSetting("channel1.mvperAmp= 400", 14));
    TEST_ASSERT_FALSE(Settings_ChannelSettingIsValid(1));

    TEST_ASSERT_EQUAL(ERR_READER_NONE, Settings_parseDataChannelSetting("channel1.offset = 12", 15));
    TEST_ASSERT_FALSE(Settings_ChannelSettingIsValid(1));

    TEST_ASSERT_EQUAL(ERR_READER_NONE, Settings_parseDataChannelSetting("channel1.mvperbit = 0.125", 16));
    TEST_ASSERT_TRUE(Settings_ChannelSettingIsValid(1));

    TEST_ASSERT_EQUAL_FLOAT(400.0, Settings_GetDataAsCurrent(1)->mvPerAmp);
    TEST_ASSERT_EQUAL_FLOAT(12.0, Settings_GetDataAsCurrent(1)->offset);
    TEST_ASSERT_EQUAL_FLOAT(0.125, Settings_GetDataAsCurrent(1)->mvPerBit);
}
void test_ValidVoltageSettingsAreParsedCorrectly(void)
{
    TEST_ASSERT_EQUAL(ERR_READER_NONE, Settings_parseDataChannelSetting("CH1.type =Voltage", 9));
    TEST_ASSERT_EQUAL(VOLTAGE, Settings_GetChannelType(1));
    TEST_ASSERT_FALSE(Settings_ChannelSettingIsValid(1));

    TEST_ASSERT_EQUAL(ERR_READER_NONE, Settings_parseDataChannelSetting("cH1.r1= 18300.0", 10));
    TEST_ASSERT_FALSE(Settings_ChannelSettingIsValid(1));

    TEST_ASSERT_EQUAL(ERR_READER_NONE, Settings_parseDataChannelSetting("ch1.R2 = 10000.0", 11));
    TEST_ASSERT_FALSE(Settings_ChannelSettingIsValid(1));

    TEST_ASSERT_EQUAL(ERR_READER_NONE, Settings_parseDataChannelSetting("ch1.mvperbit = 0.125", 12));
    TEST_ASSERT_TRUE(Settings_ChannelSettingIsValid(1));

    TEST_ASSERT_EQUAL_FLOAT(18300.0, Settings_GetDataAsVoltage(1)->R1);
    TEST_ASSERT_EQUAL_FLOAT(10000.0, Settings_GetDataAsVoltage(1)->R2);
    TEST_ASSERT_EQUAL_FLOAT(0.125, Settings_GetDataAsVoltage(1)->mvPerBit);
}
TEST(iir, iir_f_init)
{
  iir_f_t iir;

  /* Initialise IIR filter with an alpha of -0.01 */
  /* Alpha should be adjust to 0 */
  iir_f_init(&iir, -0.01F);
  TEST_ASSERT_EQUAL_FLOAT(0.0F, iir.alpha);

  /* Initialise IIR filter with an alpha of 1.1 */
  /* Alpha should be adjust to 1.0F */
  iir_f_init(&iir, 1.1F);
  TEST_ASSERT_EQUAL_FLOAT(1.0F, iir.alpha);

  /* Initialise IIR filter with an alpha of 0.01 */
  iir_f_init(&iir, 0.01);
  TEST_ASSERT_EQUAL_FLOAT(0.01F, iir.alpha);
  TEST_ASSERT_EQUAL_FLOAT(0.0F, iir.avg);
  TEST_ASSERT_EQUAL(0, iir.k);
}
Example #12
0
void testFloatsNotEqual(void)
{
    int failed;

    EXPECT_ABORT_BEGIN
    TEST_ASSERT_EQUAL_FLOAT(9273.9649f, 9273.0049f);
    EXPECT_ABORT_END

    failed = Unity.CurrentTestFailed;
    Unity.CurrentTestFailed = 0;

    VERIFY_FAILURE_WAS_CAUGHT
}
TEST(iir, iir_f_avg)
{
  iir_f_t iir;

  /* Initialise IIR filter with an alpha of 0.01 */
  iir_f_init(&iir, 0.01);

  /* Add some samples */
  iir_f_add(&iir, 10);
  iir_f_add(&iir, 20);
  iir_f_add(&iir, 30);
  iir_f_add(&iir, 35);

  /* With an alpha of 0.01 avg should be 10.546 */
  TEST_ASSERT_EQUAL_FLOAT(10.546F, iir.avg);
}
TEST(iir, iir_f_add)
{
  iir_f_t iir;

  /* Initialise IIR filter with an alpha of 0.01 */
  iir_f_init(&iir, 0.01);

  /* Add a sample */
  iir_f_add(&iir, 10);
  TEST_ASSERT_EQUAL(1, iir.k);
  TEST_ASSERT_EQUAL_FLOAT(10.0F, iir.avg);

  /* Add three more samples */
  iir_f_add(&iir, 11);
  iir_f_add(&iir, 12);
  iir_f_add(&iir, 13);
  TEST_ASSERT_EQUAL(4, iir.k);
}
Example #15
0
void test_KwattPris_diffrent_typ_of_values(void)
{
TEST_ASSERT_EQUAL_FLOAT(0.015, kwattPris(5, 3));
TEST_ASSERT_EQUAL_FLOAT(0, kwattPris(0, 0.1));
}
Example #16
0
void testFloatsNotEqualNegative2(void)
{
    EXPECT_ABORT_BEGIN
    TEST_ASSERT_EQUAL_FLOAT(-9273.0049f, -9273.9649f);
    VERIFY_FAILS_END
}
void test_params_set_properly()
{
  Game game_def = init_kuhn_poker_game_def();

  double params[NUM_PARAMS] = {0};
  params[C11_INDEX] = 0.5;
  params[B11_INDEX] = 0.25;
  params[B21_INDEX] = 1/2.0 - 2 * params[B11_INDEX];
  params[B23_INDEX] = (params[B11_INDEX] - params[B21_INDEX]) /
                      (2 * (1 - params[B21_INDEX]));
  params[B32_INDEX] = (2 + 4*params[B11_INDEX] + 3 * params[B21_INDEX]) / 4.0;
  params[C33_INDEX] = 1/2.0 - params[B32_INDEX] +
      (4 * params[B11_INDEX] + 3 * params[B21_INDEX]) / 4.0;
  params[C34_INDEX] = 3/4.0; // Unconstrained

  double b33 = (1.0 + params[B11_INDEX] + 2 * params[B21_INDEX]) / 2.0;
  double b41 = 2 * (params[B11_INDEX] + params[B21_INDEX]);

  CEXCEPTION_T e = 0;

  Try
  {
    Kuhn3pEquilibriumPlayer patient = new_kuhn_3p_equilibrium_player(
        &game_def,
        params,
        12
    );

    TEST_ASSERT_EQUAL_FLOAT(params[C11_INDEX], patient.params[C11_INDEX]);
    TEST_ASSERT_EQUAL_FLOAT(params[B11_INDEX], patient.params[B11_INDEX]);
    TEST_ASSERT_EQUAL_FLOAT(params[B21_INDEX], patient.params[B21_INDEX]);
    TEST_ASSERT_EQUAL_FLOAT(params[B23_INDEX], patient.params[B23_INDEX]);
    TEST_ASSERT_EQUAL_FLOAT(params[B32_INDEX], patient.params[B32_INDEX]);
    TEST_ASSERT_EQUAL_FLOAT(params[C33_INDEX], patient.params[C33_INDEX]);
    TEST_ASSERT_EQUAL_FLOAT(params[C34_INDEX], patient.params[C34_INDEX]);

    TEST_ASSERT_EQUAL_FLOAT(12, patient.seed);

    TEST_ASSERT_EQUAL_FLOAT(b33, patient.params[B33_INDEX]);
    TEST_ASSERT_EQUAL_FLOAT(b41, patient.params[B41_INDEX]);
    TEST_ASSERT_EQUAL_FLOAT(0.0, patient.params[C21_INDEX]);
  }
  Catch(e)
  {
    TEST_FAIL_MESSAGE("Should Not Have Thrown An Error");
  }
}