<commit_before>﻿using NUnit.Framework;
using System.Linq;
using Workbench.Core.Models;
using Workbench.Core.Solver;

namespace Workbench.Core.Tests.Unit
{
    /// <summary>
    /// Placeholder for a well known test that will use the character range successfully.
    /// </summary>
    [TestFixture]
    public class CharacterSolverShould
    {
        [Test]
        public void SolveWithCharacterModelReturnsStatusSuccess()
        {
            var sut = CreateWorkspace();
            var actualResult = sut.Solve();
            Assert.That(actualResult.Status, Is.EqualTo(SolveStatus.Success));
        }

        [Test]
        public void SolveWithCharacterModelReturnsValidSnapshot()
        {
            var sut = CreateWorkspace();
            var actualResult = sut.Solve();
            var aValue = actualResult.Snapshot.GetAggregateVariableValueByName("a");
            var actualSolverValues = aValue.Bindings.Select(_ => _.Solver).ToList();
            var actualModelValues = aValue.Bindings.Select(_ => _.Model).ToList();
            Assert.That(aValue.Values, Is.Unique);
            Assert.That(aValue.Value, Is.TypeOf<char>());
            Assert.That(actualSolverValues, Is.All.InRange(1, 26));
            Assert.That(actualModelValues, Is.All.InRange('a', 'z')
                                                 .Using(new CharacterRangeComparer()));
        }

        [Test]
        public void SolveWithCharacterModelReturnsValidCharacterModelBinding()
        {
            var sut = CreateWorkspace();
            var actualResult = sut.Solve();
            var bValue = actualResult.Snapshot.GetSingletonVariableValueByName("b");
            var bValueBinding = bValue.Bindings.First();
            Assert.That(bValueBinding.Solver, Is.InRange(1, 26));
            Assert.That(bValueBinding.Model, Is.InRange('a', 'z')
                                               .Using(new CharacterRangeComparer()));
        }

        /// <summary>
        /// For a value binding for a number range, the model and solver values 
        /// should be the same.
        /// </summary>
        [Test]
        public void SolveWitCharacterModelReturnsValidNumberModelBinding()
        {
            var sut = CreateWorkspace();
            var actualResult = sut.Solve();
            var cValue = actualResult.Snapshot.GetSingletonVariableValueByName("c");
            var cValueBinding = cValue.Bindings.First();
            Assert.That(cValueBinding.Solver, Is.InRange(1, 26));
            Assert.That(cValueBinding.Model, Is.InRange(1, 26));
            Assert.That(cValueBinding.Solver, Is.EqualTo(cValueBinding.Model));
        }

        private static WorkspaceModel CreateWorkspace()
        {
            var workspace = WorkspaceModel.Create("A made up test")
                                          .AddAggregate("a", 26, "'a'..'z'")<commit_msg>Improves the assertions in the Character solver test.<commit_after>﻿using NUnit.Framework;
using System.Linq;
using Workbench.Core.Models;
using Workbench.Core.Solver;

namespace Workbench.Core.Tests.Unit
{
    /// <summary>
    /// Placeholder for a well known test that will use the character range successfully.
    /// </summary>
    [TestFixture]
    public class CharacterSolverShould
    {
        [Test]
        public void SolveWithCharacterModelReturnsStatusSuccess()
        {
            var sut = CreateWorkspace();
            var actualResult = sut.Solve();
            Assert.That(actualResult.Status, Is.EqualTo(SolveStatus.Success));
        }

        [Test]
        public void SolveWithCharacterModelReturnsValidSnapshot()
        {
            var sut = CreateWorkspace();
            var actualResult = sut.Solve();
            var aValue = actualResult.Snapshot.GetAggregateVariableValueByName("a");
            var actualSolverValues = aValue.Bindings.Select(_ => _.Solver)
													.ToList();
            var actualModelValues = aValue.Bindings.Select(_ => _.Model)
												   .ToList();
            Assert.That(aValue.Values, Is.Unique);
            Assert.That(aValue.Values, Is.All.TypeOf<char>());
            Assert.That(actualSolverValues, Is.All.InRange(1, 26));
            Assert.That(actualModelValues, Is.All.InRange('a', 'z')
                                                 .Using(new CharacterRangeComparer()));
        }

        [Test]
        public void SolveWithCharacterModelReturnsValidCharacterModelBinding()
        {
            var sut = CreateWorkspace();
            var actualResult = sut.Solve();
            var bValue = actualResult.Snapshot.GetSingletonVariableValueByName("b");
            var bValueBinding = bValue.GetBindingAt(0);
            Assert.That(bValueBinding.Solver, Is.InRange(1, 26));
            Assert.That(bValueBinding.Model, Is.InRange('a', 'z')
                                               .Using(new CharacterRangeComparer()));
        }

        /// <summary>
        /// For a value binding for a number range, the model and solver values 
        /// should be the same.
        /// </summary>
        [Test]
        public void SolveWitCharacterModelReturnsValidNumberModelBinding()
        {
            var sut = CreateWorkspace();
            var actualResult = sut.Solve();
            var cValue = actualResult.Snapshot.GetSingletonVariableValueByName("c");
            var cValueBinding = cValue.GetBindingAt(0);
            Assert.That(cValueBinding.Solver, Is.InRange(1, 26));
            Assert.That(cValueBinding.Model, Is.InRange(1, 26));
            Assert.That(cValueBinding.Solver, Is.EqualTo(cValueBinding.Model));
        }

        private static WorkspaceModel CreateWorkspace()
        {
            var workspace = WorkspaceModel.Create("A made up test")
                                          .AddAggregate("a", 26, "'a'..'z'")
{'fraction_non_alphanumeric': 0.1082660250902217, 'fraction_numerical': 0.005155525004296271, 'mean_word_length': 2.037578288100209, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3398919', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1483, 'n_words': 316}