~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/grid/GridTest.java

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hisp.dhis.system.grid;
 
2
 
 
3
/*
 
4
 * Copyright (c) 2004-2007, University of Oslo
 
5
 * All rights reserved.
 
6
 *
 
7
 * Redistribution and use in source and binary forms, with or without
 
8
 * modification, are permitted provided that the following conditions are met:
 
9
 * * Redistributions of source code must retain the above copyright notice, this
 
10
 *   list of conditions and the following disclaimer.
 
11
 * * Redistributions in binary form must reproduce the above copyright notice,
 
12
 *   this list of conditions and the following disclaimer in the documentation
 
13
 *   and/or other materials provided with the distribution.
 
14
 * * Neither the name of the HISP project nor the names of its contributors may
 
15
 *   be used to endorse or promote products derived from this software without
 
16
 *   specific prior written permission.
 
17
 *
 
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
19
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
21
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 
22
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 
25
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
28
 */
 
29
 
 
30
import java.util.ArrayList;
 
31
import java.util.List;
 
32
 
 
33
import junit.framework.TestCase;
 
34
 
 
35
/**
 
36
 * @author Lars Helge Overland
 
37
 * @version $Id$
 
38
 */
 
39
public class GridTest
 
40
    extends TestCase
 
41
{
 
42
    private Grid grid;
 
43
    
 
44
    @Override
 
45
    public void setUp()
 
46
    {
 
47
        grid = new Grid();
 
48
 
 
49
        grid.nextRow();        
 
50
        grid.addValue( "11" );
 
51
        grid.addValue( "12" );
 
52
        grid.addValue( "13" );
 
53
 
 
54
        grid.nextRow();        
 
55
        grid.addValue( "21" );
 
56
        grid.addValue( "22" );
 
57
        grid.addValue( "23" );
 
58
 
 
59
        grid.nextRow();        
 
60
        grid.addValue( "31" );
 
61
        grid.addValue( "32" );
 
62
        grid.addValue( "33" );
 
63
    }
 
64
    
 
65
    public void testGetHeight()
 
66
    {
 
67
        assertEquals( 3, grid.getHeight() );
 
68
    }
 
69
    
 
70
    public void testGetWidth()
 
71
    {
 
72
        assertEquals( 3, grid.getWidth() );
 
73
    }
 
74
    
 
75
    public void testGetRow()
 
76
    {
 
77
        List<String> rowA = grid.getRow( 0 );
 
78
        
 
79
        assertTrue( rowA.size() == 3 );
 
80
        assertTrue( rowA.contains( "11" ) );
 
81
        assertTrue( rowA.contains( "12" ) );
 
82
        assertTrue( rowA.contains( "13" ) );
 
83
        
 
84
        List<String> rowB = grid.getRow( 1 );
 
85
        
 
86
        assertTrue( rowB.size() == 3 );
 
87
        assertTrue( rowB.contains( "21" ) );
 
88
        assertTrue( rowB.contains( "22" ) );
 
89
        assertTrue( rowB.contains( "23" ) );
 
90
    }
 
91
    
 
92
    public void testGetRows()
 
93
    {
 
94
        assertEquals( 3, grid.getRows().size() );
 
95
    }
 
96
    
 
97
    public void testGetColumn()
 
98
    {        
 
99
        List<String> columnB = grid.getColumn( 1 );
 
100
        
 
101
        assertTrue( columnB.size() == 3 );
 
102
        assertTrue( columnB.contains( "12" ) );
 
103
        assertTrue( columnB.contains( "22" ) );
 
104
        assertTrue( columnB.contains( "32" ) );
 
105
 
 
106
        List<String> columnC = grid.getColumn( 2 );
 
107
        
 
108
        assertTrue( columnC.size() == 3 );
 
109
        assertTrue( columnC.contains( "13" ) );
 
110
        assertTrue( columnC.contains( "23" ) );
 
111
        assertTrue( columnC.contains( "33" ) ); 
 
112
    }
 
113
    
 
114
    public void testAddColumn()
 
115
    {
 
116
        List<String> columnValues = new ArrayList<String>( 3 );
 
117
        columnValues.add( "14" );
 
118
        columnValues.add( "24" );
 
119
        columnValues.add( "34" );        
 
120
        
 
121
        grid.addColumn( columnValues );
 
122
        
 
123
        List<String> columnD = grid.getColumn( 3 );
 
124
        
 
125
        assertTrue( columnD.size() == 3 );
 
126
        assertTrue( columnD.contains( "14" ) );
 
127
        assertTrue( columnD.contains( "24" ) );
 
128
        assertTrue( columnD.contains( "34" ) );
 
129
        
 
130
        List<String> rowB = grid.getRow( 1 );
 
131
        
 
132
        assertTrue( rowB.size() == 4 );
 
133
        assertTrue( rowB.contains( "21" ) );
 
134
        assertTrue( rowB.contains( "22" ) );
 
135
        assertTrue( rowB.contains( "23" ) );
 
136
        assertTrue( rowB.contains( "24" ) );
 
137
    }
 
138
    
 
139
    public void testAddRegressionColumn()
 
140
    {
 
141
        grid = new Grid();        
 
142
 
 
143
        grid.nextRow();        
 
144
        grid.addValue( "10.0" );
 
145
        grid.nextRow();        
 
146
        grid.addValue( "50.0" );
 
147
        grid.nextRow();        
 
148
        grid.addValue( "20.0" );
 
149
        grid.nextRow();        
 
150
        grid.addValue( "60.0" );
 
151
        
 
152
        grid.addRegressionColumn( 0 );
 
153
        
 
154
        List<String> column = grid.getColumn( 1 );
 
155
        
 
156
        assertTrue( column.size() == 4 );
 
157
        assertTrue( column.contains( "17.0" ) );
 
158
        assertTrue( column.contains( "29.0" ) );
 
159
        assertTrue( column.contains( "41.0" ) );
 
160
        assertTrue( column.contains( "53.0" ) );
 
161
    }
 
162
}