<commit_before>﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Signum.Utilities;
using System.Diagnostics;
using System.Threading;

namespace Signum.Test
{
    [TestClass]
    public class StringDistanceTest
    {
        StringDistance d = new StringDistance();

        [TestMethod]
        public void ResetLazy()
        {
            int i = 0;
            ResetLazy<string> val = new ResetLazy<string>(() => "hola" + i++);

            val.Reset(); //reset before initialized
            var str1 = val.Value;
            val.Reset(); //reset after initialized

            var str2 = val.Value;

            Assert.AreNotEqual(str1, str2); 
        }

        [TestMethod]
        public void LevenshteinDistance()
        {
            Assert.AreEqual(1, d.LevenshteinDistance("hi", "ho"));
            Assert.AreEqual(1, d.LevenshteinDistance("hi", "hil"));
            Assert.AreEqual(1, d.LevenshteinDistance("hi", "h"));
        }

        [TestMethod]
        public void LevenshteinDistanceWeight()
        {
            Func<StringDistance.Choice<char>, int> w = c => c.HasAdded && char.IsNumber(c.Added) || c.HasRemoved && char.IsNumber(c.Removed) ? 10 : 1;

            Assert.AreEqual(10, d.LevenshteinDistance("hola", "ho5la", weight: w));
            Assert.AreEqual(10, d.LevenshteinDistance("ho5la", "hola", weight: w));
            Assert.AreEqual(10, d.LevenshteinDistance("ho5la", "hojla", weight: w));
            Assert.AreEqual(10, d.LevenshteinDistance("hojla", "ho5la", weight: w));
            Assert.AreEqual(10, d.LevenshteinDistance("ho5la", "ho6la", weight: w));
        }


        [TestMethod]
        public void LongestCommonSubsequence()
        {
            Assert.AreEqual(4, d.LongestCommonSubsequence("hallo", "halo"));
            Assert.AreEqual(7, d.LongestCommonSubsequence("SupeMan", "SuperMan"));
            Assert.AreEqual(0, d.LongestCommonSubsequence("aoa", ""));
        }

        [TestMethod]
        public void LongestCommonSubstring()
        {
            Assert.AreEqual(3, d.LongestCommonSubstring("hallo", "halo"));
            Assert.AreEqual(4, d.LongestCommonSubstring("SupeMan", "SuperMan"));
            Assert.AreEqual(0, d.LongestCommonSubstring("aoa", ""));
        }

        [TestMethod]
        public void Diff()
        {
            var result = d.Diff("en un lugar de la mancha".ToCharArray(), "in un place de la mincha".ToCharArray());

            var str = result.ToString("");

            Assert.AreEqual("-e+in un +pl-u-ga-r+c+e de la m-a+incha", str); 
        }

        [TestMethod]
        public void DiffWords()
        {
            var result = d.DiffWords(
                "Soft drinks, coffees, teas, beers, and ginger ales", 
                "Soft drinks, coffees, teas and beers");

            var str = result.ToString("");

            Assert.AreEqual("Soft drinks, coffees, teas-,- -beers-, and -ginger- -ales+beers", str);

        }

        [TestMethod]
        public void Choices()
        {
            var result = d.LevenshteinChoices("en un lugar de la mancha".ToCharArray(), "in un legarito de la mincha".ToCharArray());

            var str = result.ToString("");

            Assert.AreEqual("[-e+i]n un l[-u+e]gar+i+t+o de la m[-a+i]ncha", str);
        }

        [TestMethod]
        public void DiffText()
        {
            var text1 = 
@"  <NAME>
Que tal
Bien

<NAME>";

            var text2 =
@"  <NAME>

Que til
<NAME>";

            var result = d.DiffText(text1, text2);

            var str = result.ToString(l => (l.Action == StringDistance.DiffAction.Added ? "[+]" :
                l.Action == StringDistance.DiffAction.Removed ? "[-]" : "[=]") + l.Value.ToString(""), "\r\n");

            Assert.AreEqual(
@"[=]  Hola -Pedro+Pedri
[-]-Que tal
[-]-Bien
[=]
[+]+Que til
[=]Adios -Juan+Juani", str);

        }
    }
}<commit_msg>fix StringDistanceTest<commit_after>﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Signum.Utilities;
using System.Diagnostics;
using System.Threading;

namespace Signum.Test
{
    [TestClass]
    public class StringDistanceTest
    {
        StringDistance d = new StringDistance();

        [TestMethod]
        public void ResetLazy()
        {
            int i = 0;
            ResetLazy<string> val = new ResetLazy<string>(() => "hola" + i++);

            val.Reset(); //reset before initialized
            var str1 = val.Value;
            val.Reset(); //reset after initialized

            var str2 = val.Value;

            Assert.AreNotEqual(str1, str2); 
        }

        [TestMethod]
        public void LevenshteinDistance()
        {
            Assert.AreEqual(1, d.LevenshteinDistance("hi", "ho"));
            Assert.AreEqual(1, d.LevenshteinDistance("hi", "hil"));
            Assert.AreEqual(1, d.LevenshteinDistance("hi", "h"));
        }

        [TestMethod]
        public void LevenshteinDistanceWeight()
        {
            Func<StringDistance.Choice<char>, int> w = c => c.HasAdded && char.IsNumber(c.Added) || c.HasRemoved && char.IsNumber(c.Removed) ? 10 : 1;

            Assert.AreEqual(10, d.LevenshteinDistance("hola", "ho5la", weight: w));
            Assert.AreEqual(10, d.LevenshteinDistance("ho5la", "hola", weight: w));
            Assert.AreEqual(10, d.LevenshteinDistance("ho5la", "hojla", weight: w));
            Assert.AreEqual(10, d.LevenshteinDistance("hojla", "ho5la", weight: w));
            Assert.AreEqual(10, d.LevenshteinDistance("ho5la", "ho6la", weight: w));
        }


        [TestMethod]
        public void LongestCommonSubsequence()
        {
            Assert.AreEqual(4, d.LongestCommonSubsequence("hallo", "halo"));
            Assert.AreEqual(7, d.LongestCommonSubsequence("SupeMan", "SuperMan"));
            Assert.AreEqual(0, d.LongestCommonSubsequence("aoa", ""));
        }

        [TestMethod]
        public void LongestCommonSubstring()
        {
            Assert.AreEqual(3, d.LongestCommonSubstring("hallo", "halo"));
            Assert.AreEqual(4, d.LongestCommonSubstring("SupeMan", "SuperMan"));
            Assert.AreEqual(0, d.LongestCommonSubstring("aoa", ""));
        }

        [TestMethod]
        public void Diff()
        {
            var result = d.Diff("en un lugar de la mancha".ToCharArray(), "in un place de la mincha".ToCharArray());

            var str = result.ToString("");

            Assert.AreEqual("-e+in un +pl-u-ga-r+c+e de la m-a+incha", str); 
        }

        [TestMethod]
        public void DiffWords()
        {
            var result = d.DiffWords(
                "Soft drinks, coffees, teas, beers, and ginger ales", 
                "Soft drinks, coffees, teas and beers");

            var str = result.ToString("");

            Assert.AreEqual("Soft drinks, coffees, teas-,- -beers-, and -ginger- -ales+beers", str);

        }

        [TestMethod]
        public void Choices()
        {
            var result = d.LevenshteinChoices("en un lugar de la mancha".ToCharArray(), "in un legarito de la mincha".ToCharArray());

            var str = result.ToString("");

            Assert.AreEqual("[-e+i]n un l[-u+e]gar+i+t+o de la m[-a+i]ncha", str);
        }

        [TestMethod]
        public void DiffText()
        {
            var text1 = 
@"  Hola Pedro
Que tal
Bien

<NAME>";

            var text2 =
@"  Hola Pedri

Que til
Adios Juani";

            var result = d.DiffText(text1, text2);

            var str = result.ToString(l => (l.Action == StringDistance.DiffAction.Added ? "[+]" :
                l.Action == StringDistance.DiffAction.Removed ? "[-]" : "[=]") + l.Value.ToString(""), "\n");

            Assert.AreEqual(
@"[=]  Hola -Pedro+Pedri
[-]-Que tal
[-]-Bien
[=]
[+]+Que til
[=]Adios -Juan+Juani", str);

        }
    }
}
{'fraction_non_alphanumeric': 0.14604334677419356, 'fraction_numerical': 0.009324596774193549, 'mean_word_length': 2.1596337579617835, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6938670', 'n_tokens_mistral': 2595, 'n_tokens_neox': 2463, 'n_words': 526}