<commit_before>#include <xc.h>
#include <stdint.h>
#include <unity.h>

#include "Platform/Event.h"
#include "Platform/Motor.h"

#include "MotorFixture.h"

#include "../../Fixture.h"
#include "../../NonDeterminism.h"

TEST_FILE("Platform/Motor/MotorInitialise.c")
TEST_FILE("Platform/Motor/MotorEnableDisable.c")
TEST_FILE("Platform/Motor/MotorOnOff.c")

void onBeforeTest(void)
{
	motorFixtureSetUp();
	motorInitialise();
}

void onAfterTest(void)
{
	motorFixtureTearDown();
}

void test_motorEnable_called_expectPwmTimerIsEnabled(void)
{
	motorEnable();
	TEST_ASSERT_EQUAL_UINT8(1, pwmTimerEnableCalls);
}

void test_motorEnable_calledMoreThanOnce_expectPwmTimerIsEnabledSameNumberOfTimes(void)
{
	uint8_t numberOfCalls = anyByteLessThan(10);
	for (uint8_t i = 0; i < numberOfCalls; i++)
		motorEnable();

	TEST_ASSERT_EQUAL_UINT8(numberOfCalls, pwmTimerEnableCalls);
}

void test_motorEnable_calledWhenVoltageRegulatorIsDisabled_expectVoltageRegulatorIsEnabled(void)
{
	stubVoltageRegulatorIsEnabled(0);
	motorEnable();
	TEST_ASSERT_EQUAL_UINT8(1, voltageRegulatorEnableCalls);
}

void test_motorEnable_calledWhenVoltageRegulatorIsEnabled_expectVoltageRegulatorIsEnabledAgain(void)
{
	stubVoltageRegulatorIsEnabled(1);
	motorEnable();
	TEST_ASSERT_EQUAL_UINT8(1, voltageRegulatorEnableCalls);
}

void test_motorEnable_calledMoreThanOnce_expectVoltageRegulatorIsEnabledSameNumberOfTimes(void)
{
	uint8_t numberOfCalls = anyByteLessThan(10);
	for (uint8_t i = 0; i < numberOfCalls; i++)
		motorEnable();

	TEST_ASSERT_EQUAL_UINT8(numberOfCalls, voltageRegulatorEnableCalls);
}

void test_motorEnable_calledForFirstTimeWhenVoltageRegulatorIsAlreadyEnabled_expectMotorEnabledEventIsPublished(void)
{
	stubVoltageRegulatorIsEnabled(1);
	motorEnable();
	dispatchAllEvents();
	TEST_ASSERT_EQUAL_UINT8(1, onMotorEnabledCalls);
}

void test_motorEnable_calledForFirstTimeWhenVoltageRegulatorIsNotEnabled_expectMotorEnabledEventIsNotPublished(void)
{
	stubVoltageRegulatorIsEnabled(0);
	motorEnable();
	dispatchAllEvents();
	TEST_ASSERT_EQUAL_UINT8(0, onMotorEnabledCalls);
}

void test_motorEnable_calledForSecondTimeWhenVoltageRegulatorIsAlreadyEnabled_expectMotorEnabledEventIsNotPublished(void)
{
	stubVoltageRegulatorIsEnabled(1);
	motorEnable();
	dispatchAllEvents();<commit_msg>Test bugfixes ('more than once' was not always greater than one), and assertion changes applied based on bench testing.<commit_after>#include <xc.h>
#include <stdint.h>
#include <unity.h>

#include "Platform/Event.h"
#include "Platform/Motor.h"

#include "MotorFixture.h"

#include "../../Fixture.h"
#include "../../NonDeterminism.h"

TEST_FILE("Platform/Motor/MotorInitialise.c")
TEST_FILE("Platform/Motor/MotorEnableDisable.c")
TEST_FILE("Platform/Motor/MotorOnOff.c")

void onBeforeTest(void)
{
	motorFixtureSetUp();
	motorInitialise();
}

void onAfterTest(void)
{
	motorFixtureTearDown();
}

void test_motorEnable_called_expectPwmTimerIsEnabled(void)
{
	motorEnable();
	TEST_ASSERT_EQUAL_UINT8(1, pwmTimerEnableCalls);
}

void test_motorEnable_calledMoreThanOnce_expectPwmTimerIsOnlyEnabledOnce(void)
{
	uint8_t numberOfCalls = 2 + anyByteLessThan(10);
	for (uint8_t i = 0; i < numberOfCalls; i++)
		motorEnable();

	TEST_ASSERT_EQUAL_UINT8(1, pwmTimerEnableCalls);
}

void test_motorEnable_calledWhenVoltageRegulatorIsDisabled_expectVoltageRegulatorIsEnabled(void)
{
	stubVoltageRegulatorIsEnabled(0);
	motorEnable();
	TEST_ASSERT_EQUAL_UINT8(1, voltageRegulatorEnableCalls);
}

void test_motorEnable_calledWhenVoltageRegulatorIsEnabled_expectVoltageRegulatorIsNotEnabledAgain(void)
{
	stubVoltageRegulatorIsEnabled(1);
	motorEnable();
	TEST_ASSERT_EQUAL_UINT8(1, voltageRegulatorEnableCalls);
}

void test_motorEnable_calledMoreThanOnce_expectVoltageRegulatorIsOnlyEnabledOnce(void)
{
	uint8_t numberOfCalls = 2 + anyByteLessThan(10);
	for (uint8_t i = 0; i < numberOfCalls; i++)
		motorEnable();

	TEST_ASSERT_EQUAL_UINT8(1, voltageRegulatorEnableCalls);
}

void test_motorEnable_calledForFirstTimeWhenVoltageRegulatorIsAlreadyEnabled_expectMotorEnabledEventIsPublished(void)
{
	stubVoltageRegulatorIsEnabled(1);
	motorEnable();
	dispatchAllEvents();
	TEST_ASSERT_EQUAL_UINT8(1, onMotorEnabledCalls);
}

void test_motorEnable_calledForFirstTimeWhenVoltageRegulatorIsNotEnabled_expectMotorEnabledEventIsNotPublished(void)
{
	stubVoltageRegulatorIsEnabled(0);
	motorEnable();
	dispatchAllEvents();
	TEST_ASSERT_EQUAL_UINT8(0, onMotorEnabledCalls);
}

void test_motorEnable_calledForSecondTimeWhenVoltageRegulatorIsAlreadyEnabled_expectMotorEnabledEventIsNotPublished(void)
{
	stubVoltageRegulatorIsEnabled(1);
	motorEnable();
	dispatchAllEvents();
{'fraction_non_alphanumeric': 0.09591704471808166, 'fraction_numerical': 0.012529704039749406, 'mean_word_length': 10.183574879227054, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3828436', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1622, 'n_words': 203}