finished adidas v1.0
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"decode.h": "c"
|
"decode.h": "c",
|
||||||
|
"unity_test_module.h": "c"
|
||||||
},
|
},
|
||||||
"cmake.sourceDirectory": "/home/rens/files/T2/HC/holyc-lang/src"
|
"cmake.sourceDirectory": "/home/rens/files/T2/HC/holyc-lang/src"
|
||||||
}
|
}
|
||||||
BIN
C/C5 and C6 Adidas/build/main_test
Normal file → Executable file
BIN
C/C5 and C6 Adidas/build/main_test
Normal file → Executable file
Binary file not shown.
@@ -1,10 +1,16 @@
|
|||||||
#include "channel.h"
|
#include "channel.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
// add here your implementation
|
#include <stdlib.h>
|
||||||
void channel_init(){
|
|
||||||
|
|
||||||
|
void channel_init(){
|
||||||
|
srand((unsigned int)time(NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t channel_change_one_random_bit(uint8_t value){
|
uint8_t channel_change_one_random_bit(uint8_t value){
|
||||||
|
// Generate random bit position (0-7)
|
||||||
|
uint8_t bit_position = rand() % 8;
|
||||||
|
uint8_t bit_mask = 1 << bit_position;
|
||||||
|
// XOR with the mask to flip the bit
|
||||||
|
// 01101010 with mask 00000100 becomes 01101110
|
||||||
|
return value ^ bit_mask;
|
||||||
}
|
}
|
||||||
@@ -5,9 +5,9 @@ uint8_t decode_combine_nibbles(uint8_t high, uint8_t low){
|
|||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
uint8_t high_nibble;
|
uint8_t high_nibble;
|
||||||
uint8_t low_nibble;
|
uint8_t low_nibble;
|
||||||
decode_byte(high,high_nibble);
|
decode_byte(high,&high_nibble);
|
||||||
decode_byte(low,low_nibble);
|
decode_byte(low,&low_nibble);
|
||||||
combine_nibles_to_byte(high_nibble, low_nibble, byte);
|
combine_nibles_to_byte(high_nibble, low_nibble, &byte);
|
||||||
return byte;
|
return byte;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,26 +6,28 @@
|
|||||||
// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number
|
// 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)
|
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
|
||||||
|
|
||||||
extern void channel_setUp(void)
|
extern void channel_setUp(void){
|
||||||
{
|
channel_init();
|
||||||
// This is run before EACH test
|
}
|
||||||
|
extern void channel_tearDown(void) {}
|
||||||
|
|
||||||
|
void test_channel_all_zero_test(){
|
||||||
|
uint8_t value = 0x00;
|
||||||
|
uint8_t result = channel_change_one_random_bit(value);
|
||||||
|
TEST_ASSERT_NOT_EQUAL(value, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void channel_tearDown(void)
|
void test_channel_all_one_test(){
|
||||||
{
|
uint8_t value = 0xFF;
|
||||||
// This is run after EACH test
|
uint8_t result = channel_change_one_random_bit(value);
|
||||||
|
TEST_ASSERT_NOT_EQUAL(value, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_channel(void)
|
void run_channel_tests(){
|
||||||
{
|
|
||||||
TEST_ASSERT_EQUAL(1, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void run_channel_tests()
|
|
||||||
{
|
|
||||||
UnityRegisterSetupTearDown( channel_setUp, channel_tearDown);
|
UnityRegisterSetupTearDown( channel_setUp, channel_tearDown);
|
||||||
|
|
||||||
MY_RUN_TEST(test_channel);
|
MY_RUN_TEST(test_channel_all_zero_test);
|
||||||
|
MY_RUN_TEST(test_channel_all_one_test);
|
||||||
|
|
||||||
UnityUnregisterSetupTearDown();
|
UnityUnregisterSetupTearDown();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,26 +5,61 @@
|
|||||||
// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number
|
// 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)
|
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
|
||||||
|
|
||||||
extern void decode_setUp(void)
|
extern void decode_setUp(void) {}
|
||||||
{
|
extern void decode_tearDown(void) {}
|
||||||
// This is run before EACH test
|
// Format: [0][d3][d2][d1][d0][p2][p1][p0] (MSB first)
|
||||||
}
|
|
||||||
|
|
||||||
extern void decode_tearDown(void)
|
//general decode combine nibbles test
|
||||||
{
|
void test_decode_get_nibbles_normal(void){
|
||||||
// This is run after EACH test
|
uint8_t high = 0b01101100, low = 0b01001001;
|
||||||
|
// high data: 1101 or 0xD and low data: 1001 or 0x9
|
||||||
|
TEST_ASSERT_EQUAL(0xD9, decode_combine_nibbles(high, low)); // so the result should be 0b11011001 or 0xD9
|
||||||
}
|
}
|
||||||
|
void test_decode_get_nibbles_zero(void){
|
||||||
void test_decode(void)
|
uint8_t high = 0b00000000, low = 0b00000000;
|
||||||
{
|
// high data: 0000 or 0x0 and low data: 0000 or 0x0
|
||||||
TEST_ASSERT_EQUAL(1, 0);
|
TEST_ASSERT_EQUAL(0x00, decode_combine_nibbles(high, low)); // so the result should be 0b00000000 or 0x00
|
||||||
}
|
}
|
||||||
|
void test_decode_get_nibbles_all_ones(void){
|
||||||
void run_decode_tests()
|
uint8_t high = 0b11111111, low = 0b11111111;
|
||||||
{
|
// high data: 1111 or 0xF and low data: 1111 or 0xF
|
||||||
|
TEST_ASSERT_EQUAL(0xFF, decode_combine_nibbles(high, low)); // so the result should be 0b11111111 or 0xFF
|
||||||
|
}
|
||||||
|
void test_decode_MSB_flip (void){
|
||||||
|
uint8_t high = 0b11101100, low = 0b11001001;
|
||||||
|
// high data: 1101 or 0xD and low data: 1001 or 0x9
|
||||||
|
// but the MSB is flipped
|
||||||
|
TEST_ASSERT_EQUAL(0xD9, decode_combine_nibbles(high, low)); // so the result should be 0b11011001 or 0xD9
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// parity bit testing
|
||||||
|
void test_decode_databit_flip (void){
|
||||||
|
uint8_t wrong_data = 0b01001100; // this should be 0b01101100 or unparityd 0b1101, 0xD
|
||||||
|
uint8_t right_data; // this is the correct data
|
||||||
|
decode_byte(wrong_data, &right_data);
|
||||||
|
TEST_ASSERT_EQUAL(0xD, right_data); // so the result should be 0b01101100 or 0xD
|
||||||
|
}
|
||||||
|
void test_decode_common_databit_flip (void){ // the common databit is d0
|
||||||
|
uint8_t wrong_data = 0b01100100; // this should be 0b01101100 or unparityd 0b1101, 0xD
|
||||||
|
uint8_t right_data; // this is the correct data
|
||||||
|
decode_byte(wrong_data, &right_data);
|
||||||
|
TEST_ASSERT_EQUAL(0xD, right_data); // so the result should be 0b01101100 or 0xD
|
||||||
|
}
|
||||||
|
void test_decode_parity_flip(void){
|
||||||
|
uint8_t wrong_data = 0b01101101; // this should be 0b01101100 or unparityd 0b1101, 0xD
|
||||||
|
uint8_t right_data; // this is the correct data
|
||||||
|
decode_byte(wrong_data, &right_data);
|
||||||
|
TEST_ASSERT_EQUAL(0xD, right_data); // so the result should be 0b01101100 or 0xD
|
||||||
|
}
|
||||||
|
//
|
||||||
|
void run_decode_tests(){
|
||||||
UnityRegisterSetupTearDown(decode_setUp, decode_tearDown);
|
UnityRegisterSetupTearDown(decode_setUp, decode_tearDown);
|
||||||
|
|
||||||
MY_RUN_TEST(test_decode);
|
MY_RUN_TEST(test_decode_get_nibbles_normal);
|
||||||
|
MY_RUN_TEST(test_decode_get_nibbles_zero);
|
||||||
|
MY_RUN_TEST(test_decode_get_nibbles_all_ones);
|
||||||
|
MY_RUN_TEST(test_decode_MSB_flip);
|
||||||
|
MY_RUN_TEST(test_decode_databit_flip);
|
||||||
|
|
||||||
UnityUnregisterSetupTearDown();
|
UnityUnregisterSetupTearDown();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user