Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  keyorder.any.js

  Sprache: JAVA
 

// META: global=window,worker
// META: title=Key sort order
// META: script=resources/support.js

// Spec: https://w3c.github.io/IndexedDB/#key-construct

'use strict';

const global_db = createdb_for_multiple_tests();

const keysort = (desc, unsorted, expected) => {
  async_test(t => {
    const store_name = 'store-' + Date.now() + Math.random();

    // The database test
    const open_rq = global_db.setTest(t);
    open_rq.onupgradeneeded = t.step_func(e => {
      const db = e.target.result;
      const objStore = db.createObjectStore(store_name);

      for (let i = 0; i < unsorted.length; i++)
        objStore.add('value', unsorted[i]);
    });

    open_rq.onsuccess = t.step_func(e => {
      const db = e.target.result;
      const actual_keys = [];
      const rq =
          db.transaction(store_name).objectStore(store_name).openCursor();

      rq.onsuccess = t.step_func(e => {
        const cursor = e.target.result;

        if (cursor) {
          actual_keys.push(cursor.key);
          cursor.continue();
        } else {
          assert_key_equals(actual_keys, expected, 'keyorder array');
          assert_equals(actual_keys.length, expected.length, 'array length');

          t.done();
        }
      });
    });
  }, `Database readback sort - ${desc}`);

  // The IDBKey.cmp test
  test(() => {
    const sorted = unsorted.slice(0).sort((a, b) => indexedDB.cmp(a, b));
    assert_key_equals(sorted, expected, 'sorted array');
  }, `IDBKey.cmp sort - ${desc}`);
};

const now = new Date();
const one_sec_ago = new Date(now - 1000);
const one_min_future = new Date(now.getTime() + 1000 * 60);

keysort('String < Array', [[0], 'yo''', []], ['''yo', [], [0]]);

keysort(
    'float < String', [Infinity, 'yo'0''100],
    [0100, Infinity, '''yo']);

keysort(
    'float < Date', [now, 09999999999999, -0.22],
    [-0.2209999999999999, now]);

keysort(
    'float < Date < String < Array', [[], '', now, [0], '-1'09999999999999],
    [09999999999999, now, '''-1', [], [0]]);

keysort(
    'Date(1 sec ago) < Date(now) < Date(1 minute in future)',
    [now, one_sec_ago, one_min_future], [one_sec_ago, now, one_min_future]);

keysort(
    '-1.1 < 1 < 1.01337 < 1.013373 < 2', [1.01337321.01337, -1.11],
    [-1.111.013371.0133732]);

keysort(
    '-Infinity < -0.01 < 0 < Infinity', [0, -0.01, -Infinity, Infinity],
    [-Infinity, -0.010, Infinity]);

keysort(
    '"" < "a" < "ab" < "b" < "ba"', ['a''ba''''b''ab'],
    ['''a''ab''b''ba']);

keysort(
    'Arrays', [[[0]], [0], [], [00], [0, [0]]],
    [[], [0], [00], [0, [0]], [[0]]]);

const big_array = [];
const bigger_array = [];
for (let i = 0; i < 10000; i++) {
  big_array.push(i);
  bigger_array.push(i);
}
bigger_array.push(0);

keysort(
    'Array.length: 10,000 < Array.length: 10,001',
    [bigger_array, [023], [0], [9], big_array],
    [[0], big_array, bigger_array, [023], [9]]);

keysort(
    'Infinity inside arrays',
    [
      [Infinity, 1],
      [Infinity, Infinity],
      [11],
      [1, Infinity],
      [1, -Infinity],
      [-Infinity, Infinity],
    ],
    [
      [-Infinity, Infinity],
      [1, -Infinity],
      [11],
      [1, Infinity],
      [Infinity, 1],
      [Infinity, Infinity],
    ]);

keysort(
    'Test different stuff at once',
    [
      now,
      [0, []],
      'test',
      1,
      ['a', [1, [-1]]],
      ['b''a'],
      [02'c'],
      ['a', [12]],
      [],
      [0, [], 3],
      ['a''b'],
      [12],
      ['a''b''c'],
      one_sec_ago,
      [0'b''c'],
      Infinity,
      -Infinity,
      2.55,
      [0, now],
      [1],
    ],
    [
      -Infinity,
      1,
      2.55,
      Infinity,
      one_sec_ago,
      now,
      'test',
      [],
      [02'c'],
      [0, now],
      [0'b''c'],
      [0, []],
      [0, [], 3],
      [1],
      [12],
      ['a''b'],
      ['a''b''c'],
      ['a', [12]],
      ['a', [1, [-1]]],
      ['b''a'],
    ]);

Messung V0.5 in Prozent
C=100 H=99 G=99

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002