﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Subterfuge.Remake.Core.Generation;
using Subterfuge.Remake.Core.Timing;

namespace Subterfuge.Remake.Test
{
    [TestClass]
    public class NameGeneratorTest
    {
        private NameGenerator _generator;

        [TestInitialize]
        public void Setup()
        {
            _generator = new NameGenerator(new SeededRandom(1234));
        }

        [TestMethod]
        public void GeneratesRandomNames()
        {
            string name1 = _generator.GetRandomName();
            string name2 = _generator.GetRandomName();
            Assert.IsTrue(name1.Equals(name2) == false);
        }

        [TestMethod]
        public void NoDuplicatedNames()
        {
            List<string> strings = new List<string>();
            while (_generator.HasNames())
            {
                strings.Add(_generator.GetRandomName());
            }
            
            // Ensure no duplicates.
            Assert.AreEqual(strings.Count, strings.Distinct().Count());
        }

        [TestMethod]
        public void IfNoNamesLeftNoDuplicatesGenerated()
        {
            List<string> strings = new List<string>();
            while (_generator.HasNames())
            {
                strings.Add(_generator.GetRandomName());
            }
            
            // Generate 10000 more names.
            for (int i = 0; i < 10000; i++)
            {
                strings.Add(_generator.GetRandomName());
            }

            // Ensure no duplicates.
            Assert.AreEqual(strings.Count, strings.Distinct().Count());
        }

        [TestMethod]
        public void AllNamesStartCaptolizedOthersLower()
        {
            string name;
            while (_generator.HasNames())
            {
                name = _generator.GetRandomName();
                Assert.IsTrue(Char.IsUpper(name, 0));
            }
            
            // Generate 10000 more names.
            for (int i = 0; i < 10000; i++)
            {
                name = _generator.GetRandomName();
                Assert.IsTrue(Char.IsUpper(name, 0));
            }
        }
        
    }
}