source: josm/test/org/openstreetmap/josm/testframework/DataSetTestCaseHelper.java@ 135

Last change on this file since 135 was 135, checked in by imi, 18 years ago
  • fixed test directory structure
  • shortkeys do not cycle through modes anymore
  • Ctrl+, and Ctrl+. to zoom in/out. Should work on Mac now.
File size: 1.8 KB
Line 
1package org.openstreetmap.josm.testframework;
2
3import java.util.Arrays;
4
5import org.openstreetmap.josm.Main;
6import org.openstreetmap.josm.data.coor.LatLon;
7import org.openstreetmap.josm.data.osm.DataSet;
8import org.openstreetmap.josm.data.osm.Segment;
9import org.openstreetmap.josm.data.osm.Node;
10import org.openstreetmap.josm.data.osm.Way;
11import org.openstreetmap.josm.data.projection.Mercator;
12
13
14/**
15 * Test cases that need to manupulate a data set can use this helper.
16 *
17 * @author Imi
18 */
19public class DataSetTestCaseHelper {
20
21 /**
22 * Create a common dataset consisting of:
23 * - 5 random nodes
24 * - ls between node 0 and 1
25 * - ls between node 1 and 2
26 * - ls between node 3 and 4
27 * - a way with ls 0 and 1
28 */
29 public static DataSet createCommon() {
30 DataSet ds = new DataSet();
31 Node n1 = createNode(ds);
32 Node n2 = createNode(ds);
33 Node n3 = createNode(ds);
34 Node n4 = createNode(ds);
35 Node n5 = createNode(ds);
36 Segment ls1 = createSegment(ds, n1, n2);
37 Segment ls2 = createSegment(ds, n2, n3);
38 createSegment(ds, n4, n5);
39 createWay(ds, ls1, ls2);
40 return ds;
41 }
42
43 public static Way createWay(DataSet ds, Segment... segments) {
44 Way t = new Way();
45 t.segments.addAll(Arrays.asList(segments));
46 ds.ways.add(t);
47 return t;
48 }
49
50 /**
51 * Create a segment with out of the given nodes.
52 */
53 public static Segment createSegment(DataSet ds, Node n1, Node n2) {
54 Segment ls = new Segment(n1, n2);
55 ds.segments.add(ls);
56 return ls;
57 }
58
59 /**
60 * Add a random node.
61 */
62 public static Node createNode(DataSet ds) {
63 if (Main.proj == null)
64 Main.proj = new Mercator();
65 Node node = new Node(new LatLon(Math.random(), Math.random()));
66 if (ds != null)
67 ds.nodes.add(node);
68 return node;
69 }
70
71}
Note: See TracBrowser for help on using the repository browser.