<commit_before><!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>simple table sort - a jQuery plugin — Test</title>

  <link href="resources/qunit-1.10.0.css" rel="stylesheet">

  <script src="resources/qunit-1.10.0.js"></script>
  <script src="../lib/jquery.js"></script>
  <script src="../jquery.simpleTableSort.js"></script>
  <script src="resources/prerequisites.js"></script>

  <script>
  $(function() {
    var table, i;

    var testColumns = {
      alphabetical: 'Name',
      numeric: 'Age',
      float: 'Height (in m)',
      date: 'Reg. date'
    };

    var testRows = [
      ['Felix', '37', '1.68', 'Jan 28, 2006'],
      ['Anton', '77', '1.86', 'Dec 30, 2011'],
      ['Laith', '79', '1.74', 'Jul 17, 2008'],
      ['Zaphod', '39', '1.59', 'Jun 23, 2008'],
      ['Dorian', '28', '2.12', 'Oct 6, 2012']
    ];

    module('Built-in sort methods', {
      setup: function() {
        table = createTestTable(testColumns, testRows).simpleTableSort({ order: 'asc' });
      },
      teardown: function() {
        table.remove();
      }
    });

    // pre-sorted values
    var expectedData = {
      alphabetical: ['Anton', 'Dorian', 'Felix', 'Laith', 'Zaphod'],
      numeric: ['28', '37', '39', '77', '79'],
      float: ['1.59', '1.68', '1.74', '1.86', '2.12'],
      date: ['Jan 28, 2006', 'Jun 23, 2008', 'Jul 17, 2008', 'Dec 30, 2011', 'Oct 6, 2012']
    };

    // check ascending
    function testAscending(sortMethod, expected, index) {
      test('sort ascending: '+sortMethod, function() {
        table.clickHeadCol(index);
        var actual = table.collectActualData(index);

        deepEqual(actual, expected, 'Correct sorting order');
      });
    }
    // end check ascending

    // check descending
    function testDescending(sortMethod, expected, index) {
      test('sort descending: '+sortMethod, function() {
        table.clickHeadCol(index, 2);
        var actual = table.collectActualData(index);

        // slice() clones the array, we don't want referential reversing. the test data would be destroyed.
        var expectedReverse = expected.slice().reverse();

        deepEqual(actual, expectedReverse, 'Correct sorting order');
      });
    }
    // end check descending

    i = 0;
    $.each(expectedData, function(sortMethod, expected) {
      testAscending(sortMethod, expected, i++);
    });

    i = 0;
    $.each(expectedData, function(sortMethod, expected) {
      testDescending(sortMethod, expected, i++);
    });

    module('Options');

    test('Set css class prefix', function() {
      var before, after;
      table = createTestTable(testColumns, testRows, 'sortable').simpleTableSort({ prefix: 'sortable' });

      before = table.find('tbody td').eq(0).text();
      table.clickHeadCol(0);
      after = table.find('tbody td').eq(0).text();

      notEqual(after, before, 'Sort order was changed');

      var classList = table.find('th').eq(0).prop('class').split(' ');
      var result = true;
      $.each(classList, function(i, className) {
        if (!/sortable-/.test(className)) {
          result = false;
          return false;
        }
      });

      ok(result, 'Class prefix has been changed');

      table.remove();
    });

    test('Set auto order on table creation', function() {
      table = createTestTable(testColumns, testRows).simpleTableSort({ autoSort: 0 });

      var actual = table.collectActualData(0);

      deepEqual(actual, expectedData.alphabetical, 'Table was sorted automatically at creation');

      table.remove();
    });

    test('Set initial sort order to descending', function() {
      table = createTestTable(testColumns, testRows).simpleTableSort({ order: 'desc' });
      table.clickHeadCol(0);
<commit_msg>extended tests<commit_after><!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>simple table sort - a jQuery plugin — Test</title>

  <link href="resources/qunit-1.10.0.css" rel="stylesheet">

  <script src="resources/qunit-1.10.0.js"></script>
  <script src="../lib/jquery.js"></script>
  <script src="../jquery.simpleTableSort.js"></script>
  <script src="resources/prerequisites.js"></script>

  <script>
  $(function() {
    var table, i;

    var testColumns = {
      alphabetical: 'Name',
      numeric: 'Age',
      float: 'Height (in m)',
      date: 'Reg. date'
    };

    var testRows = [
      ['Felix', '37', '1.68', 'Jan 28, 2006'],
      ['Anton', '77', '1.86', 'Dec 30, 2011'],
      ['Laith', '79', '1.74', 'Jul 17, 2008'],
      ['Zaphod', '39', '1.59', 'Jun 23, 2008'],
      ['Dorian', '28', '2.12', 'Oct 6, 2012']
    ];

    module('Built-in sort methods', {
      setup: function() {
        table = createTestTable(testColumns, testRows).simpleTableSort({ order: 'asc' });
      },
      teardown: function() {
        table.remove();
      }
    });

    // pre-sorted values
    var expectedData = {
      alphabetical: ['Anton', 'Dorian', 'Felix', 'Laith', 'Zaphod'],
      numeric: ['28', '37', '39', '77', '79'],
      float: ['1.59', '1.68', '1.74', '1.86', '2.12'],
      date: ['Jan 28, 2006', 'Jun 23, 2008', 'Jul 17, 2008', 'Dec 30, 2011', 'Oct 6, 2012']
    };

    // check ascending
    function testAscending(sortMethod, expected, index) {
      test('sort ascending: '+sortMethod, function() {
        table.clickHeadCol(index);
        var actual = table.collectActualData(index);

        deepEqual(actual, expected, 'Correct sorting order');
      });
    }
    // end check ascending

    // check descending
    function testDescending(sortMethod, expected, index) {
      test('sort descending: '+sortMethod, function() {
        table.clickHeadCol(index, 2);
        var actual = table.collectActualData(index);

        // slice() clones the array, we don't want referential reversing. the test data would be destroyed.
        var expectedReverse = expected.slice().reverse();

        deepEqual(actual, expectedReverse, 'Correct sorting order');
      });
    }
    // end check descending

    i = 0;
    $.each(expectedData, function(sortMethod, expected) {
      testAscending(sortMethod, expected, i++);
    });

    i = 0;
    $.each(expectedData, function(sortMethod, expected) {
      testDescending(sortMethod, expected, i++);
    });

    module('Options');

    test('Set css class prefix', function() {
      var before, after;
      table = createTestTable(testColumns, testRows, 'sortable').simpleTableSort({ prefix: 'sortable' });

      before = table.find('tbody td').eq(0).text();
      table.clickHeadCol(0);
      after = table.find('tbody td').eq(0).text();

      notEqual(after, before, 'Sort order was changed');

      var classList = table.find('th').eq(0).prop('class').split(' ');
      var result = true;
      $.each(classList, function(i, className) {
        if (!/sortable-/.test(className)) {
          result = false;
          return false;
        }
      });

      ok(result, 'Class prefix has been changed');

      table.remove();
    });

    test('Set dynamic table', function() {
      table = createTestTable(testColumns, testRows).simpleTableSort({ dynamic: true });

      table.find('tbody tr:lt(2)').remove();

      var expected = ['Dorian', 'Laith', 'Zaphod'];
      table.clickHeadCol(0);

      var actual = table.collectActualData(0);

      deepEqual(actual, expected, 'Table rows were updated dynamically');

      table.remove();
    });

    test('Set multi stort state', function() {
      table = createTestTable(testColumns, testRows).simpleTableSort({ multiSortStates: true });

      table.clickHeadCol(0);
      table.clickHeadCol(1);

      var passed = true;

      table.find('tbody th:lt(2)').each(function() {
        passed = $(this).hasClass('sort-asc');
      });

      table.find('tbody th:gt(1)').each(function() {
        passed = !$(this).hasClass('sort-asc');
      });

      ok(passed, 'Head columns keep the state of current order');

      table.remove();
    });

    test('Set auto order on table creation', function() {
      table = createTestTable(testColumns, testRows).simpleTableSort({ autoSort: 0 });

      var actual = table.collectActualData(0);

      deepEqual(actual, expectedData.alphabetical, 'Table was sorted automatically at creation');

      table.remove();
    });

    test('Set initial sort order to descending', function() {
      table = createTestTable(testColumns, testRows).simpleTableSort({ order: 'desc' });
      table.clickHeadCol(0);

{'fraction_non_alphanumeric': 0.17181033463403098, 'fraction_numerical': 0.03086200780418588, 'mean_word_length': 2.8638647784376428, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '4689247', 'n_tokens_mistral': 2853, 'n_tokens_neox': 2545, 'n_words': 646}