#include <gtest/gtest.h>
#include <solution/1290.h>

class GetDecimalValueTest : public ::testing::Test
{
  protected:
    // 构建链表：vector -> ListNode*
    ListNode *buildList(const std::vector<int> &values)
    {
        ListNode dummy{0, nullptr};
        ListNode *current = &dummy;
        for (int v : values)
        {
            current->next = new ListNode{v, nullptr};
            current = current->next;
        }
        return dummy.next;
    }

    // 释放链表
    void freeList(ListNode *head)
    {
        while (head)
        {
            ListNode *tmp = head;
            head = head->next;
            delete tmp;
        }
    }
};

// 示例 1: [1, 0, 1] → 5
TEST_F(GetDecimalValueTest, Binary101)
{
    ListNode *head = buildList({1, 0, 1});
    int expected = 5;
    EXPECT_EQ(getDecimalValue(head), expected);
    freeList(head);
}

// 示例 2: [0] → 0
TEST_F(GetDecimalValueTest, Binary0)
{
    ListNode *head = buildList({0});
    int expected = 0;
    EXPECT_EQ(getDecimalValue(head), expected);
    freeList(head);
}