1   ////////////////////////////////////////////////////////////////////////////////
2   //CabaWeb
3   //Copyright (C) 2004  Thomas Vogt <Thomas.Vogt@TVC-Software.com>
4   //
5   //This library is free software; you can redistribute it and/or
6   //modify it under the terms of the GNU Lesser General Public
7   //License as published by the Free Software Foundation; either
8   //version 2.1 of the License, or (at your option) any later version.
9   //
10  //This library is distributed in the hope that it will be useful,
11  //but WITHOUT ANY WARRANTY; without even the implied warranty of
12  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  //Lesser General Public License for more details.
14  //
15  //You should have received a copy of the GNU Lesser General Public
16  //License along with this library; if not, write to the Free Software
17  //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ////////////////////////////////////////////////////////////////////////////////
19  
20  package org.fhw.cabaweb.junittests;
21  
22  import org.fhw.cabaweb.math.Common;
23  
24  import junit.framework.TestCase;
25  
26  /***
27   * Klasse um alle verf&uuml;gbaren JUnit Tests für Common durchzuf&uuml;hren
28   *
29   * @author	<a href="mailto:thomas.vogt@tvc-software.com">Thomas Vogt</a>
30   * @version	Version 1.0 22.03-07.04.2004
31   */
32  public class CommonTest extends TestCase
33  {
34  
35  	public static void main(String[] args)
36  	{
37  		junit.textui.TestRunner.run(CommonTest.class);
38  	}
39  
40  	/*
41  	 * @see TestCase#setUp()
42  	 */
43  	protected void setUp() throws Exception
44  	{
45  		super.setUp();
46  	}
47  
48      public void testAufZweiNachkommastellenRunden()
49      {
50          assertEquals(0.0, Common.aufZweiNachkommastellenRunden(0.0), 0.001);
51          assertEquals(0.01, Common.aufZweiNachkommastellenRunden(0.01), 0.001);
52          assertEquals(0.01, Common.aufZweiNachkommastellenRunden(0.014), 0.001);
53          assertEquals(0.02, Common.aufZweiNachkommastellenRunden(0.016), 0.001);
54          assertEquals(0.03, Common.aufZweiNachkommastellenRunden(0.025), 0.001);
55      }
56  
57      public void testAufDreiNachkommastellenRunden()
58      {
59          assertEquals(0.0, Common.aufDreiNachkommastellenRunden(0.0), 0.0001);
60          assertEquals(0.001, Common.aufDreiNachkommastellenRunden(0.001), 0.0001);
61          assertEquals(0.001, Common.aufDreiNachkommastellenRunden(0.0014), 0.0001);
62          assertEquals(0.002, Common.aufDreiNachkommastellenRunden(0.0016), 0.0001);
63          assertEquals(0.003, Common.aufDreiNachkommastellenRunden(0.0025), 0.0001);
64      }
65  
66      public void testAufZehnNachkommastellenRunden()
67      {
68          assertEquals(0.0, Common.aufZehnNachkommastellenRunden(0.0), 0.0000000001);
69          assertEquals(0.0000000001, Common.aufZehnNachkommastellenRunden(0.0000000001), 0.00000000001);
70          assertEquals(0.0000000001, Common.aufZehnNachkommastellenRunden(0.00000000014), 0.00000000001);
71          assertEquals(0.0000000002, Common.aufZehnNachkommastellenRunden(0.00000000016), 0.00000000001);
72          assertEquals(0.0000000003, Common.aufZehnNachkommastellenRunden(0.00000000025), 0.00000000001);
73      }
74  
75      public void testAufIntegerRunden()
76      {
77          assertEquals(0, Common.aufIntegerRunden(0.0));
78          assertEquals(0, Common.aufIntegerRunden(0.1));
79          assertEquals(1, Common.aufIntegerRunden(0.5));
80          assertEquals(1, Common.aufIntegerRunden(1.499));
81          assertEquals(2, Common.aufIntegerRunden(1.500));
82      }
83  
84      public void testAufIntegerDurchEinTausendAufrunden()
85      {
86          assertEquals(0, Common.aufIntegerDurchEinTausendAufrunden(0.0));
87          assertEquals(0, Common.aufIntegerDurchEinTausendAufrunden(499.1));
88          assertEquals(1, Common.aufIntegerDurchEinTausendAufrunden(500.5));
89          assertEquals(1, Common.aufIntegerDurchEinTausendAufrunden(1499.999));
90          assertEquals(2, Common.aufIntegerDurchEinTausendAufrunden(1500.0));
91      }
92  
93  	public void testDivide()
94  	{
95  		assertEquals(0.0, Common.divide(0.0, 0.0), 0.0000000001);
96  		assertEquals(Double.POSITIVE_INFINITY, Common.divide(1.0, 0.0), 0.00000000001);
97  		assertEquals(0.0, Common.divide(0.0, 1.0), 0.00000000001);
98  		assertEquals(1.0, Common.divide(1.0, 1.0), 0.00000000001);
99  		assertEquals(Double.NEGATIVE_INFINITY, Common.divide(-1.0, 0.0), 0.00000000001);
100 		assertEquals(0.0, Common.divide(0.0, -1.0), 0.00000000001);
101 		assertEquals(1.0, Common.divide(-1.0, -1.0), 0.00000000001);
102 		assertEquals(2.5, Common.divide(5.0, 2.0), 0.0000000001);
103 		assertEquals(0.5, Common.divide(2.5, 5.0), 0.0000000001);
104 	}
105 
106 }