Commit | Line | Data |
---|---|---|
739b9fec AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | *******************************************************************************/ | |
9 | ||
10 | package org.eclipse.tracecompass.tmf.ui.tests.views.timegraph2.swtjfx; | |
11 | ||
12 | import static org.junit.Assert.assertEquals; | |
13 | ||
14 | import org.eclipse.tracecompass.internal.provisional.tmf.ui.views.timegraph2.swtjfx.SwtJfxTimeGraphViewer; | |
15 | import org.junit.Test; | |
16 | ||
17 | public class SwtJfxTimeGraphViewerStaticTest { | |
18 | ||
19 | private static final double DELTA = 0.1; | |
20 | ||
21 | /** | |
22 | * Test area consisting of 100 pixels representing a timerange from 1000 to | |
23 | * 2000. | |
24 | */ | |
25 | private static class TestArea1 { | |
26 | private static final long START_TIMESTAMP = 1000; | |
27 | private static final long END_TIMESTAMP = 2000; | |
28 | private static final double NANOS_PER_PIXEL = 10.0; | |
29 | } | |
30 | ||
31 | @Test | |
32 | public void testTimeToPosition() { | |
33 | double yPos = SwtJfxTimeGraphViewer.timestampToPaneXPos(1500, | |
34 | TestArea1.START_TIMESTAMP, | |
35 | TestArea1.END_TIMESTAMP, | |
36 | TestArea1.NANOS_PER_PIXEL); | |
37 | assertEquals(50.0, yPos, DELTA); | |
38 | ||
39 | long start = 1332170682440133097L; | |
40 | long end = 1332170692664579801L; | |
41 | long ts1 = 1332170683481793497L; | |
42 | long ts2 = 1332170683485732407L; | |
43 | double yPos1 = SwtJfxTimeGraphViewer.timestampToPaneXPos(ts1, start, end, 10.0); | |
44 | double yPos2 = SwtJfxTimeGraphViewer.timestampToPaneXPos(ts2, start, end, 10.0); | |
45 | assertEquals(104166039.959, yPos1, DELTA); | |
46 | assertEquals(104559930.959, yPos2, DELTA); | |
47 | ||
48 | } | |
49 | ||
50 | @Test | |
51 | public void testPositionToTimestamp() { | |
52 | long ts = SwtJfxTimeGraphViewer.paneXPosToTimestamp(50.0, | |
53 | TestArea1.START_TIMESTAMP * TestArea1.NANOS_PER_PIXEL, | |
54 | TestArea1.START_TIMESTAMP, | |
55 | TestArea1.NANOS_PER_PIXEL); | |
56 | assertEquals(1500, ts); | |
57 | } | |
58 | } |