PageRenderTime 36ms CodeModel.GetById 20ms app.highlight 13ms RepoModel.GetById 0ms app.codeStats 1ms

/libformula-1.1.3/test/org/pentaho/reporting/libraries/formula/function/datetime/WeekDayFunctionTest.java

#
Java | 76 lines | 48 code | 9 blank | 19 comment | 1 complexity | ace28fb3952517ee249fc175f3ec6110 MD5 | raw file
Possible License(s): LGPL-2.1
 1/*
 2 * This program is free software; you can redistribute it and/or modify it under the
 3 * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
 4 * Foundation.
 5 *
 6 * You should have received a copy of the GNU Lesser General Public License along with this
 7 * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 8 * or from the Free Software Foundation, Inc.,
 9 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU Lesser General Public License for more details.
14 *
15 * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.  All rights reserved.
16 */
17
18package org.pentaho.reporting.libraries.formula.function.datetime;
19
20import java.math.BigDecimal;
21
22import org.pentaho.reporting.libraries.formula.FormulaTestBase;
23
24/**
25 * @author Cedric Pronzato
26 */
27public class WeekDayFunctionTest extends FormulaTestBase
28{
29  public Object[][] createDataTest()
30  {
31    return new Object[][]
32        {
33            {"WEEKDAY(DATE(2006;5;21))", new BigDecimal(1)},
34            {"WEEKDAY(DATE(2005;1;1))", new BigDecimal(7)},
35            {"WEEKDAY(DATE(2005;1;1);1)", new BigDecimal(7)},
36            {"WEEKDAY(DATE(2005;1;1);2)", new BigDecimal(6)},
37            {"WEEKDAY(DATE(2005;1;1);3)", new BigDecimal(5)},};
38  }
39
40  private Number[][] createTypeDataTest()
41  {
42    return new Number[][]
43        {
44            {new BigDecimal(1), new BigDecimal(7), new BigDecimal(6)},
45            {new BigDecimal(2), new BigDecimal(1), new BigDecimal(0)},
46            {new BigDecimal(3), new BigDecimal(2), new BigDecimal(1)},
47            {new BigDecimal(4), new BigDecimal(3), new BigDecimal(2)},
48            {new BigDecimal(5), new BigDecimal(4), new BigDecimal(3)},
49            {new BigDecimal(6), new BigDecimal(5), new BigDecimal(4)},
50            {new BigDecimal(7), new BigDecimal(6), new BigDecimal(5)},
51        };
52  }
53
54  public void testAllTypes()
55  {
56    final WeekDayFunction function = new WeekDayFunction();
57    final Number[][] dataTest = createTypeDataTest();
58    for (int i = 0; i < dataTest.length; i++)
59    {
60      final Number[] objects = dataTest[i];
61      final Number type1 = objects[0];
62      final Number type2 = objects[1];
63      final Number  type3 = objects[2];
64      assertEquals("Error with Type 1 conversion", function.convertType(type1.intValue(), 1), type1.intValue());
65      assertEquals("Error with Type 2 conversion", function.convertType(type1.intValue(), 2), type2.intValue());
66      assertEquals("Error with Type 3 conversion", function.convertType(type1.intValue(), 3), type3.intValue());
67    }
68  }
69
70  public void testDefault() throws Exception
71  {
72    runDefaultTest();
73  }
74
75
76}