Eine aufbereitete Darstellung der Quelle

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

Benutzer

Quelle  bug4409072.java

  Sprache: JAVA
 

/*
 * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code 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
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */


/*
 * @test
 * @bug 4409072
 * @summary tests for set(), add(), and roll() with various week parameters.
 * @library /java/text/testlib
 * @run main bug4409072
 */


import  java.util.*;
import static java.util.Calendar.*;

public class bug4409072 extends IntlTest {

    public static void main(String[] args) throws Exception {
        new bug4409072().run(args);
    }

    /* Confirm some public methods' behavior in Calendar.
     * (e.g. add(), roll(), set())
     */

    public void Test4409072() {
        Locale locale = Locale.getDefault();
        if (!TestUtils.usesGregorianCalendar(locale)) {
            logln("Skipping this test because locale is " + locale);
            return;
        }

        Locale savedLocale = Locale.getDefault();
        TimeZone savedTZ = TimeZone.getDefault();
        try {
            TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
            testSet();
            testAdd();
            testRoll();
        } finally {
            TimeZone.setDefault(savedTZ);
            Locale.setDefault(savedLocale);
        }
    }

    /*
     * Golden data for set() test
     */

    static final int[][][] resultWOMForSetTest = {
        { /* For year1998 */
          /* Min =     1        2        3        4        5        6        7  */
          /* Sun */ {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11,11}, {11,11},
          /* Mon */ {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11,11},
          /* Tue */ {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4},
          /* Wed */ {10,27}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4},
          /* Thu */ {10,27}, {10,27}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4},
          /* Fri */ {10,27}, {10,27}, {10,27}, {11, 4}, {11, 4}, {11, 4}, {11, 4},
          /* Sat */ {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11,11}, {11,11}, {11,11},
        },
        { /* For year1999 */
          /* Min =     1        2        3        4        5        6        7  */
          /* Sun */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11,10}, {11,10}, {11,10},
          /* Mon */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11,10}, {11,10},
          /* Tue */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11,10},
          /* Wed */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3},
          /* Thu */ {10,26}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3},
          /* Fri */ {10,26}, {10,26}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3},
          /* Sat */ {11, 3}, {11, 3}, {11, 3}, {11,10}, {11,10}, {11,10}, {11,10},
        },
        { /* For year2000 */
          /* Min =     1        2        3        4        5        6        7  */
          /* Sun */ {11, 1}, {11, 1}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8},
          /* Mon */ {11, 1}, {11, 1}, {11, 1}, {11, 8}, {11, 8}, {11, 8}, {11, 8},
          /* Tue */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 8}, {11, 8}, {11, 8},
          /* Wed */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 8}, {11, 8},
          /* Thu */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 8},
          /* Fri */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1},
          /* Sat */ {11, 1}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8},
        },
        { /* For year2001 */
          /* Min =     1        2        3        4        5        6        7  */
          /* Sun */ {10,30}, {11, 7}, {11, 7}, {11, 7}, {11, 7}, {11, 7}, {11, 7},
          /* Mon */ {10,30}, {10,30}, {11, 7}, {11, 7}, {11, 7}, {11, 7}, {11, 7},
          /* Tue */ {10,30}, {10,30}, {10,30}, {11, 7}, {11, 7}, {11, 7}, {11, 7},
          /* Wed */ {10,30}, {10,30}, {10,30}, {10,30}, {11, 7}, {11, 7}, {11, 7},
          /* Thu */ {10,30}, {10,30}, {10,30}, {10,30}, {10,30}, {11, 7}, {11, 7},
          /* Fri */ {10,30}, {10,30}, {10,30}, {10,30}, {10,30}, {10,30}, {11, 7},
          /* Sat */ {11, 7}, {11, 7}, {11, 7}, {11, 7}, {11, 7}, {11, 7}, {11, 7},
        },
        { /* For year2002 */
          /* Min =     1        2        3        4        5        6        7  */
          /* Sun */ {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6},
          /* Mon */ {10,29}, {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6},
          /* Tue */ {10,29}, {10,29}, {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6},
          /* Wed */ {10,29}, {10,29}, {10,29}, {11, 6}, {11, 6}, {11, 6}, {11, 6},
          /* Thu */ {10,29}, {10,29}, {10,29}, {10,29}, {11, 6}, {11, 6}, {11, 6},
          /* Fri */ {10,29}, {10,29}, {10,29}, {10,29}, {10,29}, {11, 6}, {11, 6},
          /* Sat */ {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11, 6}, {11,13},
        },
        { /* For year2003 */
          /* Min =     1        2        3        4        5        6        7  */
          /* Sun */ {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11,12},
          /* Mon */ {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5},
          /* Tue */ {10,28}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5},
          /* Wed */ {10,28}, {10,28}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5},
          /* Thu */ {10,28}, {10,28}, {10,28}, {11, 5}, {11, 5}, {11, 5}, {11, 5},
          /* Fri */ {10,28}, {10,28}, {10,28}, {10,28}, {11, 5}, {11, 5}, {11, 5},
          /* Sat */ {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11, 5}, {11,12}, {11,12},
        },
        { /* For year2004 */
          /* Min =     1        2        3        4        5        6        7  */
          /* Sun */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11,10}, {11,10}, {11,10},
          /* Mon */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11,10}, {11,10},
          /* Tue */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11,10},
          /* Wed */ {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3},
          /* Thu */ {10,26}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3},
          /* Fri */ {10,26}, {10,26}, {11, 3}, {11, 3}, {11, 3}, {11, 3}, {11, 3},
          /* Sat */ {11, 3}, {11, 3}, {11, 3}, {11,10}, {11,10}, {11,10}, {11,10},
        },
        { /* For year2005 */
          /* Min =     1        2        3        4        5        6        7  */
          /* Sun */ {11, 2}, {11, 2}, {11, 2}, {11, 9}, {11, 9}, {11, 9}, {11, 9},
          /* Mon */ {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 9}, {11, 9}, {11, 9},
          /* Tue */ {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 9}, {11, 9},
          /* Wed */ {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 9},
          /* Thu */ {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2},
          /* Fri */ {10,25}, {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2}, {11, 2},
          /* Sat */ {11, 2}, {11, 2}, {11, 9}, {11, 9}, {11, 9}, {11, 9}, {11, 9},
        },
        { /* For year2006 */
          /* Min =     1        2        3        4        5        6        7  */
          /* Sun */ {11, 1}, {11, 1}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8},
          /* Mon */ {11, 1}, {11, 1}, {11, 1}, {11, 8}, {11, 8}, {11, 8}, {11, 8},
          /* Tue */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 8}, {11, 8}, {11, 8},
          /* Wed */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 8}, {11, 8},
          /* Thu */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 8},
          /* Fri */ {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1}, {11, 1},
          /* Sat */ {11, 1}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8},
        },
    };

    static final int[][][] resultWOYForSetTest1 = {
        { /* For year1998 */
            /* FirstDayOfWeek = Sunday */
              {199802}, {199802}, {199802}, {199809},
              {199809}, {199809}, {199809},
            /* FirstDayOfWeek = Monday */
              {199802}, {199802}, {199802}, {199802},
              {199809}, {199809}, {199809},
            /* FirstDayOfWeek = Tuesday */
              {199802}, {199802}, {199802}, {199802},
              {199802}, {199809}, {199809},
            /* FirstDayOfWeek = Wednesday */
              {199802}, {199802}, {199802}, {199802},
              {199802}, {199802}, {199809},
            /* FirstDayOfWeek = Thursday */
              {199802}, {199802}, {199802}, {199802},
              {199802}, {199802}, {199802},
            /* FirstDayOfWeek = Friday */
              {1997,11,26}, {199802}, {199802}, {199802},
              {199802}, {199802}, {199802},
            /* FirstDayOfWeek = Saturday */
              {199802}, {199802}, {199809}, {199809},
              {199809}, {199809}, {199809},
        },
        { /* For year1999 */
            /* FirstDayOfWeek = Sunday */
              {199901}, {199901}, {199908}, {199908},
              {199908}, {199908}, {199908},
            /* FirstDayOfWeek = Monday */
              {199901}, {199901}, {199901}, {199908},
              {199908}, {199908}, {199908},
            /* FirstDayOfWeek = Tuesday */
              {199901}, {199901}, {199901}, {199901},
              {199908}, {199908}, {199908},
            /* FirstDayOfWeek = Wednesday */
              {199901}, {199901}, {199901}, {199901},
              {199901}, {199908}, {199908},
            /* FirstDayOfWeek = Thursday */
              {199901}, {199901}, {199901}, {199901},
              {199901}, {199901}, {199908},
            /* FirstDayOfWeek = Friday */
              {199901}, {199901}, {199901}, {199901},
              {199901}, {199901}, {199901},
            /* FirstDayOfWeek = Saturday */
              {199901}, {199908}, {199908}, {199908},
              {199908}, {199908}, {199908},
        },
        { /* For year2000 */
            /* FirstDayOfWeek = Sunday */
              {1999,11,31}, {200007}, {200007}, {200007},
              {200007}, {200007}, {200007},
            /* FirstDayOfWeek = Monday */
              {1999,11,31}, {1999,11,31}, {200007}, {200007},
              {200007}, {200007}, {200007},
            /* FirstDayOfWeek = Tuesday */
              {1999,11,31}, {1999,11,31}, {1999,11,31}, {200007},
              {200007}, {200007}, {200007},
            /* FirstDayOfWeek = Wednesday */
              {1999,11,31}, {1999,11,31}, {1999,11,31}, {1999,11,31},
              {200007}, {200007}, {200007},
            /* FirstDayOfWeek = Thursday */
              {1999,11,31}, {1999,11,31}, {1999,11,31}, {1999,11,31},
              {1999,11,31}, {200007}, {200007},
            /* FirstDayOfWeek = Friday */
              {1999,11,31}, {1999,11,31}, {1999,11,31}, {1999,11,31},
              {1999,11,31}, {1999,11,31}, {200007},
            /* FirstDayOfWeek = Saturday */
              {200007}, {200007}, {200007}, {200007},
              {200007}, {200007}, {200007},
        },
        { /* For year2001 */
            /* FirstDayOfWeek = Sunday */
              {200105}, {200105}, {200105}, {200105},
              {200105}, {200105}, {20010,12},
            /* FirstDayOfWeek = Monday */
              {200105}, {200105}, {200105}, {200105},
              {200105}, {200105}, {200105},
            /* FirstDayOfWeek = Tuesday */
              {2000,11,29}, {200105}, {200105}, {200105},
              {200105}, {200105}, {200105},
            /* FirstDayOfWeek = Wednesday */
              {2000,11,29}, {2000,11,29}, {200105}, {200105},
              {200105}, {200105}, {200105},
            /* FirstDayOfWeek = Thursday */
              {2000,11,29}, {2000,11,29}, {2000,11,29}, {200105},
              {200105}, {200105}, {200105},
            /* FirstDayOfWeek = Friday */
              {2000,11,29}, {2000,11,29}, {2000,11,29}, {2000,11,29},
              {200105}, {200105}, {200105},
            /* FirstDayOfWeek = Saturday */
              {200105}, {200105}, {200105}, {200105},
              {200105}, {20010,12}, {20010,12},
        },
        { /* For year2002 */
            /* FirstDayOfWeek = Sunday */
              {200204}, {200204}, {200204}, {200204},
              {200204}, {20020,11}, {20020,11},
            /* FirstDayOfWeek = Monday */
              {200204}, {200204}, {200204}, {200204},
              {200204}, {200204}, {20020,11},
            /* FirstDayOfWeek = Tuesday */
              {200204}, {200204}, {200204}, {200204},
              {200204}, {200204}, {200204},
            /* FirstDayOfWeek = Wednesday */
              {2001,11,28}, {200204}, {200204}, {200204},
              {200204}, {200204}, {200204},
            /* FirstDayOfWeek = Thursday */
              {2001,11,28}, {2001,11,28}, {200204}, {200204},
              {200204}, {200204}, {200204},
            /* FirstDayOfWeek = Friday */
              {2001,11,28}, {2001,11,28}, {2001,11,28}, {200204},
              {200204}, {200204}, {200204},
            /* FirstDayOfWeek = Saturday */
              {200204}, {200204}, {200204}, {200204},
              {20020,11}, {20020,11}, {20020,11},
        },
        { /* For year2003 */
            /* FirstDayOfWeek = Sunday */
              {200303}, {200303}, {200303}, {200303},
              {20030,10}, {20030,10}, {20030,10},
            /* FirstDayOfWeek = Monday */
              {200303}, {200303}, {200303}, {200303},
              {200303}, {20030,10}, {20030,10},
            /* FirstDayOfWeek = Tuesday */
              {200303}, {200303}, {200303}, {200303},
              {200303}, {200303}, {20030,10},
            /* FirstDayOfWeek = Wednesday */
              {200303}, {200303}, {200303}, {200303},
              {200303}, {200303}, {200303},
            /* FirstDayOfWeek = Thursday */
              {2002,11,27}, {200303}, {200303}, {200303},
              {200303}, {200303}, {200303},
            /* FirstDayOfWeek = Friday */
              {2002,11,27}, {2002,11,27}, {200303}, {200303},
              {200303}, {200303}, {200303},
            /* FirstDayOfWeek = Saturday */
              {200303}, {200303}, {200303}, {20030,10},
              {20030,10}, {20030,10}, {20030,10},
        },
        { /* For year2004 */
            /* FirstDayOfWeek = Sunday */
              {200402}, {200402}, {200402}, {200409},
              {200409}, {200409}, {200409},
            /* FirstDayOfWeek = Monday */
              {200402}, {200402}, {200402}, {200402},
              {200409}, {200409}, {200409},
            /* FirstDayOfWeek = Tuesday */
              {200402}, {200402}, {200402}, {200402},
              {200402}, {200409}, {200409},
            /* FirstDayOfWeek = Wednesday */
              {200402}, {200402}, {200402}, {200402},
              {200402}, {200402}, {200409},
            /* FirstDayOfWeek = Thursday */
              {200402}, {200402}, {200402}, {200402},
              {200402}, {200402}, {200402},
            /* FirstDayOfWeek = Friday */
              {2003,11,26}, {200402}, {200402}, {200402},
              {200402}, {200402}, {200402},
            /* FirstDayOfWeek = Saturday */
              {200402}, {200402}, {200409}, {200409},
              {200409}, {200409}, {200409},
        },
        { /* For year2005 */
            /* FirstDayOfWeek = Sunday */
              {2004,11,31}, {200507}, {200507}, {200507},
              {200507}, {200507}, {200507},
            /* FirstDayOfWeek = Monday */
              {2004,11,31}, {2004,11,31}, {200507}, {200507},
              {200507}, {200507}, {200507},
            /* FirstDayOfWeek = Tuesday */
              {2004,11,31}, {2004,11,31}, {2004,11,31}, {200507},
              {200507}, {200507}, {200507},
            /* FirstDayOfWeek = Wednesday */
              {2004,11,31}, {2004,11,31}, {2004,11,31}, {2004,11,31},
              {200507}, {200507}, {200507},
            /* FirstDayOfWeek = Thursday */
              {2004,11,31}, {2004,11,31}, {2004,11,31}, {2004,11,31},
              {2004,11,31}, {200507}, {200507},
            /* FirstDayOfWeek = Friday */
              {2004,11,31}, {2004,11,31}, {2004,11,31}, {2004,11,31},
              {2004,11,31}, {2004,11,31}, {200507},
            /* FirstDayOfWeek = Saturday */
              {200507}, {200507}, {200507}, {200507},
              {200507}, {200507}, {200507},
        },
        { /* For year2006 */
            /* FirstDayOfWeek = Sunday */
              {200606}, {200606}, {200606}, {200606},
              {200606}, {200606}, {200606},
            /* FirstDayOfWeek = Monday */
              {2005,11,30}, {200606}, {200606}, {200606},
              {200606}, {200606}, {200606},
            /* FirstDayOfWeek = Tuesday */
              {2005,11,30}, {2005,11,30}, {200606}, {200606},
              {200606}, {200606}, {200606},
            /* FirstDayOfWeek = Wednesday */
              {2005,11,30}, {2005,11,30}, {2005,11,30}, {200606},
              {200606}, {200606}, {200606},
            /* FirstDayOfWeek = Thursday */
              {2005,11,30}, {2005,11,30}, {2005,11,30}, {2005,11,30},
              {200606}, {200606}, {200606},
            /* FirstDayOfWeek = Friday */
              {2005,11,30}, {2005,11,30}, {2005,11,30}, {2005,11,30},
              {2005,11,30}, {200606}, {200606},
            /* FirstDayOfWeek = Saturday */
              {200606}, {200606}, {200606}, {200606},
              {200606}, {200606}, {20060,13},
        }
    };

    static final int[][] resultWOYForSetTest2 = {
          /* Min =    1       2       3       4       5       6       7  */
          /* Sun */ {4,25}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1},
          /* Mon */ {4,25}, {4,25}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1},
          /* Tue */ {4,25}, {4,25}, {4,25}, {5, 1}, {5, 1}, {5, 1}, {5, 1},
          /* Wed */ {4,25}, {4,25}, {4,25}, {4,25}, {5, 1}, {5, 1}, {5, 1},
          /* Thu */ {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 8}, {5, 8},
          /* Fri */ {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 8},
          /* Sat */ {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1}, {5, 1},
    };

    /**
     * Test for set()
     */

    void testSet() {
        boolean noerror = true;
        Calendar cal = Calendar.getInstance();
        int sYear=1998;
        int eYear=2006;

        // Loop for FirstDayOfWeek: SUNDAY..SATURDAY
        for (int dow = SUNDAY; dow <= SATURDAY; dow++) {

            // Loop for MinimalDaysInFirstWeek: 1..7
            for (int minDow = 1; minDow <= 7; minDow++) {
                int index = (dow-1)*7 + (minDow-1);

                cal.clear();
                cal.setLenient(true);
                cal.setMinimalDaysInFirstWeek(minDow);
                cal.setFirstDayOfWeek(dow);
                cal.set(YEAR, 2005);
                cal.set(DAY_OF_WEEK, WEDNESDAY);
                cal.set(WEEK_OF_YEAR, 22);

                int y = 2005;
                int m = resultWOYForSetTest2[index][0];
                int d = resultWOYForSetTest2[index][1];
                int year = cal.get(YEAR);
                int month = cal.get(MONTH);
                int date = cal.get(DATE);

                if (cal.get(WEEK_OF_YEAR) != 22) {
                    noerror = false;
                    errln("Failed : set(WEEK_OF_YEAR=22)" +
                          " *** get(WEEK_OF_YEAR=" +
                          cal.get(WEEK_OF_YEAR) + ")" +
                          ", got " + (month+1)+"/"+date+"/"+year +
                          ", expected " + (m+1)+"/"+d+"/"+2005 +
                          ", MinFirstDOW=" + minDow +
                          ", FirstDOW=" + dow);
                } else if ((year != y) || (month != m) || (date != d)) {
                    noerror = false;
                    errln("Failed : set(WEEK_OF_YEAR=22)" +
                          " got " + (month+1)+"/"+date+"/"+year +
                          ", expected " + (m+1)+"/"+d+"/"+y +
                          ", MinFirstDOW=" + minDow +
                          ", FirstDOW=" + dow);
                }

                for (int targetYear = sYear; targetYear<= eYear; targetYear++) {
                    cal.clear();
                    cal.setLenient(true);
                    cal.setMinimalDaysInFirstWeek(minDow);
                    cal.setFirstDayOfWeek(dow);
                    cal.set(YEAR, targetYear);
                    cal.set(DAY_OF_WEEK, FRIDAY);
                    cal.set(MONTH, DECEMBER);
                    cal.set(WEEK_OF_MONTH, 1);

                    y = targetYear;
                    m = resultWOMForSetTest[targetYear-sYear][index][0];
                    d = resultWOMForSetTest[targetYear-sYear][index][1];
                    year = cal.get(YEAR);
                    month = cal.get(MONTH);
                    date = cal.get(DATE);

                    if ((year != y) || (month != m) || (date != d)) {
                        noerror = false;
                        errln("Failed : set(WEEK_OF_MONTH=1)" +
                              " got " + (month+1)+"/"+date+"/"+year +
                              ", expected " + (m+1)+"/"+d+"/"+y +
                              ", MinFirstDOW=" + minDow +
                              ", FirstDOW=" + dow);
                    }

                    cal.clear();
                    cal.setLenient(true);
                    cal.setMinimalDaysInFirstWeek(minDow);
                    cal.setFirstDayOfWeek(dow);
                    cal.set(YEAR, targetYear);
                    cal.set(DAY_OF_WEEK, FRIDAY);
                    cal.set(WEEK_OF_YEAR, 1);

                    y = resultWOYForSetTest1[targetYear-sYear][index][0];
                    m = resultWOYForSetTest1[targetYear-sYear][index][1];
                    d = resultWOYForSetTest1[targetYear-sYear][index][2];
                    year = cal.get(YEAR);
                    month = cal.get(MONTH);
                    date = cal.get(DATE);

                    if (cal.get(WEEK_OF_YEAR) != 1) {
                        noerror = false;
                        errln("Failed : set(WEEK_OF_YEAR=1)" +
                              " *** get(WEEK_OF_YEAR=" +
                              cal.get(WEEK_OF_YEAR) + ")" +
                              ", got " + (month+1)+"/"+date+"/"+year +
                              ", expected " + (m+1)+"/"+d+"/"+y +
                              ", MinFirstDOW=" + minDow +
                              ", FirstDOW=" + dow);
                    } else if ((year != y) || (month != m) || (date != d)) {
                        noerror = false;
                        errln("Failed : set(WEEK_OF_YEAR=1)" +
                              " got " + (month+1)+"/"+date+"/"+year +
                              ", expected " + (m+1)+"/"+d+"/"+y +
                              ", MinFirstDOW=" + minDow +
                              ", FirstDOW=" + dow);
                    }
                }
            }
        }

        if (noerror) {
            logln("Passed : set() test");
        }
    }

    /**
     * Test for add()
     */

    void testAdd() {
        boolean noerror = true;
        Calendar cal = Calendar.getInstance();

        // Loop for FirstDayOfWeek: SUNDAY..SATURDAY
        for (int dow = SUNDAY; dow <= SATURDAY; dow++) {

            // Loop for MinimalDaysInFirstWeek: 1..7
            for (int minDow = 1; minDow <= 7; minDow++) {
                int oldWOY, newWOY;

                cal.clear();
                cal.setLenient(true);
                cal.setMinimalDaysInFirstWeek(minDow);
                cal.setFirstDayOfWeek(dow);
                cal.set(2005, DECEMBER, 7);
                oldWOY = cal.get(WEEK_OF_YEAR);

                for (int cnt = 0; cnt < 7; cnt++) {
                    cal.add(WEEK_OF_YEAR, 1);
                }

                int year = cal.get(YEAR);
                int month = cal.get(MONTH);
                int date = cal.get(DATE);

                if ((year != 2006) || (month != 0) || (date != 25)) {
                    noerror = false;
                    errln("Failed : add(WEEK_OF_YEAR+1)" +
                          " got " + (month+1)+"/"+date+"/"+year +
                          ", expected 1/25/2006" +
                          ", MinFirstDOW=" + minDow +
                          ", FirstDOW=" + dow);
                }

                for (int cnt = 0; cnt < 10; cnt++) {
                    cal.add(WEEK_OF_YEAR, -1);
                }
                newWOY = cal.get(WEEK_OF_YEAR);

                year = cal.get(YEAR);
                month = cal.get(MONTH);
                date = cal.get(DATE);

                if ((oldWOY - newWOY) != 3) {
                    errln("Failed : add(WEEK_OF_YEAR-1)" +
                          " got " + (month+1)+"/"+date+"/"+year +
                          ", expected 11/16/2005" +
                          ", MinFirstDOW=" + minDow +
                          ", FirstDOW=" + dow +
                          ", WEEK_OF_YEAR=" + newWOY +
                          " should be " + (oldWOY-3));
                } else if ((year != 2005) || (month != 10) || (date != 16)) {
                    errln("Failed : add(-1)" +
                          " got " + (month+1)+"/"+date+"/"+year +
                          ", expected 11/16/2005" +
                          ", MinFirstDOW=" + minDow +
                          ", FirstDOW=" + dow);
                }
            }
        }

        if (noerror) {
            logln("Passed : add() test");
        }
    }

    /*
     * Golden data for roll() test
     */

    static final int[] resultWOMForRollTest = {
          /* Min =    1   2   3   4   5   6   7  */
          /* Sun */   1,  1,  1, 26, 26, 26, 26,
          /* Mon */   1,  1,  1,  1, 26, 26, 26,
          /* Tue */  31, 31, 31, 31, 31, 24, 24,
          /* Wed */  31, 31, 31, 31, 31, 31, 24,
          /* Thu */  31, 31, 31, 31, 31, 31, 31,
          /* Fri */   1, 31, 31, 31, 31, 31, 31,
          /* Sat */   1,  1, 31, 31, 31, 31, 31,
    };

    static final int[][] resultWOYForRollTest = {
          /* Min =    1       2       3       4       5       6       7  */
          /* Sun */ {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26},
          /* Mon */ {1, 2}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26},
          /* Tue */ {1, 2}, {1, 2}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26},
          /* Wed */ {1, 2}, {1, 2}, {1, 2}, {0,26}, {0,26}, {0,26}, {0,26},
          /* Thu */ {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {1, 2}, {1, 2},
          /* Fri */ {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {1, 2},
          /* Sat */ {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26}, {0,26},
    };

    /**
     * Test for roll()
     */

    void testRoll() {
        boolean noerror = true;
        Calendar cal = Calendar.getInstance();

        // Loop for FirstDayOfWeek: SUNDAY..SATURDAY
        for (int dow = SUNDAY; dow <= SATURDAY; dow++) {

            // Loop for MinimalDaysInFirstWeek: 1..7
            for (int minDow = 1; minDow <= 7; minDow++) {
                int oldWOY, newWOY;
                int index = (dow-1)*7 + (minDow-1);

                cal.clear();
                cal.setLenient(true);
                cal.setMinimalDaysInFirstWeek(minDow);
                cal.setFirstDayOfWeek(dow);
                cal.set(2005, DECEMBER, 12);
                oldWOY = cal.get(WEEK_OF_YEAR);
                for (int cnt = 0; cnt < 2; cnt++) {
                    cal.roll(WEEK_OF_MONTH, -1);
                }
                int y = 2005;
                int m = DECEMBER;
                int d = resultWOMForRollTest[index];
                int year = cal.get(YEAR);
                int month = cal.get(MONTH);
                int date = cal.get(DATE);

                if ((year != y) || (month != m) || (date != d)) {
                    noerror = false;
                    errln("Failed : roll(WEEK_OF_MONTH-1)" +
                          " got " + (month+1) + "/" + date + "/" + year +
                          ", expected " + (m+1) + "/" + d + "/" + y +
                          ", MinFirstDOW=" + minDow +
                          ", FirstDOW=" + dow);
                }

                cal.clear();
                cal.setLenient(true);
                cal.setMinimalDaysInFirstWeek(minDow);
                cal.setFirstDayOfWeek(dow);
                cal.set(2005, DECEMBER, 7);
                oldWOY = cal.get(WEEK_OF_YEAR);

                for (int cnt = 0; cnt < 7; cnt++) {
                    cal.roll(WEEK_OF_YEAR, 1);
                }

                y = 2005;
                m = resultWOYForRollTest[index][0];
                d = resultWOYForRollTest[index][1];
                year = cal.get(YEAR);
                month = cal.get(MONTH);
                date = cal.get(DATE);

                if ((year != y) || (month != m) || (date != d)) {
                    noerror = false;
                    errln("Failed : roll(WEEK_OF_YEAR+1)" +
                          " got " + (month+1) + "/" + date + "/" + year +
                          ", expected " + (m+1) + "/" + d + "/" + y +
                          ", MinFirstDOW=" + minDow +
                          ", FirstDOW=" + dow);
                }

                for (int cnt = 0; cnt < 10; cnt++) {
                    cal.roll(WEEK_OF_YEAR, -1);
                }
                newWOY = cal.get(WEEK_OF_YEAR);

                y = 2005;
                m = NOVEMBER;
                d = 16;
                year = cal.get(YEAR);
                month = cal.get(MONTH);
                date = cal.get(DATE);

                if ((year != y) || (month != m) || (date != d)) {
                    noerror = false;
                    errln("Failed : roll(WEEK_OF_YEAR-1)" +
                          " got " + (month+1)+"/"+date+"/"+year +
                          ", expected " + (m+1)+"/"+d+"/"+y +
                          ", MinFirstDOW=" + minDow +
                          ", FirstDOW=" + dow);
                }
            }
        }

        if (noerror) {
            logln("Passed : roll() test");
        }
    }
}

Messung V0.5 in Prozent
C=73 H=78 G=75

¤ Dauer der Verarbeitung: 0.17 Sekunden  (vorverarbeitet am  2026-06-06) ¤

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

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik