package com.chick_mood.data.model

import org.junit.Assert.*
import org.junit.Test

/**
 * Emotion枚举的单元测试
 * 测试情绪类型枚举的各种功能
 *
 * @author Claude
 * @date 2025-10-22
 */
class EmotionTest {

    /**
     * 测试情绪枚举的基本属性
     */
    @Test
    fun testEmotionBasicProperties() {
        assertEquals("开心", Emotion.HAPPY.displayName)
        assertEquals("#FFAB76", Emotion.HAPPY.colorValue)
        assertEquals(1, Emotion.HAPPY.chickExpression)

        assertEquals("生气", Emotion.ANGRY.displayName)
        assertEquals("#D9534F", Emotion.ANGRY.colorValue)
        assertEquals(2, Emotion.ANGRY.chickExpression)

        assertEquals("悲伤", Emotion.SAD.displayName)
        assertEquals("#5DADE2", Emotion.SAD.colorValue)
        assertEquals(3, Emotion.SAD.chickExpression)

        assertEquals("烦恼", Emotion.WORRIED.displayName)
        assertEquals("#95A5A6", Emotion.WORRIED.colorValue)
        assertEquals(4, Emotion.WORRIED.chickExpression)

        assertEquals("孤单", Emotion.LONELY.displayName)
        assertEquals("#AF7AC5", Emotion.LONELY.colorValue)
        assertEquals(5, Emotion.LONELY.chickExpression)

        assertEquals("害怕", Emotion.SCARED.displayName)
        assertEquals("#F4D03F", Emotion.SCARED.colorValue)
        assertEquals(6, Emotion.SCARED.chickExpression)
    }

    /**
     * 测试根据数值获取情绪枚举
     */
    @Test
    fun testFromValue() {
        assertEquals(Emotion.HAPPY, Emotion.fromValue(1))
        assertEquals(Emotion.ANGRY, Emotion.fromValue(2))
        assertEquals(Emotion.SAD, Emotion.fromValue(3))
        assertEquals(Emotion.WORRIED, Emotion.fromValue(4))
        assertEquals(Emotion.LONELY, Emotion.fromValue(5))
        assertEquals(Emotion.SCARED, Emotion.fromValue(6))

        // 测试无效值，应该返回默认的HAPPY
        assertEquals(Emotion.HAPPY, Emotion.fromValue(0))
        assertEquals(Emotion.HAPPY, Emotion.fromValue(7))
        assertEquals(Emotion.HAPPY, Emotion.fromValue(-1))
        assertEquals(Emotion.HAPPY, Emotion.fromValue(100))
    }

    /**
     * 测试获取所有情绪显示名称
     */
    @Test
    fun testGetAllDisplayNames() {
        val displayNames = Emotion.getAllDisplayNames()
        assertEquals(6, displayNames.size)
        assertTrue(displayNames.contains("开心"))
        assertTrue(displayNames.contains("生气"))
        assertTrue(displayNames.contains("悲伤"))
        assertTrue(displayNames.contains("烦恼"))
        assertTrue(displayNames.contains("孤单"))
        assertTrue(displayNames.contains("害怕"))
    }

    /**
     * 测试获取颜色资源ID
     */
    @Test
    fun testGetColorResourceId() {
        // 验证所有情绪都能返回有效的颜色资源ID
        for (emotion in Emotion.values()) {
            val colorId = emotion.getColorResourceId()
            assertTrue("Color resource ID should be positive", colorId > 0)
        }
    }

    /**
     * 测试情绪枚举值的唯一性
     */
    @Test
    fun testEmotionValueUniqueness() {
        val values = Emotion.values().map { it.chickExpression }
        val uniqueValues = values.toSet()
        assertEquals("Emotion values should be unique", values.size, uniqueValues.size)
    }

    /**
     * 测试情绪显示名称的唯一性
     */
    @Test
    fun testEmotionDisplayNameUniqueness() {
        val displayNames = Emotion.values().map { it.displayName }
        val uniqueDisplayNames = displayNames.toSet()
        assertEquals("Emotion display names should be unique",
                    displayNames.size, uniqueDisplayNames.size)
    }

    /**
     * 测试所有情绪都有有效的颜色值
     */
    @Test
    fun testAllEmotionsHaveValidColorValues() {
        for (emotion in Emotion.values()) {
            assertNotNull("Color value should not be null", emotion.colorValue)
            assertTrue("Color value should start with #",
                      emotion.colorValue.startsWith("#"))
            assertEquals("Color value should be 7 characters long",
                        7, emotion.colorValue.length)
        }
    }
}