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 TimeTest {
00030
00031 @Before
00032 public void setUp() {
00033 }
00034
00035 @Test
00036 public void testConstructor() {
00037
00038 Time t = new Time();
00039 assertEquals(0, t.nsecs);
00040 assertEquals(0, t.secs);
00041
00042
00043 t = new Time(1, 2);
00044 assertEquals(1, t.secs);
00045 assertEquals(2, t.nsecs);
00046
00047
00048 t = new Time(2, -1);
00049 assertEquals(1, t.secs);
00050 assertEquals(1000000000 - 1, t.nsecs);
00051
00052 t = new Time(2, 1000000000 + 2);
00053 assertEquals(3, t.secs);
00054 assertEquals(2, t.nsecs);
00055 }
00056
00057 @Test
00058 public void testFromMillis() {
00059 assertEquals(new Time(0, 0), Time.fromMillis(0));
00060 assertEquals(new Time(0, 1000000), Time.fromMillis(1));
00061 assertEquals(new Time(1, 0), Time.fromMillis(1000));
00062 assertEquals(new Time(10, 0), Time.fromMillis(10000));
00063 assertEquals(new Time(1, 1000000), Time.fromMillis(1001));
00064 assertEquals(new Time(1, 11000000), Time.fromMillis(1011));
00065 }
00066
00067 @Test
00068 public void testNormalize() {
00069 Time t = new Time(0, 0);
00070 t.secs = 1;
00071 t.nsecs = 1000000000;
00072 t.normalize();
00073 assertEquals(2, t.secs);
00074 assertEquals(0, t.nsecs);
00075
00076 t.secs = 1;
00077 t.nsecs = -1;
00078 t.normalize();
00079 assertEquals(0, t.secs);
00080 assertEquals(1000000000 - 1, t.nsecs);
00081 }
00082
00083 @Test
00084 public void testIsZero() {
00085 assertTrue(new Time(0, 0).isZero());
00086 assertFalse(new Time(1, 0).isZero());
00087 assertFalse(new Time(0, 1).isZero());
00088 }
00089
00090 @Test
00091 public void testComparable() {
00092 assertEquals(0, new Time(0, 0).compareTo(new Time(0, 0)));
00093 assertEquals(0, new Time(1, 1).compareTo(new Time(1, 1)));
00094 assertTrue(new Time(0, 1).compareTo(new Time(0, 0)) > 0);
00095
00096 assertEquals(-1, new Time(0, 0).compareTo(new Time(0, 1)));
00097 assertTrue(new Time(0, 0).compareTo(new Time(0, 1)) < 0);
00098 assertTrue(new Time(1, 0).compareTo(new Time(0, 0)) > 0);
00099 assertTrue(new Time(0, 0).compareTo(new Time(1, 0)) < 0);
00100
00101 }
00102 }