// ---------------------------------------------------------------------------
// BT.Framework.Tests
// ObservableQueueTests.cs — ObservableQueue 단위 테스트
// ---------------------------------------------------------------------------
using System.Collections.Generic;
using NUnit.Framework;
using BurningTimes.Core.Container;

namespace BurningTimes.Tests.Core.Container
{
    public class ObservableQueueTests
    {
        [Test]
        public void Enqueue_EmitsEnqueued()
        {
            var q = new ObservableQueue<int>();
            var items = new List<int>();
            q.Enqueued += items.Add;

            q.Enqueue(1);
            q.Enqueue(2);

            Assert.That(items, Is.EqualTo(new[] { 1, 2 }));
        }

        [Test]
        public void Dequeue_EmitsDequeuedAndReturnsFifo()
        {
            var q = new ObservableQueue<int>();
            q.Enqueue(1);
            q.Enqueue(2);
            var items = new List<int>();
            q.Dequeued += items.Add;

            int a = q.Dequeue();
            int b = q.Dequeue();

            Assert.That(a, Is.EqualTo(1));
            Assert.That(b, Is.EqualTo(2));
            Assert.That(items, Is.EqualTo(new[] { 1, 2 }));
        }

        [Test]
        public void TryDequeue_OnEmpty_ReturnsFalse()
        {
            var q = new ObservableQueue<int>();
            int emitted = 0;
            q.Dequeued += _ => emitted++;

            Assert.IsFalse(q.TryDequeue(out _));
            Assert.That(emitted, Is.EqualTo(0));
        }

        [Test]
        public void Peek_DoesNotEmit()
        {
            var q = new ObservableQueue<int>();
            q.Enqueue(42);
            int emitted = 0;
            q.Dequeued += _ => emitted++;

            Assert.That(q.Peek(), Is.EqualTo(42));
            Assert.That(emitted, Is.EqualTo(0));
        }

        [Test]
        public void Clear_EmitsReset()
        {
            var q = new ObservableQueue<int>();
            q.Enqueue(1);
            int resetCount = 0;
            q.Reset += () => resetCount++;

            q.Clear();

            Assert.That(resetCount, Is.EqualTo(1));
            Assert.That(q.Count, Is.EqualTo(0));
        }

        [Test]
        public void Clear_OnEmpty_DoesNotEmit()
        {
            var q = new ObservableQueue<int>();
            int resetCount = 0;
            q.Reset += () => resetCount++;

            q.Clear();

            Assert.That(resetCount, Is.EqualTo(0));
        }
    }
}
