#include "unity.h"
#include "unity_test_module.h"
#include "parity.h"

// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number
#define MY_RUN_TEST(func) RUN_TEST(func, 0)

extern void parity_setUp(void){
    // This is run before EACH test
}

extern void parity_tearDown(void){
    // This is run after EACH test
}

void test_calculate_parity_bits_all_zeros(void) {
    uint8_t p0, p1, p2;
    calculate_parity_bits(0x00, &p0, &p1, &p2);
    TEST_ASSERT_EQUAL_UINT8(0, p0);
    TEST_ASSERT_EQUAL_UINT8(0, p1);
    TEST_ASSERT_EQUAL_UINT8(0, p2);
}

void test_calculate_parity_bits_all_ones(void) {
    uint8_t p0, p1, p2;
    calculate_parity_bits(0x0F, &p0, &p1, &p2);
    // 0x0F = 1111
    // dus p0, p1 en p2 zijn '1'
    TEST_ASSERT_EQUAL_UINT8(1, p0);
    TEST_ASSERT_EQUAL_UINT8(1, p1);
    TEST_ASSERT_EQUAL_UINT8(1, p2);
}

// Update run_parity_tests function
void run_parity_tests(void) {
    UnityRegisterSetupTearDown(parity_setUp, parity_tearDown);
    
    MY_RUN_TEST(test_calculate_parity_bits_all_zeros);
    MY_RUN_TEST(test_calculate_parity_bits_all_ones);
    
    UnityUnregisterSetupTearDown();
}