#include "tempSensor.h"
#include "unity.h"

/* Include files generated automatically generated by CMock. */
#include "mock_i2c.h"


const uint8_t TEMP_REGISTER_ADDRESS = 0x03;
const float TEMP_TOLERANCE = 0.1f;


void setUp(void)
{
    /* Do nothing. */
}


void tearDown(void)
{
    /* Do nothing. */
}


void test_whenTempRegisterReadsMaxValue_thenTheTempIsTheMaxValue(void)
{    
    float expectedTemp = 104.6f;
    
    /* When mocked temperature sensor holds 0x3ff. */
    i2c_readRegister_ExpectAndReturn(TEMP_REGISTER_ADDRESS, 0x3ff);
    
    /* Then get temperature based on calcualtions in our function. */
    float actualTemperature = tempSensor_getTemperature();

    /* And finally test that we got the expected temperature. */
    TEST_ASSERT_FLOAT_WITHIN(TEMP_TOLERANCE, expectedTemp, actualTemperature);
}


void test_whenTempRegisterReadsMinValue_thenTheTempIsTheMinValue(void)
{
    float expectedTemp = -100.0f;

    /* When mocked temperature sensor holds 0x0. */
    i2c_readRegister_ExpectAndReturn(TEMP_REGISTER_ADDRESS, 0x0);
    
    /* Then get temperature based on calcualtions in our function. */
    float actualTemperature = tempSensor_getTemperature();

    /* And finally test that we got the expected temperature. */
    TEST_ASSERT_FLOAT_WITHIN(TEMP_TOLERANCE, expectedTemp, actualTemperature);
}
