<commit_before>﻿// Spines.Mahjong.Analysis.InternalTests.ShantenCalculatorTests.cs
// 
// Copyright (C) 2017  <NAME>
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
using Spines.Mahjong.Analysis.Classification;

namespace Spines.Mahjong.Analysis.InternalTests
{
  [TestFixture]
  public class ShantenCalculatorTests
  {
    [TestCase("123456789m12344p", -1)]
    [TestCase("123456789m1234p", 0)]
    [TestCase("123456789m1245p", 1)]
    [TestCase("123456789m147p1s", 2)]
    [TestCase("12345679m147p14s", 3)]
    [TestCase("1345679m147p147s", 4)]
    [TestCase("145679m147p147s1z", 5)]
    [TestCase("14679m147p147s12z", 6)]
    [TestCase("1479m147p147s123z", 7)]
    [TestCase("147m147p147s1234z", 8)]
    [TestCase("123456789m44p123S", -1)]
    [TestCase("1245p112z333P6666P", 2)]
    [TestCase("123456789m44p111Z", -1)]
    [TestCase("1245p112z444Z3333Z", 1)]
    public void ShantenShouldBeCorrect(string hand, int expected)
    {
      var c = new Hand(hand);

      var actual = c.Shanten;

      Assert.That(actual, Is.EqualTo(expected));
    }

    [Test]
    public void HandShouldWork()
    {
      Console.WriteLine(new Hand("123456789m12344p").Shanten);

      for(var f = 0; f < 5; ++f)
      {
        var rand = new Random(5);

        var sw = new Stopwatch();
        sw.Start();

        for (var iterations = 0; iterations < 40000; iterations++)
        {
          var drawn = new bool[136];

          var hand = new Hand();<commit_msg>Improved performence measurement<commit_after>﻿// Spines.Mahjong.Analysis.InternalTests.ShantenCalculatorTests.cs
// 
// Copyright (C) 2017  <NAME>
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using NUnit.Framework;
using Spines.Mahjong.Analysis.Classification;

namespace Spines.Mahjong.Analysis.InternalTests
{
  [TestFixture]
  public class ShantenCalculatorTests
  {
    [TestCase("123456789m12344p", -1)]
    [TestCase("123456789m1234p", 0)]
    [TestCase("123456789m1245p", 1)]
    [TestCase("123456789m147p1s", 2)]
    [TestCase("12345679m147p14s", 3)]
    [TestCase("1345679m147p147s", 4)]
    [TestCase("145679m147p147s1z", 5)]
    [TestCase("14679m147p147s12z", 6)]
    [TestCase("1479m147p147s123z", 7)]
    [TestCase("147m147p147s1234z", 8)]
    [TestCase("123456789m44p123S", -1)]
    [TestCase("1245p112z333P6666P", 2)]
    [TestCase("123456789m44p111Z", -1)]
    [TestCase("1245p112z444Z3333Z", 1)]
    public void ShantenShouldBeCorrect(string hand, int expected)
    {
      var c = new Hand(hand);

      var actual = c.Shanten;

      Assert.That(actual, Is.EqualTo(expected));
    }

    [Test]
    public void HandShouldWork()
    {
      Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(2);
      Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
      Thread.CurrentThread.Priority = ThreadPriority.Highest;

      Console.WriteLine(new Hand("123456789m12344p").Shanten);

      for(var f = 0; f < 5; ++f)
      {
        var rand = new Random(5);

        var sw = new Stopwatch();

        GC.Collect();
        GC.WaitForPendingFinalizers();
        GC.Collect();

        sw.Restart();

        for (var iterations = 0; iterations < 40000; iterations++)
        {
          var drawn = new bool[136];

          var hand = new Hand();
{'fraction_non_alphanumeric': 0.11884984025559106, 'fraction_numerical': 0.09904153354632587, 'mean_word_length': 3.3683720930232557, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1466738', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1443, 'n_words': 417}