1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/**
* Copyright (C) 2009 by Mar'yan Rachynskyy
* mrach@users.sourceforge.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.sf.linuxorg.pcal.engine;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* @author Mar'yan Rachynskyy
*
*/
public class DateIntsContainerTest {
/**
* Test method for {@link net.sf.linuxorg.pcal.engine.DateIntsContainer#DateIntsContainer()}.
*/
@Test
public final void testDateIntsContainer() {
DateIntsContainer intsContainer = new DateIntsContainer();
for(int i=0; i<DateIntsContainer.getIntsCount(); i++) {
assertNull(intsContainer.getIntValue(i));
}
}
/**
* Test method for {@link net.sf.linuxorg.pcal.engine.DateIntsContainer#DateIntsContainer(int, java.lang.Integer)}.
*/
@Test
public final void testDateIntsContainerIntInteger() {
for(int i = 0; i<DateIntsContainer.getIntsCount(); i++) {
DateIntsContainer intsContainer = new DateIntsContainer(i, i+5);
for(int j = 0; j<DateIntsContainer.getIntsCount(); j++) {
if(i==j) {
assertEquals((Object)intsContainer.getIntValue(j), (Object)(i+5));
} else {
assertNull(intsContainer.getIntValue(j));
}
}
}
}
/**
* Test method for {@link net.sf.linuxorg.pcal.engine.DateIntsContainer#getIntValue(int)}.
*/
@Test
public final void testGetIntValue() {
DateIntsContainer intsContainer = new DateIntsContainer();
intsContainer.setIntValue(0, 3);
assertEquals((Object)intsContainer.getIntValue(0), (Object)3);
intsContainer.setIntValue(100, 1);
assertEquals((Object)intsContainer.getIntValue(3), (Object)null);
assertEquals((Object)intsContainer.getIntValue(100), (Object)null);
intsContainer.setIntValue(0, null);
assertEquals((Object)intsContainer.getIntValue(0), (Object)null);
}
/**
* Test method for {@link net.sf.linuxorg.pcal.engine.DateIntsContainer#toString()}.
*/
@Test
public final void testToString() {
DateIntsContainer intsContainer = new DateIntsContainer();
assertEquals(intsContainer.toString(), ",,,"); //$NON-NLS-1$
intsContainer.setIntValue(0, 3);
assertEquals(intsContainer.toString(), "3,,,"); //$NON-NLS-1$
intsContainer.setIntValue(3, 2);
assertEquals(intsContainer.toString(), "3,,,2"); //$NON-NLS-1$
}
/**
* Test method for {@link net.sf.linuxorg.pcal.engine.DateIntsContainer#parseFromString(java.lang.String)}.
*/
@Test
public final void testParseFromString() {
String testStrings[] = {",,,", ",1,2,3", "1,2,3,", "1,2,3,4", "1,2,3", "1,2,", "1,2"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
Integer expectedInts[][] = {
{null, null, null, null},
{null, 1, 2, 3},
{1, 2, 3, null},
{1, 2, 3, 4},
{1, 2, 3, null},
{1, 2, null, null},
{1, 2, null, null}
};
for(int i = 0; i< testStrings.length; i++) {
DateIntsContainer intsContainer = DateIntsContainer.parseFromStringFactory(testStrings[i]);
for(int j = 0; j< expectedInts[i].length; j++) {
assertEquals(intsContainer.getIntValue(j), expectedInts[i][j]);
}
}
}
/**
* Test method for {@link net.sf.linuxorg.pcal.engine.DateIntsContainer#getIntsCount()}.
*/
@Test
public final void testGetIntsCount() {
assertEquals(DateIntsContainer.getIntsCount(), 4);
}
}
|