Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros.message;
00018
00019 import static org.junit.Assert.assertEquals;
00020 import static org.junit.Assert.assertFalse;
00021 import static org.junit.Assert.assertTrue;
00022
00023 import org.junit.Before;
00024 import org.junit.Test;
00025
00029 public class DurationTest {
00030
00031 @Before
00032 public void setUp() {
00033 }
00034
00035 @Test
00036 public void testConstructor() {
00037
00038 Duration t = new Duration();
00039 assertEquals(0, t.nsecs);
00040 assertEquals(0, t.secs);
00041
00042
00043 t = new Duration(1, 2);
00044 assertEquals(1, t.secs);
00045 assertEquals(2, t.nsecs);
00046
00047
00048 t = new Duration(2, -1);
00049 assertEquals(1, t.secs);
00050 assertEquals(1000000000 - 1, t.nsecs);
00051
00052 t = new Duration(2, 1000000000 + 2);
00053 assertEquals(3, t.secs);
00054 assertEquals(2, t.nsecs);
00055 }
00056
00057 @Test
00058 public void testNormalize() {
00059 Duration d = new Duration(0, 0);
00060 d.secs = 1;
00061 d.nsecs = 1000000000;
00062 d.normalize();
00063 assertEquals(2, d.secs);
00064 assertEquals(0, d.nsecs);
00065
00066 d.secs = 1;
00067 d.nsecs = -1;
00068 d.normalize();
00069 assertEquals(0, d.secs);
00070 assertEquals(1000000000-1, d.nsecs);
00071 }
00072
00073 @Test
00074 public void testIsZero() {
00075 assertTrue(new Duration(0, 0).isZero());
00076 assertFalse(new Duration(1, 0).isZero());
00077 assertFalse(new Duration(0, 1).isZero());
00078 }
00079
00080 @Test
00081 public void testComparable() {
00082 assertEquals(0, new Duration(0, 0).compareTo(new Duration(0, 0)));
00083 assertEquals(0, new Duration(1, 0).compareTo(new Duration(1, 0)));
00084
00085 assertTrue(new Duration(0, 0).compareTo(new Duration(0, -1)) > 0);
00086 assertTrue(new Duration(0, -1).compareTo(new Duration(0, 0)) < 0);
00087
00088 assertTrue(new Duration(0, 0).compareTo(new Duration(-1, 0)) > 0);
00089 assertTrue(new Duration(-1, 0).compareTo(new Duration(0, 0)) < 0);
00090
00091 assertTrue(new Duration(1, 0).compareTo(new Duration(0, 0)) > 0);
00092 assertTrue(new Duration(0, 0).compareTo(new Duration(1, 0)) < 0);
00093
00094 assertTrue(new Duration(0, 1).compareTo(new Duration(0, 0)) > 0);
00095 assertTrue(new Duration(0, 0).compareTo(new Duration(0, 1)) < 0);
00096 }
00097 }