#include "unity.h"
#include "puzzle_state.h"

TEST_CASE("assembles the code from reported fragments", "[pstate]")
{
    puzzle_state_t s;
    puzzle_state_init(&s);
    puzzle_state_report(&s, /*id=*/1, (const uint8_t[]){1,2,0,0}, 2);
    puzzle_state_report(&s, /*id=*/3, (const uint8_t[]){3,4,0,0}, 2);
    char code[16];
    TEST_ASSERT_EQUAL_INT(4, puzzle_state_code(&s, code, sizeof(code)));
    TEST_ASSERT_EQUAL_STRING("1234", code);
}

TEST_CASE("a puzzle reported twice does not duplicate its digits", "[pstate]")
{
    puzzle_state_t s;
    puzzle_state_init(&s);
    puzzle_state_report(&s, 1, (const uint8_t[]){1,2,0,0}, 2);
    puzzle_state_report(&s, 1, (const uint8_t[]){1,2,0,0}, 2);
    char code[16];
    TEST_ASSERT_EQUAL_INT(2, puzzle_state_code(&s, code, sizeof(code)));
    TEST_ASSERT_EQUAL_STRING("12", code);
}
