Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/storage/test/unit/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 2 kB image not shown  

Quelle  test_storage_ext_percentile.js

  Sprache: JAVA
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


// This file tests support for the percentile extension.

// Some example statements in this test are taken from the SQLite percentile
// documentation page: https://sqlite.org/percentile.html

function run_test() {
  let db = Services.storage.openSpecialDatabase("memory");

  db.executeSimpleSQL("CREATE TABLE t1(x REAL)");
  db.executeSimpleSQL(
    "INSERT INTO t1(x) VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10)"
  );

  let stmt = db.createStatement("SELECT percentile(x, 50) FROM t1");
  Assert.ok(stmt.executeStep());
  Assert.equal(stmt.getDouble(0), 5.5);
  stmt.reset();
  stmt.finalize();

  // median(x) is equivalent to percentile(x, 50).
  stmt = db.createStatement("SELECT median(x) FROM t1");
  Assert.ok(stmt.executeStep());
  Assert.equal(stmt.getDouble(0), 5.5);
  stmt.reset();
  stmt.finalize();

  // percentile(x, 0) returns the minimum value.
  stmt = db.createStatement("SELECT percentile(x, 0) FROM t1");
  Assert.ok(stmt.executeStep());
  Assert.equal(stmt.getDouble(0), 1.0);
  stmt.reset();
  stmt.finalize();

  // percentile(x, 100) returns the maximum value.
  stmt = db.createStatement("SELECT percentile(x, 100) FROM t1");
  Assert.ok(stmt.executeStep());
  Assert.equal(stmt.getDouble(0), 10.0);
  stmt.reset();
  stmt.finalize();

  // percentile(x, 25) exercises the linear interpolation path.
  // ix = 0.25 * 9 = 2.25; v1 = a[2] = 3.0, v2 = a[3] = 4.0 => 3.25
  stmt = db.createStatement("SELECT percentile(x, 25) FROM t1");
  Assert.ok(stmt.executeStep());
  Assert.equal(stmt.getDouble(0), 3.25);
  stmt.reset();
  stmt.finalize();

  // percentile_cont(x, P) takes P in the range 0.0-1.0.
  stmt = db.createStatement("SELECT percentile_cont(x, 0.25) FROM t1");
  Assert.ok(stmt.executeStep());
  Assert.equal(stmt.getDouble(0), 3.25);
  stmt.reset();
  stmt.finalize();

  // percentile_disc(x, P) returns the nearest stored value rather than
  // interpolating.
  stmt = db.createStatement("SELECT percentile_disc(x, 0.25) FROM t1");
  Assert.ok(stmt.executeStep());
  Assert.equal(stmt.getDouble(0), 3.0);
  stmt.reset();
  stmt.finalize();

  // All-NULL input must return NULL per spec rule (8).
  stmt = db.createStatement(
    "SELECT percentile(x, 50) FROM (SELECT NULL AS x UNION ALL SELECT NULL AS x)"
  );
  Assert.ok(stmt.executeStep());
  Assert.ok(stmt.getIsNull(0));
  stmt.reset();
  stmt.finalize();

  db.close();
}

Messung V0.5 in Prozent
C=84 H=100 G=92

¤ Dauer der Verarbeitung: 0.5 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.