DurationTest.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
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     // Test no args constructor.
00038     Duration t = new Duration();
00039     assertEquals(0, t.nsecs);
00040     assertEquals(0, t.secs);
00041       
00042     // Test secs/nsecs constructor with no normalization.
00043     t = new Duration(1, 2);
00044     assertEquals(1, t.secs);
00045     assertEquals(2, t.nsecs);
00046 
00047     // Test secs/nsecs constructor with normalization.
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 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49