PageRenderTime 49ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/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. package org.pentaho.reporting.libraries.formula.function.datetime;
  18. import java.math.BigDecimal;
  19. import org.pentaho.reporting.libraries.formula.FormulaTestBase;
  20. /**
  21. * @author Cedric Pronzato
  22. */
  23. public class WeekDayFunctionTest extends FormulaTestBase
  24. {
  25. public Object[][] createDataTest()
  26. {
  27. return new Object[][]
  28. {
  29. {"WEEKDAY(DATE(2006;5;21))", new BigDecimal(1)},
  30. {"WEEKDAY(DATE(2005;1;1))", new BigDecimal(7)},
  31. {"WEEKDAY(DATE(2005;1;1);1)", new BigDecimal(7)},
  32. {"WEEKDAY(DATE(2005;1;1);2)", new BigDecimal(6)},
  33. {"WEEKDAY(DATE(2005;1;1);3)", new BigDecimal(5)},};
  34. }
  35. private Number[][] createTypeDataTest()
  36. {
  37. return new Number[][]
  38. {
  39. {new BigDecimal(1), new BigDecimal(7), new BigDecimal(6)},
  40. {new BigDecimal(2), new BigDecimal(1), new BigDecimal(0)},
  41. {new BigDecimal(3), new BigDecimal(2), new BigDecimal(1)},
  42. {new BigDecimal(4), new BigDecimal(3), new BigDecimal(2)},
  43. {new BigDecimal(5), new BigDecimal(4), new BigDecimal(3)},
  44. {new BigDecimal(6), new BigDecimal(5), new BigDecimal(4)},
  45. {new BigDecimal(7), new BigDecimal(6), new BigDecimal(5)},
  46. };
  47. }
  48. public void testAllTypes()
  49. {
  50. final WeekDayFunction function = new WeekDayFunction();
  51. final Number[][] dataTest = createTypeDataTest();
  52. for (int i = 0; i < dataTest.length; i++)
  53. {
  54. final Number[] objects = dataTest[i];
  55. final Number type1 = objects[0];
  56. final Number type2 = objects[1];
  57. final Number type3 = objects[2];
  58. assertEquals("Error with Type 1 conversion", function.convertType(type1.intValue(), 1), type1.intValue());
  59. assertEquals("Error with Type 2 conversion", function.convertType(type1.intValue(), 2), type2.intValue());
  60. assertEquals("Error with Type 3 conversion", function.convertType(type1.intValue(), 3), type3.intValue());
  61. }
  62. }
  63. public void testDefault() throws Exception
  64. {
  65. runDefaultTest();
  66. }
  67. }