Subversion Repository Public Repository

litesoft

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
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt
package org.litesoft.commonfoundation.typeutils;

import junit.framework.*;

import org.litesoft.core.simpletypes.temporal.*;

public class CalendarConstantsTest extends TestCase implements CalendarConstants
{
    public static TestSuite suite()
    {
        return new TestSuite( CalendarConstantsTest.class );
    }

    public CalendarConstantsTest( String name )
    {
        super( name );
    }

    public static void main( String[] args )
    {
        junit.textui.TestRunner.run( suite() );
    }

    public void test_ordinals()
            throws Exception
    {
        assertEquals( 7, WeekDay.values().length );

        assertEquals( 0, WeekDay.Sunday.ordinal() );
        assertEquals( 1, WeekDay.Monday.ordinal() );
        assertEquals( 2, WeekDay.Tuesday.ordinal() );
        assertEquals( 3, WeekDay.Wednesday.ordinal() );
        assertEquals( 4, WeekDay.Thursday.ordinal() );
        assertEquals( 5, WeekDay.Friday.ordinal() );
        assertEquals( 6, WeekDay.Saturday.ordinal() );
    }

    public void test_valueOf()
            throws Exception
    {
        for ( WeekDay zWeekDay : WeekDay.values() )
        {
            assertEquals( zWeekDay, WeekDay.valueOf( zWeekDay.ordinal() ) );
        }
        assertEquals( WeekDay.Saturday, WeekDay.valueOf( -1 ) );
        assertEquals( WeekDay.Sunday, WeekDay.valueOf( 7 ) );
    }

    public void test_prev()
            throws Exception
    {
        for ( WeekDay zWeekDay : WeekDay.values() )
        {
            int zOrdinal = zWeekDay.ordinal();
            if ( zOrdinal != 0 )
            {
                assertEquals( WeekDay.valueOf( zOrdinal - 1 ), zWeekDay.prev() );
            }
        }
        assertEquals( WeekDay.Saturday, WeekDay.Sunday.prev() );
    }

    public void test_next()
            throws Exception
    {
        for ( WeekDay zWeekDay : WeekDay.values() )
        {
            int zOrdinal = zWeekDay.ordinal();
            if ( zOrdinal != 6 )
            {
                assertEquals( WeekDay.valueOf( zOrdinal + 1 ), zWeekDay.next() );
            }
        }
        assertEquals( WeekDay.Sunday, WeekDay.Saturday.next() );
    }

    public void test_deltaTillForward()
            throws Exception
    {
        for ( int zFrom = 0; zFrom <= 6; zFrom++ )
        {
            WeekDay zWDFrom = WeekDay.valueOf( zFrom );
            for ( int zResult = 0; zResult <= 6; zResult++ )
            {
                WeekDay zWDTo = WeekDay.valueOf( zFrom + zResult );
                assertEquals( "" + zWDFrom + " -> " + zWDTo, zResult, zWDFrom.deltaTillForward( zWDTo ) );
            }
        }
    }

    public void test_deltaTillBackward()
            throws Exception
    {
        for ( int zFrom = 6; 0 <= zFrom ; zFrom-- )
        {
            WeekDay zWDFrom = WeekDay.valueOf( zFrom );
            for ( int zResult = 0; zResult <= 6; zResult++ )
            {
                WeekDay zWDTo = WeekDay.valueOf( zFrom - zResult );
                assertEquals( "" + zWDFrom + " -> " + zWDTo, zResult, zWDFrom.deltaTillBackward( zWDTo ) );
            }
        }
    }
}

Commits for litesoft/trunk/Java/core/Anywhere/tests/org/litesoft/commonfoundation/typeutils/CalendarConstantsTest.java

Diff revisions: vs.
Revision Author Commited Message
939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

851 Diff Diff GeorgeS picture GeorgeS Mon 08 Oct, 2012 00:05:32 +0000

Breaking the code as Temporal changes are implemented...

821 Diff Diff GeorgeS picture GeorgeS Sun 19 Aug, 2012 00:08:41 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000