Debian Codegraph @

test/footleg/cavesurvey/data/model/CaveSurveyTest.java

raw symbols SCIP
1 /**
2 * Copyright (C) 2009-2017 Paul Fretwell - aka 'Footleg' ([email protected])
3 *
4 * This file is part of Cave Converter.
5 *
6 * Cave Converter is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Cave Converter is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Cave Converter. If not, see <http://www.gnu.org/licenses/>.
18 */
19 package footleg.cavesurvey.data.model;
20
21 import static org.junit.Assert.*;
22
23 import org.junit.Test;
24
25 import footleg.cavesurvey.converter.CmdLineLogger;
26 import footleg.cavesurvey.tools.TestHelper;
27
28 /**
29 * Unit test class for {@link footleg.cavesurvey.data.model.CaveSurvey}
30 *
31 * @author Footleg
32 * @version 2017.01.09 (ISO 8601 YYYY.MM.DD)
33 * @since 1.6 (The Java version used)
34 */
35 public class CaveSurveyTest {
36
37 @Test
38 public void testSetGetSurveyName() {
39 CaveSurvey survey = new CaveSurvey( new CmdLineLogger() );
40
41 String name = "test name";
42
43 survey.setSurveyName( name );
44
45 assertEquals("Name set for survey should match name retrieved for survey", name, survey.getSurveyName() );
46 }
47
48 @Test
49 public void testIsEmptySetRemove() {
50 String seriesName1 = "A Survey Series";
51 String seriesName2 = "Another Series";
52
53 //Create series with a name
54 SurveySeries series1 = new SurveySeries( seriesName1 );
55 SurveySeries series2 = new SurveySeries( seriesName2 );
56
57 CaveSurvey survey = new CaveSurvey( new CmdLineLogger() );
58
59 assertTrue("Survey created with no series should be empty", survey.isEmpty() );
60
61 //Add a series and check again
62 survey.add( series1 );
63 assertFalse("Survey created with one series should not be empty", survey.isEmpty() );
64
65 //Add a second series and check again
66 survey.add( series2 );
67 assertFalse("Survey created with two series should not be empty", survey.isEmpty() );
68 assertEquals("Count series in survey", 2, survey.size() );
69
70 //Remove a series
71 survey.remove( 0 );
72 assertEquals("Count series in survey", 1, survey.size() );
73 assertEquals("First series should be series 2", seriesName2, survey.get(0).getSeriesName() );
74 assertFalse("Survey after one of two series removed should not be empty", survey.isEmpty() );
75
76 //Remove 2nd series
77 survey.remove( 0 );
78 assertEquals("Count series in survey", 0, survey.size() );
79 assertTrue("Survey after two of two series removed should be empty", survey.isEmpty() );
80 }
81
82 @Test
83 public void testClear() {
84 String seriesName1 = "A Survey Series";
85 String seriesName2 = "Another Series";
86
87 //Create series with a name
88 SurveySeries series1 = new SurveySeries( seriesName1 );
89 SurveySeries series2 = new SurveySeries( seriesName2 );
90
91 CaveSurvey survey = new CaveSurvey( new CmdLineLogger() );
92 survey.add( series1 );
93 survey.add( series2 );
94
95 assertEquals("Count series in survey", 2, survey.size() );
96 assertFalse("Survey should not be empty", survey.isEmpty() );
97
98 //Clear survey and it should be empty
99 survey.clear();
100 assertEquals("Count series in survey", 0, survey.size() );
101 assertTrue("Survey should be empty after clear.", survey.isEmpty() );
102 }
103
104 @Test
105 public void testGetChild() {
106 CaveSurvey survey = new CaveSurvey( new CmdLineLogger() );
107 SurveySeries series = TestHelper.createLinearLeapfrogSurveyingSeriesWithSplays();
108 survey.add( series );
109
110 //Generate LRUD data from splays
111 survey.generateLRUDfromSplays();
112
113 //4 splays, then next item in series should be leg 1-2
114 SurveyLeg leg1 = (SurveyLeg) survey.getChild( series, 4 );
115 assertEquals("First leg should be from 1 - 2", "1", leg1.getFromStn().getName() );
116 assertEquals("First leg should be from 1 - 2", "2", leg1.getToStn().getName() );
117 //4 splays, then next item in series should be leg 2-3
118 SurveyLeg leg2 = (SurveyLeg) survey.getChild( series, 9 );
119 assertEquals("First leg should be from 3 - 2", "3", leg2.getFromStn().getName() );
120 assertEquals("First leg should be from 3 - 2", "2", leg2.getToStn().getName() );
121 }
122
123 /**
124 * Test method for {@link footleg.cavesurvey.data.model.CaveSurvey#getChild(Object,int)},
125 * {@link footleg.cavesurvey.data.model.CaveSurvey#getChildCount(Object)},
126 * {@link footleg.cavesurvey.data.model.CaveSurvey#isLeaf(Object)}.
127 * Tests that get child returns both the inner series and the legs for nested series.
128 */
129 @Test
130 public void testGetChild2() {
131 CaveSurvey survey = new CaveSurvey( new CmdLineLogger() );
132 String series1Name = "First Series";
133 SurveySeries series1 = TestHelper.createSimpleForward3SurveyingSeriesWithNoSplays( 1 );
134 series1.setSeriesName( series1Name );
135 String series2Name = "2nd Series";
136 SurveySeries series2 = TestHelper.createSimpleForward3SurveyingSeriesWithNoSplays( 4 );
137 series2.setSeriesName( series2Name );
138 String series3Name = "Third Series";
139 SurveySeries series3 = TestHelper.createSimpleForward3SurveyingSeriesWithNoSplays( 7 );
140 series3.setSeriesName( series3Name );
141
142 //Put series 2 into series 1 as an inner series (giving mixed series with legs)
143 series1.addSeries(series2);
144
145 //Put series 3 into series 2 as an inner series (giving mixed series with legs)
146 series2.addSeries(series3);
147
148 //Add outer series to cave survey
149 survey.add( series1 );
150
151 //Should be only one item in survey
152 int rootChildCount = survey.getChildCount( survey );
153 assertEquals("Root should contain 1 child", 1, rootChildCount );
154 SurveySeries testRoot = (SurveySeries) survey.getChild(survey, 0);
155 assertEquals("First item returned should be 1st series", series1Name, testRoot.getSeriesName() );
156 assertFalse("Series should not be a leaf", survey.isLeaf( testRoot ) );
157
158 //Should only be 4 items in series 1
159 int series1ChildCount = survey.getChildCount( series1 );
160 assertEquals("Series 1 should contain 4 children", 4, series1ChildCount );
161
162 //First item in series1 should be series2
163 SurveySeries testSeries1 = (SurveySeries) survey.getChild( series1, 0 );
164 assertEquals("First item returned should be 2nd series", series2Name, testSeries1.getSeriesName() );
165 assertFalse("Series should not be a leaf", survey.isLeaf( testSeries1 ) );
166
167 //2nd item in series1 should be leg 1-2
168 SurveyLeg leg1 = (SurveyLeg) survey.getChild( series1, 1 );
169 assertEquals("First leg in series 1 should be from 1", "1", leg1.getFromStn().getName() );
170 assertEquals("First leg in series 1 should be to 2", "2", leg1.getToStn().getName() );
171 assertTrue("Leg should be a leaf", survey.isLeaf( leg1 ) );
172
173 //3rd item in series1 should be leg 2-3
174 SurveyLeg leg2 = (SurveyLeg) survey.getChild( series1, 2 );
175 assertEquals("Second leg in series 1 should be from 2", "2", leg2.getFromStn().getName() );
176 assertEquals("Second leg in series 1 should be to 3", "3", leg2.getToStn().getName() );
177 assertTrue("Leg should be a leaf", survey.isLeaf( leg2 ) );
178
179 //4th item in series1 should be leg 3-4
180 SurveyLeg leg3 = (SurveyLeg) survey.getChild( series1, 3 );
181 assertEquals("Third leg in series 1 should be from 3", "3", leg3.getFromStn().getName() );
182 assertEquals("Third leg in series 1 should be to 4", "4", leg3.getToStn().getName() );
183 assertTrue("Leg should be a leaf", survey.isLeaf( leg3 ) );
184
185 //Should only be 4 items in series 2
186 int series2ChildCount = survey.getChildCount( series2 );
187 assertEquals("Series 2 should contain 4 children", 4, series2ChildCount );
188
189 //First item in series2 should be series3
190 SurveySeries testSeries2 = (SurveySeries) survey.getChild( series2, 0 );
191 assertEquals("First item returned should be 3rd series", series3Name, testSeries2.getSeriesName() );
192 assertFalse("Series should not be a leaf", survey.isLeaf( testSeries2 ) );
193
194 //2nd item in series2 should be leg 4-5
195 SurveyLeg leg4 = (SurveyLeg) survey.getChild( series2, 1 );
196 assertEquals("First leg in series 2 should be from 4", "4", leg4.getFromStn().getName() );
197 assertEquals("First leg in series 2 should be to 5", "5", leg4.getToStn().getName() );
198 assertTrue("Leg should be a leaf", survey.isLeaf( leg4 ) );
199
200 //3rd item in series2 should be leg 5-6
201 SurveyLeg leg5 = (SurveyLeg) survey.getChild( series2, 2 );
202 assertEquals("Second leg in series 2 should be from 5", "5", leg5.getFromStn().getName() );
203 assertEquals("Second leg in series 2 should be to 6", "6", leg5.getToStn().getName() );
204 assertTrue("Leg should be a leaf", survey.isLeaf( leg5 ) );
205
206 //4th item in series2 should be leg 6-7
207 SurveyLeg leg6 = (SurveyLeg) survey.getChild( series2, 3 );
208 assertEquals("Third leg in series 2 should be from 6", "6", leg6.getFromStn().getName() );
209 assertEquals("Third leg in series 2 should be to 7", "7", leg6.getToStn().getName() );
210 assertTrue("Leg should be a leaf", survey.isLeaf( leg6 ) );
211
212 //Should only be 3 items in series 3
213 int series3ChildCount = survey.getChildCount( series3 );
214 assertEquals("series 3 should contain 3 children", 3, series3ChildCount );
215
216 //1st item in series3 should be leg 7-8
217 SurveyLeg leg7 = (SurveyLeg) survey.getChild( series3, 0 );
218 assertEquals("First leg in series 3 should be from 7", "7", leg7.getFromStn().getName() );
219 assertEquals("First leg in series 3 should be to 8", "8", leg7.getToStn().getName() );
220 assertTrue("Leg should be a leaf", survey.isLeaf( leg7 ) );
221
222 //2nd item in series3 should be leg 8-9
223 SurveyLeg leg8 = (SurveyLeg) survey.getChild( series3, 1 );
224 assertEquals("Second leg in series 3 should be from 8", "8", leg8.getFromStn().getName() );
225 assertEquals("Second leg in series 3 should be to 9", "9", leg8.getToStn().getName() );
226 assertTrue("Leg should be a leaf", survey.isLeaf( leg8 ) );
227
228 //3rd item in series3 should be leg 9-10
229 SurveyLeg leg9 = (SurveyLeg) survey.getChild( series3, 2 );
230 assertEquals("Third leg in series 3 should be from 9", "9", leg9.getFromStn().getName() );
231 assertEquals("Third leg in series 3 should be to 10", "10", leg9.getToStn().getName() );
232 assertTrue("Leg should be a leaf", survey.isLeaf( leg9 ) );
233
234 }
235
236 }