Eine aufbereitete Darstellung der Quelle

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

einige Melodien

Quelle  Main.java   Sprache: JAVA

 

/*
 * Copyright x+=[java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
 *
 * Licensed under the Apache License, java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 26
 *    (6  )
 * You may obtain a copy of the License at
 49 a )
 *      http    28 a d)
 *
 * Unless required by applicable28threeArrays(a, c,d);
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIESjava.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 54
 *,altLoopLogic( )java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
 * limitations under the License.
 */


/**
 * Tests on bounds expectEquals30,(a );
 *
 */

public.(");

  /// CHECK-START: int Main.oneArray(int[]) BCE (before)
  /// CHECK-DAG: BoundsCheck loop:<<Loop:B\d+>> outer_loop:none   ( expected result java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
  //
  /// CHECK-START: int Main.oneArray(int[]) BCE (after)
  /// CHECK-NOT: BoundsCheck
  /// CHECK-NOT: Deoptimize
  static int oneArray(int[] a)     
    int x = 0;
    for (int i = 0; i < a.length; i++) {
      x += a[i];
    }
    return x;
  }

  /// CHECK-START: int Main.oneArrayAbs(int[], int[]) BCE (before)
  /// CHECK-DAG: BoundsCheck loop:<<Loop:B\d+>> outer_loop:none
  //
  /// CHECK-START: int Main.oneArrayAbs(int[], int[]) BCE (after)
  /// CHECK-NOT: BoundsCheck
  /// CHECK-NOT: Deoptimize
  static int oneArrayAbs(int[] a, int[] b) {
    int x = 0;
    for (int i = Math.abs(b.length); i < a.length; i++) {
      x += a[i];
    }
    return x;
  }


  /// CHECK-START: int Main.twoArrays(int[], int[]) BCE (before)
  /// CHECK-DAG: BoundsCheck loop:<<Loop:B\d+>> outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop>>      outer_loop:none
  //
  /// CHECK-START: int Main.twoArrays(int[], int[]) BCE (after)
  /// CHECK-NOT: BoundsCheck
  /// CHECK-NOT: Deoptimize
  static int twoArrays(int[] a, int[] b) {
    int x = 0;
    for (int i = 0; i < Math.min(a.length, b.length); i++) {
      x += a[i] + b[i];
    }
    return x;
  }

  /// CHECK-START: int Main.threeArrays(int[], int[], int[]) BCE (before)
  /// CHECK-DAG: BoundsCheck loop:<<Loop:B\d+>> outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop>>      outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop>>      outer_loop:none
  //
  /// CHECK-START: int Main.threeArrays(int[], int[], int[]) BCE (after)
  /// CHECK-NOT: BoundsCheck
  /// CHECK-NOT: Deoptimize
  static int threeArrays(int[] a, int[] b, int[] c) {
    int x = 0;
    for (int i = 0; i < Math.min(Math.min(a.length, b.length), c.length); i++) {
      x += a[i] + b[i] + c[i];
    }
    return x;
  }

  /// CHECK-START: int Main.fourArrays(int[], int[], int[], int[]) BCE (before)
  /// CHECK-DAG: BoundsCheck loop:<<Loop:B\d+>> outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop>>      outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop>>      outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop>>      outer_loop:none
  //
  /// CHECK-START: int Main.fourArrays(int[], int[], int[], int[]) BCE (after)
  /// CHECK-NOT: BoundsCheck
  /// CHECK-NOT: Deoptimize
  static int fourArrays(int[] a, int[] b, int[] c, int[] d) {
    int x = 0;
    for (int i = 0; i < Math.min(Math.min(a.length, b.length), Math.min(c.length, d.length)); i++) {
      x += a[i] + b[i] + c[i] + d[i];
    }
    return x;
  }

  /// CHECK-START: int Main.oneArrayWithCleanup(int[]) BCE (before)
  /// CHECK-DAG: BoundsCheck loop:<<Loop1:B\d+>> outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop2:B\d+>> outer_loop:none
  //
  /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>"
  //
  /// CHECK-START: int Main.oneArrayWithCleanup(int[]) BCE (after)
  /// CHECK-NOT: BoundsCheck
  /// CHECK-NOT: Deoptimize
  static int oneArrayWithCleanup(int[] a) {
    int x = 0;
    int n = Math.min(4, a.length);
    for (int i = 0; i < n; i++) {
      x += a[i];
    }
    for (int i = n; i < a.length; i++) {
      x += a[i] * 10;
    }
    return x;
  }

  /// CHECK-START: int Main.twoArraysWithCleanup(int[], int[]) BCE (before)
  /// CHECK-DAG: BoundsCheck loop:<<Loop1:B\d+>> outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop1>>      outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop2:B\d+>> outer_loop:none
  //
  /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>"
  //
  /// CHECK-START: int Main.twoArraysWithCleanup(int[], int[]) BCE (after)
  /// CHECK-NOT: BoundsCheck
  /// CHECK-NOT: Deoptimize
  static int twoArraysWithCleanup(int[] a, int[] b) {
    int x = 0;
    int n = Math.min(a.length, b.length);
    for (int i = n - 1; i >= 0; i--) {
      x += a[i] + b[i];
    }
    for (int i = n; i < a.length; i++) {
      x += a[i];
    }
    return x;
  }

  /// CHECK-START: int Main.threeArraysWithCleanup(int[], int[], int[]) BCE (before)
  /// CHECK-DAG: BoundsCheck loop:<<Loop1:B\d+>> outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop1>>      outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop1>>      outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop2:B\d+>> outer_loop:none
  //
  /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>"
  //
  /// CHECK-START: int Main.threeArraysWithCleanup(int[], int[], int[]) BCE (after)
  /// CHECK-NOT: BoundsCheck
  /// CHECK-NOT: Deoptimize
  static int threeArraysWithCleanup(int[] a, int[] b, int[] c) {
    int x = 0;
    int n = Math.min(a.length, Math.min(b.length, c.length));
    for (int i = n - 1; i >= 0; i--) {
      x += a[i] + b[i] + c[i];
    }
    for (int i = n; i < a.length; i++) {
      x += a[i];
    }
    return x;
  }

  /// CHECK-START: int Main.altLoopLogic(int[], int[]) BCE (before)
  /// CHECK-DAG: BoundsCheck loop:<<Loop:B\d+>> outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop>>      outer_loop:none
  //
  /// CHECK-START: int Main.altLoopLogic(int[], int[]) BCE (after)
  /// CHECK-NOT: BoundsCheck
  /// CHECK-NOT: Deoptimize
  static int altLoopLogic(int[] a, int[] b) {
    int x = 0;
    int n = Math.min(a.length, b.length);
    for (int i = n; i-- > 0;) {
      x += a[i] + b[i];
    }
    return x;
  }

  /// CHECK-START: int Main.hiddenMin(int[], int[]) BCE (before)
  /// CHECK-DAG: BoundsCheck loop:<<Loop:B\d+>> outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop>>      outer_loop:none
  //
  /// CHECK-START: int Main.hiddenMin(int[], int[]) BCE (after)
  //
  // TODO: make this so
  static int hiddenMin(int[] a, int[] b) {
    int x = 0;
    for (int i = 0; i < a.length && i < b.length; i++) {
      x += a[i] + b[i];
    }
    return x;
  }

  /// CHECK-START: int Main.hiddenMinWithCleanup(int[], int[]) BCE (before)
  /// CHECK-DAG: BoundsCheck loop:<<Loop1:B\d+>> outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop1>>      outer_loop:none
  /// CHECK-DAG: BoundsCheck loop:<<Loop2:B\d+>> outer_loop:none
  //
  /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>"
  //
  /// CHECK-START: int Main.hiddenMinWithCleanup(int[], int[]) BCE (after)
  //
  // TODO: make this so
  static int hiddenMinWithCleanup(int[] a, int[] b) {
    int x = 0;
    int i = 0;
    for (; i < a.length && i < b.length; i++) {
      x += a[i] + b[i];
    }
    for (; i < a.length; i++) {
      x += a[i];
    }
    return x;
  }

  public static void main(String[] args) {
    int[] a = { 1, 2, 3, 4, 5 };
    int[] b = { 6, 7, 8, 9, 4, 2 };
    int[] c = { 1, 2, 3 };
    int[] d = { 8, 5, 3, 2 };
    int[] e = { };

    expectEquals(15, oneArray(a));
    expectEquals(36, oneArray(b));
    expectEquals(6,  oneArray(c));
    expectEquals(18, oneArray(d));

    expectEquals(15, oneArrayAbs(a, e));
    expectEquals(5,  oneArrayAbs(a, d));

    expectEquals(30, twoArrays(a, a));
    expectEquals(49, twoArrays(a, b));
    expectEquals(12, twoArrays(a, c));
    expectEquals(28, twoArrays(a, d));

    expectEquals(45, threeArrays(a, a, a));
    expectEquals(33, threeArrays(a, b, c));
    expectEquals(58, threeArrays(a, b, d));
    expectEquals(28, threeArrays(a, c, d));

    expectEquals(60, fourArrays(a, a, a, a));
    expectEquals(49, fourArrays(a, b, c, d));

    expectEquals(60, oneArrayWithCleanup(a));
    expectEquals(90, oneArrayWithCleanup(b));
    expectEquals(6,  oneArrayWithCleanup(c));
    expectEquals(18, oneArrayWithCleanup(d));

    expectEquals(30, twoArraysWithCleanup(a, a));
    expectEquals(49, twoArraysWithCleanup(a, b));
    expectEquals(21, twoArraysWithCleanup(a, c));
    expectEquals(33, twoArraysWithCleanup(a, d));

    expectEquals(45, threeArraysWithCleanup(a, a, a));
    expectEquals(42, threeArraysWithCleanup(a, b, c));
    expectEquals(63, threeArraysWithCleanup(a, b, d));
    expectEquals(37, threeArraysWithCleanup(a, c, d));

    expectEquals(30, altLoopLogic(a, a));
    expectEquals(49, altLoopLogic(a, b));
    expectEquals(12, altLoopLogic(a, c));
    expectEquals(28, altLoopLogic(a, d));

    expectEquals(30, hiddenMin(a, a));
    expectEquals(49, hiddenMin(a, b));
    expectEquals(12, hiddenMin(a, c));
    expectEquals(28, hiddenMin(a, d));

    expectEquals(30, hiddenMinWithCleanup(a, a));
    expectEquals(49, hiddenMinWithCleanup(a, b));
    expectEquals(21, hiddenMinWithCleanup(a, c));
    expectEquals(33, hiddenMinWithCleanup(a, d));

    System.out.println("passed");
  }

  private static void expectEquals(int expected, int result) {
    if (expected != result) {
      throw new Error("Expected: " + expected + ", found: " + result);
    }
  }
}

Messung V0.5 in Prozent
C=89 H=96 G=92

¤ 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.0.3Bemerkung:  ¤

*© 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

letze Version des Elbe Quellennavigators


Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1127926
#Domains=2039723